Open mentatbot[bot] opened 2 weeks ago
@mentatbot - you didn't implement the API call correctly in "message_to_anthropic_message.register(UserImageMessage)"
here are two examples
import anthropic
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-3-5-sonnet-20240620",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": image1_media_type,
"data": image1_data,
},
},
{
"type": "text",
"text": "Describe this image."
}
],
}
],
)
print(message)
message = client.messages.create(
model="claude-3-5-sonnet-20240620",
max_tokens=1024,
system="Respond only in Spanish.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "Image 1:"
},
{
"type": "image",
"source": {
"type": "base64",
"media_type": image1_media_type,
"data": image1_data,
},
},
{
"type": "text",
"text": "Image 2:"
},
{
"type": "image",
"source": {
"type": "base64",
"media_type": image2_media_type,
"data": image2_data,
},
},
{
"type": "text",
"text": "How are these images different?"
}
],
}
],
)
This commit adds support for converting
UserImageMessage
to the Anthropic message format. The implementation mirrors the existingmessage_to_openai_message
function, ensuring compatibility with image messages for Anthropic models.Changes include:
UserImageMessage
inanthropic_chat_model.py
.vision.py
to register the new function and ensure proper role assignment.This enhancement allows the use of image messages with Anthropic models, similar to the existing support for OpenAI models.
Closes #3