diff options
author | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2025-03-11 17:43:05 +0100 |
---|---|---|
committer | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2025-03-11 17:43:05 +0100 |
commit | fa937182bc93aa2c6faadda80ea998cdfd479b4e (patch) | |
tree | cba8e16edcccc6fd2932173484ac444cb79abea2 /src/client/views/nodes/chatbot/tools/CalculateTool.ts | |
parent | cf91c46cfec6e3e36b9184764016f9c1b5c997d4 (diff) | |
parent | 04669ffeb163688c7aefd7b5face7998252abdca (diff) |
Merge branch 'master' of https://github.com/brown-dash/Dash-Web into DocCreatorMenu-work
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/CalculateTool.ts')
-rw-r--r-- | src/client/views/nodes/chatbot/tools/CalculateTool.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/client/views/nodes/chatbot/tools/CalculateTool.ts b/src/client/views/nodes/chatbot/tools/CalculateTool.ts new file mode 100644 index 000000000..ca7223803 --- /dev/null +++ b/src/client/views/nodes/chatbot/tools/CalculateTool.ts @@ -0,0 +1,33 @@ +import { Observation } from '../types/types'; +import { ParametersType, ToolInfo } from '../types/tool_types'; +import { BaseTool } from './BaseTool'; + +const calculateToolParams = [ + { + name: 'expression', + type: 'string', + description: 'The mathematical expression to evaluate', + required: true, + }, +] as const; + +type CalculateToolParamsType = typeof calculateToolParams; + +const calculateToolInfo: ToolInfo<CalculateToolParamsType> = { + name: 'calculate', + citationRules: 'No citation needed.', + parameterRules: calculateToolParams, + description: 'Runs a calculation and returns the number - uses JavaScript so be sure to use floating point syntax if necessary', +}; + +export class CalculateTool extends BaseTool<CalculateToolParamsType> { + constructor() { + super(calculateToolInfo); + } + + async execute(args: ParametersType<CalculateToolParamsType>): Promise<Observation[]> { + // TypeScript will ensure 'args.expression' is a string based on the param config + const result = eval(args.expression); // Be cautious with eval(), as it can be dangerous. Consider using a safer alternative. + return [{ type: 'text', text: result.toString() }]; + } +} |