From cbb14b0198a4f85b3fbce57851df1b8f5b5c6181 Mon Sep 17 00:00:00 2001 From: Vinlic Date: Sun, 17 Mar 2024 18:18:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E5=83=8F=E8=A7=A3=E6=9E=90=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/controllers/chat.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/api/controllers/chat.ts b/src/api/controllers/chat.ts index 2b3f73f..8529ba5 100644 --- a/src/api/controllers/chat.ts +++ b/src/api/controllers/chat.ts @@ -316,14 +316,23 @@ function messagesPrepare(messages: any[], refs: any[]) { const role = message.role.replace('user', '我').replace('assistant', '你') || '我'; return content += `${role}:${message.content}\n你:`; }, ''); + const fileRefs = refs.filter(ref => !ref.width && !ref.height); + const imageRefs = refs.filter(ref => ref.width || ref.height).map(ref => { + ref.image_url = ref.file_url; + return ref; + }); return [ { role: 'user', content: [ { type: 'text', text: headPrompt + content }, - ...(refs.length == 0 ? [] : [{ + ...(fileRefs.length == 0 ? [] : [{ type: 'file', - file: refs + file: fileRefs + }]), + ...(imageRefs.length == 0 ? [] : [{ + type: 'image', + image: imageRefs }]) ] }