aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools/CalculateTool.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-10-10 18:58:39 -0400
committerbobzel <zzzman@gmail.com>2024-10-10 18:58:39 -0400
commit5752dff8ff7b1b2858542feec0b1bb037461bf1a (patch)
tree04080d4a596b0e5199b5ec95ab625fbb590f2a75 /src/client/views/nodes/chatbot/tools/CalculateTool.ts
parent36735ff00a55ae587af5f69eef495533a1f35393 (diff)
parentd347fc59feefd91a796012892da57511787bb6d0 (diff)
Merge branch 'master' into nathan-starter
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/CalculateTool.ts')
-rw-r--r--src/client/views/nodes/chatbot/tools/CalculateTool.ts26
1 files changed, 26 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..77ab1b39b
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/CalculateTool.ts
@@ -0,0 +1,26 @@
+import { BaseTool } from './BaseTool';
+
+export class CalculateTool extends BaseTool<{ expression: string }> {
+ constructor() {
+ super(
+ 'calculate',
+ 'Perform a calculation',
+ {
+ expression: {
+ type: 'string',
+ description: 'The mathematical expression to evaluate',
+ required: 'true',
+ max_inputs: '1',
+ },
+ },
+ '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);
+ return [{ type: 'text', text: result.toString() }];
+ }
+}