-
Couldn't load subscription status.
- Fork 1.9k
Description
Discussed in #4408
Originally posted by rkc0818 January 28, 2025
Hello I am trying to send two attachments to Calude 3.5 sonnet (modelId: nthropic.claude-3-5-sonnet-20240620-v1:0), I cant seem to make this work. I am sending them as follows.
payload = {
"modelId": "anthropic.claude-3-5-sonnet-20240620-v1:0",
"contentType": "application/json",
"accept": "application/json",
"body": json.dumps({
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 10000,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Explain the diagram from the PDF and sumamrize content from the DOCX attachments"
},
*attachments
]
}
]
})
}
my attachments are created as specified below.
attachments = []
# Add PDF file
with open(pdf_file, 'rb') as file:
mime_type, _ = mimetypes.guess_type(pdf_file)
attachments.append({
"type": "image",
"image": {
"source": {
"type": "base64",
"media_type": mime_type or "application/pdf",
"data": base64.b64encode(file.read()).decode('utf-8')
}
}
})
# Add DOCX file
with open(docx_file, 'rb') as file:
mime_type, _ = mimetypes.guess_type(docx_file)
attachments.append({
"type": "image",
"image": {
"source": {
"type": "base64",
"media_type": mime_type or "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"data": base64.b64encode(file.read()).decode('utf-8')
}
}
})
the error is raise error_class(parsed_response, operation_name)
botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the InvokeModel operation: messages.0.content.1.image.source: Field required
my invocation is
response = self.bedrock_client.invoke_model(modelId=payload["modelId"], body=payload["body"])