langcode
Version:
A Plugin-Based Framework for Managing and Using LangChain
37 lines (36 loc) • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const calculator_1 = require("@langchain/community/tools/calculator");
const types_1 = require("../../types");
class CalculatorToolPlugin {
constructor() {
this.name = "calculatorTool";
this.description = "Evaluate math expressions using a built-in calculator.";
this.type = types_1.PluginType.Tool;
this.RunConfigExample = {
input: ""
};
this.InitConfigExample = {};
this.tool = null;
}
expose() {
return {
name: this.name,
description: this.description,
type: this.type,
InitConfigExample: this.InitConfigExample,
RunConfigExample: this.RunConfigExample,
tool: this.tool,
};
}
async init(config) {
this.tool = new calculator_1.Calculator();
}
async run(args) {
if (!this.tool)
throw new Error("Tool is not initialized.");
const result = await this.tool.invoke(args);
return result;
}
}
exports.default = CalculatorToolPlugin;