aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools/SearchTool.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/SearchTool.ts')
-rw-r--r--src/client/views/nodes/chatbot/tools/SearchTool.ts20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/client/views/nodes/chatbot/tools/SearchTool.ts b/src/client/views/nodes/chatbot/tools/SearchTool.ts
index 3a4668422..103abcdbe 100644
--- a/src/client/views/nodes/chatbot/tools/SearchTool.ts
+++ b/src/client/views/nodes/chatbot/tools/SearchTool.ts
@@ -1,10 +1,12 @@
import { v4 as uuidv4 } from 'uuid';
import { Networking } from '../../../../Network';
import { BaseTool } from './BaseTool';
+import { Observation } from '../types/types';
-export class SearchTool extends BaseTool<{ query: string | string[] }> {
+export class SearchTool extends BaseTool<{ query: { type: string | string[]; description: string; required: boolean } }> {
private _addLinkedUrlDoc: (url: string, id: string) => void;
private _max_results: number;
+
constructor(addLinkedUrlDoc: (url: string, id: string) => void, max_results: number = 5) {
super(
'searchTool',
@@ -13,32 +15,28 @@ export class SearchTool extends BaseTool<{ query: string | string[] }> {
query: {
type: 'string',
description: 'The search query or queries to use for finding websites',
- required: 'true',
- max_inputs: '3',
+ required: true,
},
},
- 'Provide up to 3 search queries 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 queries, helping to identify which websites might contain relevant information.'
+ 'Provide up to 3 search queries to find a broad range of websites.',
+ 'Returns a list of websites and their overviews based on the search queries.'
);
this._addLinkedUrlDoc = addLinkedUrlDoc;
this._max_results = max_results;
}
- async execute(args: { query: string | string[] }): Promise<unknown> {
+ async execute(args: { query: string | string[] }): Promise<Observation[]> {
const queries = Array.isArray(args.query) ? args.query : [args.query];
const allResults = [];
for (const query of queries) {
try {
const { results } = await Networking.PostToServer('/getWebSearchResults', { query, max_results: this._max_results });
- const data: { type: string; text: string }[] = results.map((result: { url: string; snippet: string }) => {
+ const data = results.map((result: { url: string; snippet: string }) => {
const id = uuidv4();
return {
type: 'text',
- text: `<chunk chunk_id="${id}" chunk_type="text">
- <url>${result.url}</url>
- <overview>${result.snippet}</overview>
- </chunk>`,
+ text: `<chunk chunk_id="${id}" chunk_type="text"><url>${result.url}</url><overview>${result.snippet}</overview></chunk>`,
};
});
allResults.push(...data);