From 3bb2a93211976a0151ba66a3f17e554e20d15b78 Mon Sep 17 00:00:00 2001 From: Vinlic Date: Thu, 28 Mar 2024 18:43:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B6=88=E6=81=AF=E4=B8=AD?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E6=8F=92=E4=BB=B6=E8=B0=83=E7=94=A8=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=86=85=E5=AE=B9=E7=9A=84=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 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/api/controllers/chat.ts b/src/api/controllers/chat.ts index 9f24388..0e61e96 100644 --- a/src/api/controllers/chat.ts +++ b/src/api/controllers/chat.ts @@ -323,9 +323,8 @@ function messagesPrepare(messages: any[]) { return _content + (v["text"] || ""); }, content); } - return (content += `<|im_start|>${message.role || "user"}\n${ - message.content - }<|im_end|>\n`); + return (content += `<|im_start|>${message.role || "user"}\n${message.content + }<|im_end|>\n`); }, ""); return [ { @@ -383,7 +382,9 @@ async function receiveStream(stream: any): Promise { throw new Error(`Stream response invalid: ${event.data}`); if (!data.id && result.sessionId) data.id = result.sessionId; const text = (result.contents || []).reduce((str, part) => { - const { role, content } = part; + const { contentType, role, content } = part; + console.log(part); + if (contentType != 'text' && contentType != 'text2image') return str; if (role != "assistant" && !_.isString(content)) return str; return str + content; }, ""); @@ -467,7 +468,8 @@ function createTransStream(stream: any, endCallback?: Function) { if (_.isError(result)) throw new Error(`Stream response invalid: ${event.data}`); const text = (result.contents || []).reduce((str, part) => { - const { role, content } = part; + const { contentType, role, content } = part; + if (contentType != 'text' && contentType != 'text2image') return str; if (role != "assistant" && !_.isString(content)) return str; return str + content; }, "");