Created
December 10, 2023 15:40
-
-
Save sergenes/2ff15c7fc036dcce77c8ac044db3269a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import anthropic_bedrock | |
from anthropic_bedrock import AnthropicBedrock | |
aws_access_key = os.getenv('AWS_ACCESS_KEY') | |
aws_secret_key = os.getenv('AWS_SECRET_KEY') | |
abclient = AnthropicBedrock( | |
# Authenticate by either providing the keys below or use the default AWS credential providers, such as | |
# using ~/.aws/credentials or the "AWS_SECRET_ACCESS_KEY" and "AWS_ACCESS_KEY_ID" environment variables. | |
aws_access_key=aws_access_key, | |
aws_secret_key=aws_secret_key, | |
# Temporary credentials can be used with aws_session_token. | |
# Read more at https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp.html. | |
# aws_session_token="<session_token>", | |
# aws_region changes the aws region to which the request is made. By default, we read AWS_REGION, | |
# and if that's not present, we default to us-east-1. Note that we do not read ~/.aws/config for the region. | |
aws_region="us-east-1", | |
) | |
def get_bedrock_anthropic_completion(aprompt, amodel="anthropic.claude-instant-v1"): | |
completion = abclient.completions.create( | |
model=amodel, | |
max_tokens_to_sample=1000, | |
temperature=0.2, | |
prompt=f"{anthropic_bedrock.HUMAN_PROMPT} ${aprompt} {anthropic_bedrock.AI_PROMPT}", | |
) | |
return completion.completion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment