aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools/FileNamesTool.ts
blob: b69874afadfc57bdf2aae77fbe6a86395439b8d5 (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
32
33
34
import { Observation } from '../types/types';
import { ParametersType, ToolInfo } from '../types/tool_types';
import { Vectorstore } from '../vectorstore/Vectorstore';
import { BaseTool } from './BaseTool';

const fileNamesToolParams = [] as const;

type FileNamesToolParamsType = typeof fileNamesToolParams;

const fileNamesToolInfo: ToolInfo<FileNamesToolParamsType> = {
    name: 'fileNames',
    description: 'Retrieves the names of all files in the Dash codebase to help understand the codebase structure.',
    citationRules: `No citation needed.`,
    parameterRules: fileNamesToolParams,
};

export class FileNamesTool extends BaseTool<FileNamesToolParamsType> {
    constructor(private vectorstore: Vectorstore) {
        super(fileNamesToolInfo);
    }

    async execute(args: ParametersType<FileNamesToolParamsType>): Promise<Observation[]> {
        console.log(`Executing file names retrieval`);

        const filepaths = await this.vectorstore.getFileNames();

        return [
            {
                type: 'text',
                text: `The file names in the codebase are: ${filepaths}`,
            },
        ];
    }
}