UNPKG

genaiscript

Version:

A CLI for GenAIScript, a generative AI scripting framework.

31 lines (28 loc) 945 B
system({ title: "Math expression evaluator", description: "Register a function that evaluates math expressions", }) export default function (ctx: ChatGenerationContext) { const { defTool } = ctx defTool( "math_eval", "Evaluates a math expression. Do NOT try to compute arithmetic operations yourself, use this tool.", { type: "object", properties: { expression: { type: "string", description: "Math expression to evaluate using mathjs format. Use ^ for power operator.", }, }, required: ["expression"], }, async (args) => { const { context, expression } = args const res = String((await parsers.math(expression)) ?? "?") context.log(`math: ${expression} => ${res}`) return res } ) }