aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/ChatBox/tools/DataAnalysisTool.ts
blob: d2edc484791909e097aee457b45179a45f1ae1ae (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
import { BaseTool } from './BaseTool';

export class DataAnalysisTool extends BaseTool<{ csv_file_name: string }> {
    private csv_files_function: () => { [filename: string]: string };
    constructor(csv_files: () => { [filename: string]: string }) {
        super(
            'dataAnalysis',
            'Analyzes, and provides insights, from a CSV file',
            {
                csv_file_name: {
                    type: 'string',
                    description: 'Name of the CSV file to analyze',
                    required: 'true',
                },
            },
            'Provide the name of the CSV file to analyze based on the user query and whichever available CSV file may be relevant.',
            'Provides the full CSV file text for your analysis based on the user query and the available CSV file. '
        );
        this.csv_files_function = csv_files;
    }

    getFileContent(filename: string): string | undefined {
        const files = this.csv_files_function();
        return files[filename];
    }

    async execute(args: { csv_file_name: string }): Promise<any> {
        return [{ type: 'text', text: this.getFileContent(args.csv_file_name) }];
    }
}