mirror of
https://github.com/sune-org/ORP.git
synced 2026-01-14 00:27:59 +00:00
feat: update index.js
This commit is contained in:
18
index.js
18
index.js
@@ -223,10 +223,20 @@ export class MyDurableObject {
|
|||||||
|
|
||||||
mapToGoogleContents(messages) {
|
mapToGoogleContents(messages) {
|
||||||
const contents = messages.reduce((acc, m) => {
|
const contents = messages.reduce((acc, m) => {
|
||||||
const role = m.role === 'assistant' ? 'model' : 'user', text = this.extractTextFromMessage(m);
|
const role = m.role === 'assistant' ? 'model' : 'user';
|
||||||
if (!text) return acc;
|
const msgContent = Array.isArray(m.content) ? m.content : [{ type: 'text', text: String(m.content ?? '') }];
|
||||||
if (acc.length > 0 && acc.at(-1).role === role) acc.at(-1).parts.push({ text });
|
const parts = msgContent.map(p => {
|
||||||
else acc.push({ role, parts: [{ text }] });
|
if (p.type === 'text') return { text: p.text || '' };
|
||||||
|
if (p.type === 'image_url' && p.image_url?.url) {
|
||||||
|
const match = p.image_url.url.match(/^data:(image\/\w+);base64,(.*)$/);
|
||||||
|
if (match) return { inline_data: { mime_type: match[1], data: match[2] } };
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}).filter(Boolean);
|
||||||
|
|
||||||
|
if (!parts.length) return acc;
|
||||||
|
if (acc.length > 0 && acc.at(-1).role === role) acc.at(-1).parts.push(...parts);
|
||||||
|
else acc.push({ role, parts });
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
if (contents.at(-1)?.role !== 'user') contents.pop();
|
if (contents.at(-1)?.role !== 'user') contents.pop();
|
||||||
|
|||||||
Reference in New Issue
Block a user