Chatbot
This is a basic example of using the ChatCompletion
endpoint. It allows us to create a chatbot that chats back to us.
Installing SDK
Install using pip.
pip install bedrock_anthropic
Example
A simple example of using the ChatCompletion
endpoint.
import os
from bedrock_anthropic import AnthropicBedrock
anthropic = AnthropicBedrock(
access_key=os.getenv("AWS_ACCESS_KEY"),
secret_key=os.getenv("AWS_SECRET_KEY"),
region=os.getenv("AWS_REGION")
)
chat = anthropic.ChatCompletion.create(
model="anthropic.claude-v2",
max_tokens_to_sample=300,
messages=[
{"role": "user", "content": "Hello!"}
]
)
print(chat["messages"])
Response
[
{ "role": "user", "content": "Hello!" },
{
"role": "system",
"content": " Hello! I'm Claude, an AI assistant created by Anthropic to be helpful, harmless, and honest."
}
]