ChatBedrockAnthropic

ChatBedrockAnthropic(
    model=None,
    max_tokens=4096,
    aws_secret_key=None,
    aws_access_key=None,
    aws_region=None,
    aws_profile=None,
    aws_session_token=None,
    base_url=None,
    system_prompt=None,
    turns=None,
    kwargs=None,
)

Chat with an AWS bedrock model.

AWS Bedrock provides a number of chat based models, including those Anthropic’s Claude.

Prerequisites

AWS credentials

Consider using the approach outlined in this guide to manage your AWS credentials: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html

Python requirements

ChatBedrockAnthropic, requires the anthropic package with the bedrock extras (e.g., pip install anthropic[bedrock]).

Examples

from chatlas import ChatBedrockAnthropic

chat = ChatBedrockAnthropic(
    aws_profile="...",
    aws_region="us-east",
    aws_secret_key="...",
    aws_access_key="...",
    aws_session_token="...",
)
chat.chat("What is the capital of France?")

Parameters

Name Type Description Default
model Optional[str] The model to use for the chat. None
max_tokens int Maximum number of tokens to generate before stopping. 4096
aws_secret_key Optional[str] The AWS secret key to use for authentication. None
aws_access_key Optional[str] The AWS access key to use for authentication. None
aws_region Optional[str] The AWS region to use. Defaults to the AWS_REGION environment variable. If that is not set, defaults to 'us-east-1'. None
aws_profile Optional[str] The AWS profile to use. None
aws_session_token Optional[str] The AWS session token to use. None
base_url Optional[str] The base URL to use. Defaults to the ANTHROPIC_BEDROCK_BASE_URL environment variable. If that is not set, defaults to f"https://bedrock-runtime.{aws_region}.amazonaws.com". None
system_prompt Optional[str] A system prompt to set the behavior of the assistant. None
turns Optional[list[Turn]] A list of turns to start the chat with (i.e., continuing a previous conversation). If not provided, the conversation begins from scratch. Do not provide non-None values for both turns and system_prompt. Each message in the list should be a dictionary with at least role (usually system, user, or assistant, but tool is also possible). Normally there is also a content field, which is a string. None
kwargs Optional['ChatBedrockClientArgs'] Additional arguments to pass to the anthropic.AnthropicBedrock() client constructor. None

Returns

Name Type Description
Chat A Chat object.