UNPKG

@terranlabs/appflow-langchain

Version:

Use langchain in appflow

69 lines (61 loc) 2.32 kB
module.exports = function (RED) { "use strict"; const { AgentExtractLeads } = require('./agent'); function AgentFindDomainAndBODs(config) { RED.nodes.createNode(this, config); const node = this; var agent_config = {}; agent_config.searchStrategy = { strategyName: config.strategy, strategyConfig: { apiKey: config.apiKey, cx: config.cx } } agent_config.llmConfig = { api_key: config.llmApiKey, base_url: config.llmHostedUrl || "" } agent_config.llmStrategy = config.llmStrategy; const agent = new AgentExtractLeads(agent_config); node.on("input", function (msg) { var query = typeof msg.payload === 'string' ? msg.payload : ''; var domainOnly = config.domainOnly; agent.run(query, domainOnly).then( (response) => { msg.payload = response; node.send(msg); }).catch((error) => { node.error(error); }); }); } // function AgentFindDomainAndBODsInternal(config) { // RED.nodes.createNode(this, config); // const node = this; // config.strategy = { strategyName: config.strategy, strategyConfig: { apiKey: config.apiKey, cx: config.cx } } // const agent = new AgentFindDomainAndBODInternal(config); // node.on("input", function (msg) { // var query = typeof msg.payload === 'string' ? msg.payload : ''; // agent.run(query).then( // (response) => { // msg.payload = response; // node.send(msg); // }).catch((error) => { // node.error(error); // }); // }); // } // function AgentFindBODs(config) { // RED.nodes.createNode(this, config); // const node = this; // const agent = new AgentBod(config.openAIApiKey, config.basePath); // node.on("input", function (msg) { // var query = typeof msg.payload === 'string' ? msg.payload : ''; // agent.run(query).then( // (response) => { // msg.payload = response; // node.send(msg); // }).catch((error) => { // node.error(error); // }); // }); // } // RED.nodes.registerType("find-bod", AgentFindBODs); RED.nodes.registerType("find-domain-bod", AgentFindDomainAndBODs); // RED.nodes.registerType("find-domain-bod-internal", AgentFindDomainAndBODsInternal); };