1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
import { Networking } from '../../../../Network';
import { BaseTool } from './BaseTool';
import { v4 as uuidv4 } from 'uuid';
export class SearchTool extends BaseTool<{ query: string }> {
private _addLinkedUrlDoc: (url: string, id: string) => void;
constructor(addLinkedUrlDoc: (url: string, id: string) => void) {
super(
'searchTool',
'Search the web to find a wide range of websites related to a query',
{
query: {
type: 'string',
description: 'The search query to use for finding websites',
required: true,
},
},
'Provide a search query to find a broad range of websites. This tool is intended to help you identify relevant websites, but not to be used for providing the final answer. Use this information to determine which specific website to investigate further.',
'Returns a list of websites and their overviews based on the search query, helping to identify which website might contain the most relevant information.'
);
this._addLinkedUrlDoc = addLinkedUrlDoc;
}
async execute(args: { query: string }): Promise<any> {
try {
const { results } = await Networking.PostToServer('/getWebSearchResults', { query: args.query });
console.log(results);
const data: { type: string; text: string }[] = results.map((result: { url: string; snippet: string }) => {
console.log;
const id = uuidv4();
this._addLinkedUrlDoc(result.url, id);
return {
type: 'text',
text: `<chunk chunk_id="${id}" chunk_type="text">
<url>${result.url}</url>
<overview>${result.snippet}</overview>
</chunk>`,
};
});
return data;
} catch (error) {
console.log(error);
return [{ type: 'text', text: 'An error occurred while performing the web search.' }];
}
}
}
|