UNPKG

@langchain/community

Version:
1 lines 1.55 kB
{"version":3,"file":"calculator.cjs","names":["Mexp","Tool"],"sources":["../../src/tools/calculator.ts"],"sourcesContent":["import Mexp from \"math-expression-evaluator\";\n\nimport { Tool } from \"@langchain/core/tools\";\n\n/**\n * The Calculator class is a tool used to evaluate mathematical\n * expressions. It extends the base Tool class.\n * @example\n * ```typescript\n * import { Calculator } from \"@langchain/community/tools/calculator\";\n *\n * const calculator = new Calculator();\n * const sum = await calculator.invoke(\"99 + 99\");\n * console.log(\"The sum of 99 and 99 is:\", sum);\n * // The sum of 99 and 99 is: 198\n * ```\n */\n\nconst Parser = new Mexp();\nexport class Calculator extends Tool {\n static lc_name() {\n return \"Calculator\";\n }\n\n get lc_namespace() {\n return [...super.lc_namespace, \"calculator\"];\n }\n\n name = \"calculator\";\n\n /** @ignore */\n async _call(input: string) {\n try {\n return Parser.eval(input).toString();\n } catch {\n return \"I don't know how to do that.\";\n }\n }\n\n description = `Useful for getting the result of a math expression. The input to this tool should be a valid mathematical expression that could be executed by a simple calculator.`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkBA,MAAM,SAAS,IAAIA,0BAAAA,SAAM;AACzB,IAAa,aAAb,cAAgCC,sBAAAA,KAAK;CACnC,OAAO,UAAU;AACf,SAAO;;CAGT,IAAI,eAAe;AACjB,SAAO,CAAC,GAAG,MAAM,cAAc,aAAa;;CAG9C,OAAO;;CAGP,MAAM,MAAM,OAAe;AACzB,MAAI;AACF,UAAO,OAAO,KAAK,MAAM,CAAC,UAAU;UAC9B;AACN,UAAO;;;CAIX,cAAc"}