為幾何實作 few-shot learning
你正與一間科技公司合作,該公司正在開發一個給小學自然與數學訓練用的教育平台。他們需要 AI 模型遵循特定的教學格式,並請你以幾何圖形作為示範。
已預先匯入 boto3 與 json 函式庫。
本練習屬於課程
Amazon Bedrock 入門
練習說明
- 完成提示:補上兩個圖形的定義,包含
"Shape"與"Description"標籤。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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='us.anthropic.claude-sonnet-4-5-20250929-v1:0', body=request_body)
response_body = json.loads(response['body'].read().decode())
print(response_body['content'][0]['text'])