aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools/NoTool.ts
diff options
context:
space:
mode:
authorA.J. Shulman <Shulman.aj@gmail.com>2024-10-15 14:18:44 -0400
committerA.J. Shulman <Shulman.aj@gmail.com>2024-10-15 14:18:44 -0400
commit596502c232ea6b6b88c3c58486e139074ea056ff (patch)
treecbdabc8375ae91415b5243648e87c097b440b00c /src/client/views/nodes/chatbot/tools/NoTool.ts
parentfc06a98deec3fa2b173f8ea30a4f4b1781447b19 (diff)
tried something for typechecking but way too overcomplicated
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/NoTool.ts')
-rw-r--r--src/client/views/nodes/chatbot/tools/NoTool.ts54
1 files changed, 43 insertions, 11 deletions
diff --git a/src/client/views/nodes/chatbot/tools/NoTool.ts b/src/client/views/nodes/chatbot/tools/NoTool.ts
index edd3160ec..103abcdbe 100644
--- a/src/client/views/nodes/chatbot/tools/NoTool.ts
+++ b/src/client/views/nodes/chatbot/tools/NoTool.ts
@@ -1,19 +1,51 @@
-// tools/NoTool.ts
+import { v4 as uuidv4 } from 'uuid';
+import { Networking } from '../../../../Network';
import { BaseTool } from './BaseTool';
+import { Observation } from '../types/types';
-export class NoTool extends BaseTool<Record<string, unknown>> {
- constructor() {
+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(
- 'no_tool',
- 'Use this when no external tool or action is required to answer the question.',
- {},
- 'When using the "no_tool" action, simply provide an empty <action_input> element. The observation will always be "No tool used. Proceed with answering the question."',
- 'Use when no external tool or action is required to answer the question.'
+ 'searchTool',
+ 'Search the web to find a wide range of websites related to a query or multiple queries',
+ {
+ query: {
+ type: 'string',
+ description: 'The search query or queries to use for finding websites',
+ required: true,
+ },
+ },
+ '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;
}
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- async execute(args: object): Promise<unknown> {
- return [{ type: 'text', text: 'No tool used. Proceed with answering the question.' }];
+ 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 = 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>`,
+ };
+ });
+ allResults.push(...data);
+ } catch (error) {
+ console.log(error);
+ allResults.push({ type: 'text', text: `An error occurred while performing the web search for query: ${query}` });
+ }
+ }
+
+ return allResults;
}
}