Skip to content

Commit 35e0194

Browse files
Add support for base64 images in chat messages
Handle base64 image data for Llama 4 in chat messages.
1 parent f7c11c8 commit 35e0194

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/workers-ai-provider/src/convert-to-workersai-chat-messages.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ export function convertToWorkersAIChatMessages(prompt: LanguageModelV2Prompt): {
4242
providerOptions: part.providerOptions,
4343
});
4444
}
45+
// For Llama 4, images are expected to be in the input messages array in base64
46+
if (typeof part.data === "string") {
47+
return {
48+
image_url: {url : `data:${part.mimeType};base64,${part.data}`},
49+
type: "image_url",
50+
mimeType: part.mediaType,
51+
providerOptions: part.providerOptions
52+
}
53+
}
4554
return ""; // No text for the image part
4655
}
4756
}

0 commit comments

Comments
 (0)