Using the correct model in Bedrock
Learn how to use the Claude model in Amazon Bedrock to generate a simple text response. In this exercise you'll interact with your model by making an API call using the 'modelId'
for the Anthropic Claude model, asking for some ways to track project milestones.
The boto3
and json
libraries have been pre-imported.
This exercise is part of the course
Introduction to Amazon Bedrock
Exercise instructions
- Initialize the Bedrock client for inference.
- Invoke the model using the
bedrock
client.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Initialize the client for inference
bedrock = boto3.client('____', region_name='us-east-1')
messages = [{"role": "user", "content": "What are some ways to track project milestones?"}]
request_body=json.dumps({"anthropic_version": "bedrock-2023-05-31", "max_tokens": 20,
"messages": messages})
# Invoke the model
response = bedrock.____(body=request_body, modelId='anthropic.claude-3-5-sonnet-20240620-v1:0')
response_body = json.loads(response.get('body').read())
print(response_body)