aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
diff options
context:
space:
mode:
authoreleanor-park <eleanor_park@brown.edu>2024-10-30 19:39:46 -0400
committereleanor-park <eleanor_park@brown.edu>2024-10-30 19:39:46 -0400
commitc11c760db62f78a07b624b98b209e6ee86036c8e (patch)
treec9587b50042a5115373e91ba8ecf9b76913cd321 /src/client/views/nodes/chatbot/tools/WikipediaTool.ts
parentb5944e87f9d4f3149161de4de0d76db486461c76 (diff)
parent4c768162e0436115a05b9c8b0e4d837d626d45ba (diff)
Merge branch 'master' into eleanor-gptdraw
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/WikipediaTool.ts')
-rw-r--r--src/client/views/nodes/chatbot/tools/WikipediaTool.ts33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/client/views/nodes/chatbot/tools/WikipediaTool.ts b/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
index 692dff749..4fcffe2ed 100644
--- a/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
+++ b/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
@@ -1,33 +1,46 @@
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<unknown> {
+ 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.' }];