From 41c9488e8462c80cf17d1bb378d588312fd013de Mon Sep 17 00:00:00 2001 From: Vinlic Date: Mon, 25 Mar 2024 11:25:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dqwen=E6=B5=81=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E5=BC=82=E5=B8=B8=E5=AD=97=E7=AC=A6=E6=97=B6=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=B5=81=E6=96=87=E6=9C=AC=E5=88=86=E5=89=B2=E5=BC=82?= =?UTF-8?q?=E5=B8=B8-=E6=A2=85=E5=BC=80=E4=BA=8C=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/controllers/chat.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/api/controllers/chat.ts b/src/api/controllers/chat.ts index 969b8f9..52f61bc 100644 --- a/src/api/controllers/chat.ts +++ b/src/api/controllers/chat.ts @@ -262,9 +262,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 [ { @@ -327,10 +326,7 @@ async function receiveStream(stream: any): Promise { return str + content; }, ""); const exceptCharIndex = text.indexOf('�'); - let chunk = text.substring( - data.choices[0].message.content.length, - exceptCharIndex == -1 ? text.length : exceptCharIndex - ); + let chunk = text.substring(exceptCharIndex != -1 ? Math.min(data.choices[0].message.content.length, exceptCharIndex) : data.choices[0].message.content.length, exceptCharIndex == -1 ? text.length : exceptCharIndex); if (chunk && result.contentType == "text2image") { chunk = chunk.replace( /https?:\/\/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=\,]*)/gi, @@ -409,7 +405,7 @@ function createTransStream(stream: any, endCallback?: Function) { return str + content; }, ""); const exceptCharIndex = text.indexOf('�'); - let chunk = text.substring(content.length, exceptCharIndex == -1 ? text.length : exceptCharIndex); + let chunk = text.substring(exceptCharIndex != -1 ? Math.min(content.length, exceptCharIndex) : content.length, exceptCharIndex == -1 ? text.length : exceptCharIndex); if (chunk && result.contentType == "text2image") { chunk = chunk.replace( /https?:\/\/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=\,]*)/gi,