diff options
| author | bobzel <zzzman@gmail.com> | 2024-10-10 19:04:57 -0400 |
|---|---|---|
| committer | bobzel <zzzman@gmail.com> | 2024-10-10 19:04:57 -0400 |
| commit | 3a35e2687e3c7b0c864dd4f00b1002ff088b56d3 (patch) | |
| tree | 98697432c5be99a0e1b64cc42eff9e7a0ec58457 /src/client/views/nodes/chatbot/tools/WikipediaTool.ts | |
| parent | f75f15ae58b57644c28d42446c176289bbe55dd4 (diff) | |
| parent | d347fc59feefd91a796012892da57511787bb6d0 (diff) | |
merged with master
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/WikipediaTool.ts')
| -rw-r--r-- | src/client/views/nodes/chatbot/tools/WikipediaTool.ts | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/client/views/nodes/chatbot/tools/WikipediaTool.ts b/src/client/views/nodes/chatbot/tools/WikipediaTool.ts new file mode 100644 index 000000000..692dff749 --- /dev/null +++ b/src/client/views/nodes/chatbot/tools/WikipediaTool.ts @@ -0,0 +1,36 @@ +import { v4 as uuidv4 } from 'uuid'; +import { Networking } from '../../../../Network'; +import { BaseTool } from './BaseTool'; + +export class WikipediaTool extends BaseTool<{ title: string }> { + 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, + }, + }, + '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<unknown> { + 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>` }]; + } catch (error) { + console.log(error); + return [{ type: 'text', text: 'An error occurred while fetching the article.' }]; + } + } +} |
