aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools/CalculateTool.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-10-17 17:19:25 -0400
committerbobzel <zzzman@gmail.com>2024-10-17 17:19:25 -0400
commit8ac260db2fdffc37ff9b6e91971f287df6a70528 (patch)
treec4bad3d44cb4c374b84834a39f5fc664345784f7 /src/client/views/nodes/chatbot/tools/CalculateTool.ts
parent3067940f28563d1217056f6eb428d377365077a8 (diff)
parentdd93f5175064850c6c0e47f025cd7bbba1f23106 (diff)
Merge branch 'master' into alyssa-starter
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/CalculateTool.ts')
-rw-r--r--src/client/views/nodes/chatbot/tools/CalculateTool.ts30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/client/views/nodes/chatbot/tools/CalculateTool.ts b/src/client/views/nodes/chatbot/tools/CalculateTool.ts
index 77ab1b39b..e96c9a98a 100644
--- a/src/client/views/nodes/chatbot/tools/CalculateTool.ts
+++ b/src/client/views/nodes/chatbot/tools/CalculateTool.ts
@@ -1,26 +1,32 @@
+import { Observation } from '../types/types';
+import { ParametersType } from './ToolTypes';
import { BaseTool } from './BaseTool';
-export class CalculateTool extends BaseTool<{ expression: string }> {
+const calculateToolParams = [
+ {
+ name: 'expression',
+ type: 'string',
+ description: 'The mathematical expression to evaluate',
+ required: true,
+ },
+] as const;
+
+type CalculateToolParamsType = typeof calculateToolParams;
+
+export class CalculateTool extends BaseTool<CalculateToolParamsType> {
constructor() {
super(
'calculate',
'Perform a calculation',
- {
- expression: {
- type: 'string',
- description: 'The mathematical expression to evaluate',
- required: 'true',
- max_inputs: '1',
- },
- },
+ calculateToolParams, // Use the reusable param config here
'Provide a mathematical expression to calculate that would work with JavaScript eval().',
'Runs a calculation and returns the number - uses JavaScript so be sure to use floating point syntax if necessary'
);
}
- async execute(args: { expression: string }): Promise<unknown> {
- // Note: Using eval() can be dangerous. Consider using a safer alternative.
- const result = eval(args.expression);
+ 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() }];
}
}