diff options
| author | A.J. Shulman <Shulman.aj@gmail.com> | 2024-10-17 10:41:49 -0400 |
|---|---|---|
| committer | A.J. Shulman <Shulman.aj@gmail.com> | 2024-10-17 10:41:49 -0400 |
| commit | 80d86bd5ae3e1d3dc70e7636f72a872a5fb2f01d (patch) | |
| tree | 0eaea49f596bd16720f05a6535958ab8270673c8 /src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts | |
| parent | 596502c232ea6b6b88c3c58486e139074ea056ff (diff) | |
Implemented strict typechecking for tools, specifically tool inputs
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts')
| -rw-r--r-- | src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts b/src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts index b97576095..d9b75219d 100644 --- a/src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts +++ b/src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts @@ -1,20 +1,27 @@ import { Observation } from '../types/types'; +import { ParametersType } from './ToolTypes'; import { BaseTool } from './BaseTool'; -export class DataAnalysisTool extends BaseTool<{ csv_file_name: { type: string | string[]; description: string; required: boolean } }> { +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, - }, - }, + '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).' ); @@ -33,8 +40,8 @@ export class DataAnalysisTool extends BaseTool<{ csv_file_name: { type: string | return file?.id; } - async execute(args: { csv_file_name: string | string[] }): Promise<Observation[]> { - const filenames = Array.isArray(args.csv_file_name) ? args.csv_file_name : [args.csv_file_name]; + async execute(args: ParametersType<DataAnalysisToolParamsType>): Promise<Observation[]> { + const filenames = args.csv_file_names; const results: Observation[] = []; for (const filename of filenames) { @@ -44,7 +51,7 @@ export class DataAnalysisTool extends BaseTool<{ csv_file_name: { type: 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({ |
