From 53f3365872df9a9cb5b736dc19d941885560d811 Mon Sep 17 00:00:00 2001 From: Vinlic Date: Mon, 6 May 2024 11:19:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=9D=9E=E6=B5=81=E5=BC=8F?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E7=BB=93=E6=9E=9C=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/controllers/chat.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/api/controllers/chat.ts b/src/api/controllers/chat.ts index dbefe68..a6b98e9 100644 --- a/src/api/controllers/chat.ts +++ b/src/api/controllers/chat.ts @@ -731,6 +731,7 @@ async function receiveStream(stream: any): Promise { let codeTemp = ""; let lastExecutionOutput = ""; let textOffset = 0; + let refContent = ''; const parser = createParser((event) => { try { if (event.type !== "event") return; @@ -772,14 +773,9 @@ async function receiveStream(stream: any): Promise { meta_data && _.isArray(meta_data.metadata_list) ) { - const searchText = - meta_data.metadata_list.reduce( - (meta, v) => meta + `检索 ${v.title}(${v.url}) ...`, - "" - ) + "\n"; - textOffset += searchText.length; - toolCall = true; - return innerStr + searchText; + refContent = meta_data.metadata_list.reduce((meta, v) => { + return meta + `${v.title} - ${v.url}\n`; + }, refContent); } else if ( type == "image" && _.isArray(image) && @@ -839,7 +835,7 @@ async function receiveStream(stream: any): Promise { data.choices[0].message.content += chunk; } else { data.choices[0].message.content = - data.choices[0].message.content.replace(/【\d+†来源】/g, ""); + data.choices[0].message.content.replace(/【\d+†(来源|source)】/g, "") + (refContent ? `\n\n搜索结果来自:\n${refContent.replace(/\n$/, '')}` : ''); resolve(data); } } catch (err) {