diff options
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/BaseTool.ts')
-rw-r--r-- | src/client/views/nodes/chatbot/tools/BaseTool.ts | 57 |
1 files changed, 42 insertions, 15 deletions
diff --git a/src/client/views/nodes/chatbot/tools/BaseTool.ts b/src/client/views/nodes/chatbot/tools/BaseTool.ts index a77f567a5..4f8f81bcb 100644 --- a/src/client/views/nodes/chatbot/tools/BaseTool.ts +++ b/src/client/views/nodes/chatbot/tools/BaseTool.ts @@ -1,3 +1,5 @@ +import { Tool, ParameterArray, ParametersType, Observation, ParamConfig } from '../types/types'; + /** * @file BaseTool.ts * @description This file defines the abstract BaseTool class, which serves as a blueprint @@ -6,27 +8,52 @@ * and retrieving action rules for use within the assistant's workflow. */ -import { Tool } from '../types/types'; +export abstract class BaseTool implements Tool<ParamConfig[]> { + name: string; + description: string; + parameterRules: ParameterArray; // Still using ParameterArray + citationRules: string; + briefSummary: string; + paramConfig: ParamConfig[]; -export abstract class BaseTool<T extends Record<string, unknown> = Record<string, unknown>> implements Tool<T> { constructor( - public name: string, - public description: string, - public parameters: Record<string, unknown>, - public citationRules: string, - public briefSummary: string - ) {} + name: string, + description: string, + parameterRules: ParameterArray, // Allow tuple types for parameters + citationRules: string, + briefSummary: string + ) { + this.name = name; + this.description = description; + this.parameterRules = parameterRules; + this.citationRules = citationRules; + this.briefSummary = briefSummary; + this.paramConfig = this.parameterRules.map(param => ({ + name: param.name, + type: param.type, + })); // Convert ParameterArray to ParamConfig[] + } - abstract execute(args: T): Promise<unknown>; + // Abstract execute method with dynamic types based on parameters + abstract execute(args: ParametersType<ParamConfig[]>): Promise<Observation[]>; + // Implement the getActionRule method getActionRule(): Record<string, unknown> { return { - [this.name]: { - name: this.name, - citationRules: this.citationRules, - description: this.description, - parameters: this.parameters, - }, + tool: this.name, + description: this.description, + parameters: this.parameterRules.reduce( + (acc, param) => { + acc[param.name] = { + type: param.type, + description: param.description, + required: param.required, + max_inputs: param.max_inputs, + }; + return acc; + }, + {} as Record<string, Omit<ParameterArray[number], 'name'>> + ), }; } } |