Invoke Amazon Bedrock Claude 3 with an image in message block
✓ Published0🌍 Public
VVioletVivirand
Last edited Jul 12, 2024
Created on Jul 12, 2024
This example demonstrates how to invoke Amazon Bedrock’s Claude 3 Haiku model with both an image and a text prompt in a single request. The code uses the Bedrock Runtime client from boto3 to call `invoke_model`, converting the request payload to JSON. It fetches a Wikimedia Commons photo of an ant, encodes it as base64, and embeds it in the message’s `content` array alongside the text “Describe this image.” The response’s text is then extracted from the model’s JSON output and printed. The script also handles potential client errors with a try-except block.
AI-generated description