fix(gemini): improve base64 image data parsing

This commit is contained in:
decolua
2026-01-09 17:17:08 +07:00
parent 18533505ef
commit 5645d0a0fb
+8 -3
View File
@@ -27,10 +27,15 @@ export function convertOpenAIContentToParts(content) {
if (item.type === "text") { if (item.type === "text") {
parts.push({ text: item.text }); parts.push({ text: item.text });
} else if (item.type === "image_url" && item.image_url?.url?.startsWith("data:")) { } else if (item.type === "image_url" && item.image_url?.url?.startsWith("data:")) {
const match = item.image_url.url.match(/^data:([^;]+);base64,(.+)$/); const url = item.image_url.url;
if (match) { const commaIndex = url.indexOf(",");
if (commaIndex !== -1) {
const mimePart = url.substring(5, commaIndex); // skip "data:"
const data = url.substring(commaIndex + 1);
const mimeType = mimePart.split(";")[0];
parts.push({ parts.push({
inlineData: { mime_type: match[1], data: match[2] } inlineData: { mime_type: mimeType, data: data }
}); });
} }
} }