Get startedGet started for free

Implement few-shot learning for geometry

Create effective few-shot prompts that teach the model how to describe geometric shapes. In this exercise, you'll demonstrate how to use examples to establish a consistent pattern for shape descriptions.

The boto3 and json libraries have been pre-imported.

This exercise is part of the course

Introduction to Amazon Bedrock

View Course

Exercise instructions

  • Complete the prompt by completing the definitions of the two shapes described.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Add two more shape descriptions
messages = [
    {"role": "user", "content": """Here are descriptions of geometric shapes:
Shape - Triangle. Description: 3 sides, angles sum to 180°. Seen in roofs.
Shape - ____. Description: 4 equal sides, 90° angles. Found in tiles.
Shape - ____. Description: Round, no corners. Seen in wheels.
Now describe this shape: Hexagon"""}  
]

request_body = json.dumps({"anthropic_version": "bedrock-2023-05-31","max_tokens": 100, "messages": messages})
response = bedrock.invoke_model(modelId='anthropic.claude-3-5-sonnet-20240620-v1:0', body=request_body)
response_body = json.loads(response['body'].read().decode())

print(response_body['content'][0]['text'])
Edit and Run Code