diff options
| author | A.J. Shulman <Shulman.aj@gmail.com> | 2024-10-17 10:41:49 -0400 |
|---|---|---|
| committer | A.J. Shulman <Shulman.aj@gmail.com> | 2024-10-17 10:41:49 -0400 |
| commit | 80d86bd5ae3e1d3dc70e7636f72a872a5fb2f01d (patch) | |
| tree | 0eaea49f596bd16720f05a6535958ab8270673c8 /src/client/views/nodes/chatbot/tools/WikipediaTool.ts | |
| parent | 596502c232ea6b6b88c3c58486e139074ea056ff (diff) | |
Implemented strict typechecking for tools, specifically tool inputs
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/WikipediaTool.ts')
| -rw-r--r-- | src/client/views/nodes/chatbot/tools/WikipediaTool.ts | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/client/views/nodes/chatbot/tools/WikipediaTool.ts b/src/client/views/nodes/chatbot/tools/WikipediaTool.ts index ee5661905..4fcffe2ed 100644 --- a/src/client/views/nodes/chatbot/tools/WikipediaTool.ts +++ b/src/client/views/nodes/chatbot/tools/WikipediaTool.ts @@ -2,33 +2,45 @@ import { v4 as uuidv4 } from 'uuid'; import { Networking } from '../../../../Network'; import { BaseTool } from './BaseTool'; import { Observation } from '../types/types'; +import { ParametersType } from './ToolTypes'; -export class WikipediaTool extends BaseTool<{ title: string }> { +const wikipediaToolParams = [ + { + name: 'title', + type: 'string', + description: 'The title of the Wikipedia article to search', + required: true, + }, +] as const; + +type WikipediaToolParamsType = typeof wikipediaToolParams; + +export class WikipediaTool extends BaseTool<WikipediaToolParamsType> { private _addLinkedUrlDoc: (url: string, id: string) => void; + constructor(addLinkedUrlDoc: (url: string, id: string) => void) { super( 'wikipedia', 'Search Wikipedia and return a summary', - { - title: { - type: 'string', - description: 'The title of the Wikipedia article to search', - required: true, - }, - }, + wikipediaToolParams, 'Provide simply the title you want to search on Wikipedia and nothing more. If re-using this tool, try a different title for different information.', 'Returns a summary from searching an article title on Wikipedia' ); this._addLinkedUrlDoc = addLinkedUrlDoc; } - async execute(args: { title: string }): Promise<Observation[]> { + async execute(args: ParametersType<WikipediaToolParamsType>): Promise<Observation[]> { try { const { text } = await Networking.PostToServer('/getWikipediaSummary', { title: args.title }); const id = uuidv4(); const url = `https://en.wikipedia.org/wiki/${args.title.replace(/ /g, '_')}`; this._addLinkedUrlDoc(url, id); - return [{ type: 'text', text: `<chunk chunk_id=${id} chunk_type=csv}> ${text} </chunk>` }]; + return [ + { + type: 'text', + text: `<chunk chunk_id="${id}" chunk_type="text"> ${text} </chunk>`, + }, + ]; } catch (error) { console.log(error); return [{ type: 'text', text: 'An error occurred while fetching the article.' }]; |
