Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not find any example to use bedrock converse API with AnthropicBedrock #758

Open
mohitsophos opened this issue Nov 20, 2024 · 1 comment

Comments

@mohitsophos
Copy link

mohitsophos commented Nov 20, 2024

As documented here: https://docs.anthropic.com/en/api/claude-on-amazon-bedrock#making-requests,
The following internally calls the AWS bedrock invoke API (https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-runtime_example_bedrock-runtime_InvokeModel_AnthropicClaude_section.html)

AWS also supports the converse API: https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-runtime_example_bedrock-runtime_Converse_AnthropicClaude_section.html

I tried going through repo to find an example as well but couldn't. Is this supported?

from anthropic import AnthropicBedrock

client = 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="<access key>",
    aws_secret_key="<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-west-2",
)

message = client.messages.create(
    model="anthropic.claude-3-5-sonnet-20241022-v2:0",
    max_tokens=256,
    messages=[{"role": "user", "content": "Hello, world"}]
)
print(message.content)
@booyaa
Copy link

booyaa commented Dec 4, 2024

hey @mohitsophos looking at the Anthropic Bedrock client I can't see the Converse (Sream) Request URLs. Also there's no tests relating to those runtimes.

Not an official answer, but I'd say it's not supported. You'd be better off using Boto3 for now until these runtimes are added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants