Use BedrockConverse to send image (or document) ChatMessages #14729
Replies: 1 comment 1 reply
|
Thanks for laying this out so precisely, with both Converse payload shapes side by side and a pointer to the exact conversion function. That made it quick to check against the current code. Short answer: this is supported now. from llama_index.core.base.llms.types import ChatMessage, TextBlock, ImageBlock, DocumentBlock
from llama_index.llms.bedrock_converse import BedrockConverse
llm = BedrockConverse(model="anthropic.claude-3-5-sonnet-20240620-v1:0", region_name="us-east-1")
msg = ChatMessage(
role="user",
blocks=[
TextBlock(text="Describe the image and quote the document."),
ImageBlock(image=png_bytes, image_mimetype="image/png"), # or ImageBlock(path="pixel.png")
DocumentBlock(data=txt_bytes, document_mimetype="text/plain", title="notes"), # or DocumentBlock(path="report.pdf", title="report")
],
)
resp = llm.chat([msg])What {
"role": "user",
"content": [
{"text": "Describe the image and quote the document."},
{"image": {"format": "png", "source": {"bytes": "<70 raw bytes, head=b'\\x89PNG\\r\\n\\x1a\\n'>"}}},
{"document": {"format": "txt", "name": "notes", "source": {"bytes": "<29 raw bytes, head=b'The secr'>"}}}
]
}Live call and a few details from the code pathSame message sent for real in us-east-1. Claude Sonnet 4 came back with a "marked as Legacy" error on my account, so this is Sonnet 4.5. The image was a 1x1 PNG and the document a text file containing "The secret word is pineapple." From
|
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I'm wondering how I could use BedrockConverse to send an image (or document), rather than a plain text,
ChatMessageto the model (in my case, Anthropic Claude Sonnet 3.5). In other words, rather than sending this:... I'd like to send this:
Both formats are taken from the respective AWS documentation page
From a quick look at the conversion code in
bedrock_converse/utils.pyit looks like this is currently not supported.Or am I missing something?
All reactions