aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/ChatBox/tools/WikipediaTool.ts
diff options
context:
space:
mode:
authorA.J. Shulman <Shulman.aj@gmail.com>2024-08-15 13:16:32 -0400
committerA.J. Shulman <Shulman.aj@gmail.com>2024-08-15 13:16:32 -0400
commit6f9b8f9b393d411a17f7954b6cc36618efe698e2 (patch)
tree8090d9d0bafdfe3e97b8fd8914da9d1264e4172c /src/client/views/nodes/ChatBox/tools/WikipediaTool.ts
parent0c8001c61a55540cdeeb6ae249fdd2835580121c (diff)
implemented search tool and other tools but scraping doesn't work
Diffstat (limited to 'src/client/views/nodes/ChatBox/tools/WikipediaTool.ts')
-rw-r--r--src/client/views/nodes/ChatBox/tools/WikipediaTool.ts10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/client/views/nodes/ChatBox/tools/WikipediaTool.ts b/src/client/views/nodes/ChatBox/tools/WikipediaTool.ts
index e2c5009a1..143d91d80 100644
--- a/src/client/views/nodes/ChatBox/tools/WikipediaTool.ts
+++ b/src/client/views/nodes/ChatBox/tools/WikipediaTool.ts
@@ -2,9 +2,11 @@ import { title } from 'process';
import { Networking } from '../../../../Network';
import { BaseTool } from './BaseTool';
import axios from 'axios';
+import { v4 as uuidv4 } from 'uuid';
export class WikipediaTool extends BaseTool<{ title: string }> {
- constructor() {
+ private _addLinkedUrlDoc: (url: string, id: string) => void;
+ constructor(addLinkedUrlDoc: (url: string, id: string) => void) {
super(
'wikipedia',
'Search Wikipedia and return a summary',
@@ -18,12 +20,16 @@ export class WikipediaTool extends BaseTool<{ title: string }> {
'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<any> {
try {
const { text } = await Networking.PostToServer('/getWikipediaSummary', { title: args.title });
- return [{ type: 'text', text: text }];
+ 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) {
return [{ type: 'text', text: 'An error occurred while fetching the article.' }];
}