diff options
| author | eleanor-park <eleanor_park@brown.edu> | 2024-10-30 19:39:46 -0400 |
|---|---|---|
| committer | eleanor-park <eleanor_park@brown.edu> | 2024-10-30 19:39:46 -0400 |
| commit | c11c760db62f78a07b624b98b209e6ee86036c8e (patch) | |
| tree | c9587b50042a5115373e91ba8ecf9b76913cd321 /src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts | |
| parent | b5944e87f9d4f3149161de4de0d76db486461c76 (diff) | |
| parent | 4c768162e0436115a05b9c8b0e4d837d626d45ba (diff) | |
Merge branch 'master' into eleanor-gptdraw
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts')
| -rw-r--r-- | src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts b/src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts index 2e663fed1..d9b75219d 100644 --- a/src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts +++ b/src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts @@ -1,22 +1,29 @@ +import { Observation } from '../types/types'; +import { ParametersType } from './ToolTypes'; import { BaseTool } from './BaseTool'; -export class DataAnalysisTool extends BaseTool<{ csv_file_name: string | string[] }> { +const dataAnalysisToolParams = [ + { + name: 'csv_file_names', + type: 'string[]', + description: 'List of names of the CSV files to analyze', + required: true, + max_inputs: 3, + }, +] as const; + +type DataAnalysisToolParamsType = typeof dataAnalysisToolParams; + +export class DataAnalysisTool extends BaseTool<DataAnalysisToolParamsType> { private csv_files_function: () => { filename: string; id: string; text: string }[]; constructor(csv_files: () => { filename: string; id: string; text: string }[]) { super( 'dataAnalysis', - 'Analyzes, and provides insights, from one or more CSV files', - { - csv_file_name: { - type: 'string', - description: 'Name(s) of the CSV file(s) to analyze', - required: 'true', - max_inputs: '3', - }, - }, + 'Analyzes and provides insights from one or more CSV files', + dataAnalysisToolParams, 'Provide the name(s) of up to 3 CSV files to analyze based on the user query and whichever available CSV files may be relevant.', - 'Provides the full CSV file text for your analysis based on the user query and the available CSV file(s). ' + 'Provides the full CSV file text for your analysis based on the user query and the available CSV file(s).' ); this.csv_files_function = csv_files; } @@ -33,9 +40,9 @@ export class DataAnalysisTool extends BaseTool<{ csv_file_name: string | string[ return file?.id; } - async execute(args: { csv_file_name: string | string[] }): Promise<unknown> { - const filenames = Array.isArray(args.csv_file_name) ? args.csv_file_name : [args.csv_file_name]; - const results = []; + async execute(args: ParametersType<DataAnalysisToolParamsType>): Promise<Observation[]> { + const filenames = args.csv_file_names; + const results: Observation[] = []; for (const filename of filenames) { const fileContent = this.getFileContent(filename); @@ -44,7 +51,7 @@ export class DataAnalysisTool extends BaseTool<{ csv_file_name: string | string[ if (fileContent && fileID) { results.push({ type: 'text', - text: `<chunk chunk_id=${fileID} chunk_type=csv>${fileContent}</chunk>`, + text: `<chunk chunk_id="${fileID}" chunk_type="csv">${fileContent}</chunk>`, }); } else { results.push({ |
