Skip to content

Commit 38d59e2

Browse files
authored
Merge pull request #141 from Yanyutin753/优化web搜索输出
🦄 优化web搜索输出
2 parents b2ae055 + bc37f56 commit 38d59e2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/api/controllers/chat.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ function checkResult(result: AxiosResponse, refreshToken: string) {
723723
* @param stream 消息流
724724
*/
725725
async function receiveStream(model: string, convId: string, stream: any) {
726+
let webSearchCount = 0;
726727
return new Promise((resolve, reject) => {
727728
// 消息初始化
728729
const data = {
@@ -756,8 +757,10 @@ async function receiveStream(model: string, convId: string, stream: any) {
756757
resolve(data);
757758
}
758759
// 处理联网搜索
759-
else if (!silentSearch && result.event == 'search_plus' && result.msg && result.msg.type == 'get_res')
760-
refContent += `${result.msg.title} - ${result.msg.url}\n`;
760+
else if (!silentSearch && result.event == 'search_plus' && result.msg && result.msg.type == 'get_res'){
761+
webSearchCount += 1;
762+
refContent += `【检索 ${webSearchCount}】 [${result.msg.title}](${result.msg.url})\n\n`;
763+
}
761764
// else
762765
// logger.warn(result.event, result);
763766
}
@@ -788,6 +791,7 @@ function createTransStream(model: string, convId: string, stream: any, endCallba
788791
const created = util.unixTimestamp();
789792
// 创建转换流
790793
const transStream = new PassThrough();
794+
let webSearchCount = 0;
791795
let searchFlag = false;
792796
const silentSearch = model.indexOf('silent_search') != -1;
793797
!transStream.closed && transStream.write(`data: ${JSON.stringify({
@@ -847,14 +851,15 @@ function createTransStream(model: string, convId: string, stream: any, endCallba
847851
else if (!silentSearch && result.event == 'search_plus' && result.msg && result.msg.type == 'get_res') {
848852
if (!searchFlag)
849853
searchFlag = true;
854+
webSearchCount += 1;
850855
const data = `data: ${JSON.stringify({
851856
id: convId,
852857
model,
853858
object: 'chat.completion.chunk',
854859
choices: [
855860
{
856861
index: 0, delta: {
857-
content: `检索 ${result.msg.title} - ${result.msg.url} ...\n`
862+
content: `检索 ${webSearchCount}】 [${result.msg.title}](${result.msg.url})\n`
858863
}, finish_reason: null
859864
}
860865
],

0 commit comments

Comments
 (0)