aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/ChatBox/tools/WikipediaTool.ts
blob: e2c5009a14b33c44c33419e46a3c582422b6fd4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { title } from 'process';
import { Networking } from '../../../../Network';
import { BaseTool } from './BaseTool';
import axios from 'axios';

export class WikipediaTool extends BaseTool<{ title: string }> {
    constructor() {
        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'
        );
    }

    async execute(args: { title: string }): Promise<any> {
        try {
            const { text } = await Networking.PostToServer('/getWikipediaSummary', { title: args.title });
            return [{ type: 'text', text: text }];
        } catch (error) {
            return [{ type: 'text', text: 'An error occurred while fetching the article.' }];
        }
    }
}