File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -312,6 +312,7 @@ export const webSearchTool: Tool = {
312312用户提供这个工具通常是对你的知识储备或判断持怀疑态度,希望通过网络搜索获取更权威或更新的信息。
313313你可以用它来补充自己的回答,确保回答准确且有据可依。
314314当问到你依稀技术名词的时候,你没有把握就不要乱说,先联网搜索。因为大模型很容易产生幻觉,以为自己什么都懂。
315+ 使用完这些搜索到的信息以后,你还应该输出所有被你采纳信息的来源,也就是url,方便用户核实
315316
316317使用场景:
317318- 获取最新信息: 例如,用户询问“2023年最好的编程语言是什么?”
@@ -343,15 +344,28 @@ export const webSearchTool: Tool = {
343344 return '未找到相关结果' ;
344345 }
345346
347+ // 修改结果处理部分
346348 const results = await Promise . all (
347349 links . map ( link =>
348350 fetchPageContent ( link as string )
349- . catch ( e => `抓取失败: ${ link } (${ e . message } )` )
351+ . then ( content => ( {
352+ url : link ,
353+ content : content
354+ } ) )
355+ . catch ( e => ( {
356+ url : link ,
357+ content : `抓取失败: ${ e . message } `
358+ } ) )
350359 )
351360 ) ;
352361
362+ // 添加URL信息到返回结果
353363 return results
354- . map ( ( res , i ) => `【结果${ i + 1 } 】\n${ res } ` )
364+ . map ( ( res , i ) =>
365+ `【结果${ i + 1 } 】\n` +
366+ `来源:${ res . url } \n` +
367+ `内容摘要:${ res . content . slice ( 0 , 500 ) } ...` // 限制内容长度
368+ )
355369 . join ( '\n\n' ) ;
356370 } catch ( error : any ) {
357371 return `搜索失败: ${ error . message } ` ;
You can’t perform that action at this time.
0 commit comments