From f453c075e2f080c30e090dc6b622589e7fe2ce5f Mon Sep 17 00:00:00 2001 From: Yanyutin753 <132346501+Yanyutin753@users.noreply.github.com> Date: Tue, 2 Apr 2024 15:21:03 +0800 Subject: [PATCH] =?UTF-8?q?try=20fix=20=E4=B8=8A=E4=B8=8B=E6=96=87?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=81=8A=E5=A4=A9=E4=B8=8D?= =?UTF-8?q?=E8=BF=9E=E8=B4=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/controllers/chat.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/api/controllers/chat.ts b/src/api/controllers/chat.ts index b0b0486..ba6a19c 100644 --- a/src/api/controllers/chat.ts +++ b/src/api/controllers/chat.ts @@ -495,6 +495,19 @@ function messagesPrepare(messages: any[], refs: any[]) { return !message.content.some(v => (typeof v === 'object' && ['file', 'image_url'].includes(v['type']))); }); + // 检查最新消息是否含有"type": "image_url"或"type": "file",如果有则注入消息 + let latestMessage = validMessages[validMessages.length - 1]; + let hasFileOrImage = Array.isArray(latestMessage.content) + && latestMessage.content.some(v => (typeof v === 'object' && ['file', 'image_url'].includes(v['type']))); + if (hasFileOrImage) { + // newMessage是一个用于指示文件的消息,是的模型能正常回答出相应的问题 + let newMessage = { + "content": "持续关注用户最新发送的文件和消息的结尾", + "role": "system" + }; + validMessages.splice(validMessages.length - 1, 0, newMessage); + } + const content = validMessages.reduce((content, message) => { if (_.isArray(message.content)) {