Skip to content

Commit 778539b

Browse files
celestial-roseRoz
authored andcommitted
Add support for base64 images in chat messages
Handle base64 image data for Llama 4 in chat messages.
1 parent f7c11c8 commit 778539b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ 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" && part.mediaType.startsWith('image/')) {
47+
return {
48+
image_url: {
49+
url: `data:${part.mediaType};base64,${part.data}`,
50+
},
51+
type: "image_url",
52+
mimeType: part.mediaType,
53+
providerOptions: part.providerOptions,
54+
}
55+
}
4556
return ""; // No text for the image part
4657
}
4758
}

0 commit comments

Comments
 (0)