langcode
Version:
A Plugin-Based Framework for Managing and Using LangChain
44 lines (43 loc) • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = require("../../types");
const serpapi_1 = require("@langchain/community/tools/serpapi");
class SerpAPIToolPlugin {
constructor() {
this.name = "serpAPITool";
this.description = "Use SerpAPI to fetch search results from Google.";
this.type = types_1.PluginType.Tool;
this.RunConfigExample = {
query: ""
};
this.InitConfigExample = {
apiKey: "serpapi-api-key",
params: {
q: "langchain nedir",
location: "Istanbul,Turkey",
gl: "tr",
hl: "tr",
}
};
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 serpapi_1.SerpAPI(config.apiKey, config.params);
}
async run(args) {
if (!this.tool)
throw new Error("SerpAPI plugin is not initialized.");
return await this.tool.invoke(args.query);
}
}
exports.default = SerpAPIToolPlugin;