I'm trying to upload an image to AWS Bedrock Claude model using the ConverseCommand (in @aws-sdk/client-bedrock-runtime 3.699.0).
I have the base64 version of image (eg https://yulvil.github.io/gopherjs/02/)
According to the documentation, it requires the bytes as a Uint8Array, so I've tried
bytes: new Uint8Array(Buffer.from(img, 'utf-8'))bytes: Buffer.from(img, 'utf-8')bytes: new TextEncoder().encode(ing)
None seem to work having error ValidationException: The model returned the following errors: messages.0.content.1.image.source.bytes: Invalid image input
What am I missing?
const {
BedrockRuntimeClient,
ConverseCommand,
} = require("@aws-sdk/client-bedrock-runtime");
const modelId = "anthropic.claude-3-haiku-20240307-v1:0";
let conversation = [];
const describeImage = async () => {
const client = new BedrockRuntimeClient({
region: "us-east-1",
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
});
let content = [];
const img = “data:image/png;base64,...”
content.push({
image: {
format: "png",
source: {
bytes: img,
},
},
});
content.push({ text: “Describe the given image” });
conversation.push({
role: "user",
content,
});
try {
const response = await client.send(
new ConverseCommand({
modelId,
messages: conversation,
})
);
return response.output.message.content[0].text;
} catch (err) {
console.log(`ERROR: Can't invoke '${modelId}'. Reason: ${err}`);
}
describeImage();