mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
fix(gemini): improve base64 image data parsing
This commit is contained in:
@@ -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 }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user