Get startedGet started for free

Using the correct model in Bedrock

You work for BeanBliss, a specialty-coffee company that helps independent cafés keep their menus fresh with locally roasted beans. As the team gears up to introduce AI-driven demand-planning tools, they’ve asked you to demonstrate how the Claude model in Amazon Bedrock could help forecasting customer demand more effectively.

The boto3 and json libraries have been pre-imported.

This exercise is part of the course

Introduction to Amazon Bedrock

View Course

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 forecast customer demand?"}]

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)
Edit and Run Code