Get startedGet started for free

Implement few-shot learning for geometry

You're working with a technology company that's developing an educational platform for primary school science and maths training. They need their AI model to follow specific educational formats, and have asked you to use geometric shapes as a demonstration.

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, including the "Shape" and "Description" labels.

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.
____ - ____. ____: 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