From 3e4278e4fe666eb834a83692316e9df1bdd13c48 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Tue, 16 May 2023 16:29:10 +0700 Subject: [PATCH 1/3] init --- .../nodes/agents/MRKLAgentLLM/MRKLAgentLLM.ts | 4 +- .../nodes/tools/ZapierNLA/ZapierNLA.ts | 46 ++++++++++++++++++ .../nodes/tools/ZapierNLA/zapier.png | Bin 0 -> 502 bytes 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 packages/components/nodes/tools/ZapierNLA/ZapierNLA.ts create mode 100644 packages/components/nodes/tools/ZapierNLA/zapier.png diff --git a/packages/components/nodes/agents/MRKLAgentLLM/MRKLAgentLLM.ts b/packages/components/nodes/agents/MRKLAgentLLM/MRKLAgentLLM.ts index 499b9383..f0bf54c0 100644 --- a/packages/components/nodes/agents/MRKLAgentLLM/MRKLAgentLLM.ts +++ b/packages/components/nodes/agents/MRKLAgentLLM/MRKLAgentLLM.ts @@ -26,7 +26,7 @@ class MRKLAgentLLM_Agents implements INode { { label: 'Allowed Tools', name: 'tools', - type: 'Tool', + type: 'Tool' || 'Tool[]', list: true }, { @@ -40,7 +40,7 @@ class MRKLAgentLLM_Agents implements INode { async init(nodeData: INodeData): Promise { const model = nodeData.inputs?.model as BaseLLM const tools = nodeData.inputs?.tools as Tool[] - + console.log(`something about tools: ${JSON.stringify(tools)}`) const executor = await initializeAgentExecutorWithOptions(tools, model, { agentType: 'zero-shot-react-description', verbose: true diff --git a/packages/components/nodes/tools/ZapierNLA/ZapierNLA.ts b/packages/components/nodes/tools/ZapierNLA/ZapierNLA.ts new file mode 100644 index 00000000..d38da20a --- /dev/null +++ b/packages/components/nodes/tools/ZapierNLA/ZapierNLA.ts @@ -0,0 +1,46 @@ +import { ZapierNLAWrapper, ZapiterNLAWrapperParams } from 'langchain/tools' +import { INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses } from '../../../src/utils' +import { ZapierToolKit, createSqlAgent } from 'langchain/agents' + +class ZapierNLA_Tools implements INode { + label: string + name: string + description: string + type: string + icon: string + category: string + baseClasses: string[] + inputs: INodeParams[] + + constructor() { + this.label = 'Zapier NLA' + this.name = 'zapierNLA' + this.type = 'ZapierNLA' + this.icon = 'zapier.png' + this.category = 'Tools' + this.description = 'Access to apps and actions on Zapier's platform through a natural language API interface' + this.inputs = [ + { + label: 'Zapier NLA Api Key', + name: 'apiKey', + type: 'password' + } + ] + this.baseClasses = [this.type, ...getBaseClasses(ZapierNLAWrapper)] + } + + async init(nodeData: INodeData): Promise { + const apiKey = nodeData.inputs?.apiKey as string + + const obj: Partial = { + apiKey + } + const zapier = new ZapierNLAWrapper(obj) + const toolkit = await ZapierToolKit.fromZapierNLAWrapper(zapier) + + return toolkit.tools + } +} + +module.exports = { nodeClass: ZapierNLA_Tools } diff --git a/packages/components/nodes/tools/ZapierNLA/zapier.png b/packages/components/nodes/tools/ZapierNLA/zapier.png new file mode 100644 index 0000000000000000000000000000000000000000..769716faaadca77fcd3e7ac06c22ba570d37d2e6 GIT binary patch literal 502 zcmeAS@N?(olHy`uVBq!ia0vp^?I6s-1SB`N-i-xPjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucL7@`Yh?3y^w370~qErU=qSVy9;*9)~xKIwD z7RFpp7srr_xVIM-MVTELj$9~>2wc9vtS{`rwEm`s`Qk!ziZ33Xs Date: Tue, 16 May 2023 21:44:39 +0700 Subject: [PATCH 2/3] add Zapier NLP --- packages/components/nodes/agents/AutoGPT/AutoGPT.ts | 3 ++- .../agents/ConversationalAgent/ConversationalAgent.ts | 3 ++- .../components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts | 3 ++- .../components/nodes/agents/MRKLAgentLLM/MRKLAgentLLM.ts | 7 ++++--- packages/components/nodes/tools/ZapierNLA/ZapierNLA.ts | 7 +++---- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/components/nodes/agents/AutoGPT/AutoGPT.ts b/packages/components/nodes/agents/AutoGPT/AutoGPT.ts index a9314f79..17318eb0 100644 --- a/packages/components/nodes/agents/AutoGPT/AutoGPT.ts +++ b/packages/components/nodes/agents/AutoGPT/AutoGPT.ts @@ -66,7 +66,8 @@ class AutoGPT_Agents implements INode { async init(nodeData: INodeData): Promise { const model = nodeData.inputs?.model as BaseChatModel const vectorStoreRetriever = nodeData.inputs?.vectorStoreRetriever as VectorStoreRetriever - const tools = nodeData.inputs?.tools as Tool[] + let tools = nodeData.inputs?.tools as Tool[] + tools = tools.flat() const aiName = (nodeData.inputs?.aiName as string) || 'AutoGPT' const aiRole = (nodeData.inputs?.aiRole as string) || 'Assistant' const maxLoop = nodeData.inputs?.maxLoop as string diff --git a/packages/components/nodes/agents/ConversationalAgent/ConversationalAgent.ts b/packages/components/nodes/agents/ConversationalAgent/ConversationalAgent.ts index 90a55782..76ceba05 100644 --- a/packages/components/nodes/agents/ConversationalAgent/ConversationalAgent.ts +++ b/packages/components/nodes/agents/ConversationalAgent/ConversationalAgent.ts @@ -62,7 +62,8 @@ class ConversationalAgent_Agents implements INode { async init(nodeData: INodeData): Promise { const model = nodeData.inputs?.model as BaseChatModel - const tools = nodeData.inputs?.tools as Tool[] + let tools = nodeData.inputs?.tools as Tool[] + tools = tools.flat() const memory = nodeData.inputs?.memory as BaseChatMemory const humanMessage = nodeData.inputs?.humanMessage as string const systemMessage = nodeData.inputs?.systemMessage as string diff --git a/packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts b/packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts index 1a619e6a..01a85889 100644 --- a/packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts +++ b/packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts @@ -39,7 +39,8 @@ class MRKLAgentChat_Agents implements INode { async init(nodeData: INodeData): Promise { const model = nodeData.inputs?.model as BaseChatModel - const tools = nodeData.inputs?.tools as Tool[] + let tools = nodeData.inputs?.tools as Tool[] + tools = tools.flat() const executor = await initializeAgentExecutorWithOptions(tools, model, { agentType: 'chat-zero-shot-react-description', verbose: true diff --git a/packages/components/nodes/agents/MRKLAgentLLM/MRKLAgentLLM.ts b/packages/components/nodes/agents/MRKLAgentLLM/MRKLAgentLLM.ts index f0bf54c0..c092fc17 100644 --- a/packages/components/nodes/agents/MRKLAgentLLM/MRKLAgentLLM.ts +++ b/packages/components/nodes/agents/MRKLAgentLLM/MRKLAgentLLM.ts @@ -26,7 +26,7 @@ class MRKLAgentLLM_Agents implements INode { { label: 'Allowed Tools', name: 'tools', - type: 'Tool' || 'Tool[]', + type: 'Tool', list: true }, { @@ -39,8 +39,9 @@ class MRKLAgentLLM_Agents implements INode { async init(nodeData: INodeData): Promise { const model = nodeData.inputs?.model as BaseLLM - const tools = nodeData.inputs?.tools as Tool[] - console.log(`something about tools: ${JSON.stringify(tools)}`) + let tools = nodeData.inputs?.tools as Tool[] + tools = tools.flat() + const executor = await initializeAgentExecutorWithOptions(tools, model, { agentType: 'zero-shot-react-description', verbose: true diff --git a/packages/components/nodes/tools/ZapierNLA/ZapierNLA.ts b/packages/components/nodes/tools/ZapierNLA/ZapierNLA.ts index d38da20a..849f5946 100644 --- a/packages/components/nodes/tools/ZapierNLA/ZapierNLA.ts +++ b/packages/components/nodes/tools/ZapierNLA/ZapierNLA.ts @@ -1,7 +1,6 @@ import { ZapierNLAWrapper, ZapiterNLAWrapperParams } from 'langchain/tools' import { INode, INodeData, INodeParams } from '../../../src/Interface' -import { getBaseClasses } from '../../../src/utils' -import { ZapierToolKit, createSqlAgent } from 'langchain/agents' +import { ZapierToolKit } from 'langchain/agents' class ZapierNLA_Tools implements INode { label: string @@ -19,7 +18,7 @@ class ZapierNLA_Tools implements INode { this.type = 'ZapierNLA' this.icon = 'zapier.png' this.category = 'Tools' - this.description = 'Access to apps and actions on Zapier's platform through a natural language API interface' + this.description = "Access to apps and actions on Zapier's platform through a natural language API interface" this.inputs = [ { label: 'Zapier NLA Api Key', @@ -27,7 +26,7 @@ class ZapierNLA_Tools implements INode { type: 'password' } ] - this.baseClasses = [this.type, ...getBaseClasses(ZapierNLAWrapper)] + this.baseClasses = [this.type, 'Tool'] } async init(nodeData: INodeData): Promise { From 53681394e1f97cbf9fcb68f1283f939044b9dd9b Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Tue, 16 May 2023 22:44:24 +0700 Subject: [PATCH 3/3] add Zapier NLA example into marketplaces --- packages/server/marketplaces/Zapier NLA.json | 274 +++++++++++++++++++ 1 file changed, 274 insertions(+) create mode 100644 packages/server/marketplaces/Zapier NLA.json diff --git a/packages/server/marketplaces/Zapier NLA.json b/packages/server/marketplaces/Zapier NLA.json new file mode 100644 index 00000000..e3c07779 --- /dev/null +++ b/packages/server/marketplaces/Zapier NLA.json @@ -0,0 +1,274 @@ +{ + "description": "An agent that uses Zapier NLA to accesss apps and actions on Zapier's platform", + "nodes": [ + { + "width": 300, + "height": 281, + "id": "mrklAgentLLM_0", + "position": { + "x": 919.3453672085218, + "y": 371.80988480957353 + }, + "type": "customNode", + "data": { + "id": "mrklAgentLLM_0", + "label": "MRKL Agent for LLMs", + "name": "mrklAgentLLM", + "type": "AgentExecutor", + "baseClasses": ["AgentExecutor", "BaseChain", "BaseLangChain"], + "category": "Agents", + "description": "Agent that uses the ReAct Framework to decide what action to take, optimized to be used with LLMs", + "inputParams": [], + "inputAnchors": [ + { + "label": "Allowed Tools", + "name": "tools", + "type": "Tool", + "list": true, + "id": "mrklAgentLLM_0-input-tools-Tool" + }, + { + "label": "LLM Model", + "name": "model", + "type": "BaseLLM", + "id": "mrklAgentLLM_0-input-model-BaseLLM" + } + ], + "inputs": { + "tools": ["{{zapierNLA_0.data.instance}}"], + "model": "{{openAI_0.data.instance}}" + }, + "outputAnchors": [ + { + "id": "mrklAgentLLM_0-output-mrklAgentLLM-AgentExecutor|BaseChain|BaseLangChain", + "name": "mrklAgentLLM", + "label": "AgentExecutor", + "type": "AgentExecutor | BaseChain | BaseLangChain" + } + ], + "outputs": {}, + "selected": false + }, + "selected": false, + "positionAbsolute": { + "x": 919.3453672085218, + "y": 371.80988480957353 + }, + "dragging": false + }, + { + "width": 300, + "height": 279, + "id": "zapierNLA_0", + "position": { + "x": 546.0561178227484, + "y": 83.03303671691799 + }, + "type": "customNode", + "data": { + "id": "zapierNLA_0", + "label": "Zapier NLA", + "name": "zapierNLA", + "type": "ZapierNLA", + "baseClasses": ["ZapierNLA", "Tool"], + "category": "Tools", + "description": "Access to apps and actions on Zapier's platform through a natural language API interface", + "inputParams": [ + { + "label": "Zapier NLA Api Key", + "name": "apiKey", + "type": "password", + "id": "zapierNLA_0-input-apiKey-password" + } + ], + "inputAnchors": [], + "inputs": {}, + "outputAnchors": [ + { + "id": "zapierNLA_0-output-zapierNLA-ZapierNLA|Tool", + "name": "zapierNLA", + "label": "ZapierNLA", + "type": "ZapierNLA | Tool" + } + ], + "outputs": {}, + "selected": false + }, + "selected": false, + "positionAbsolute": { + "x": 546.0561178227484, + "y": 83.03303671691799 + }, + "dragging": false + }, + { + "width": 300, + "height": 526, + "id": "openAI_0", + "position": { + "x": 547.3867724775708, + "y": 394.1919189424442 + }, + "type": "customNode", + "data": { + "id": "openAI_0", + "label": "OpenAI", + "name": "openAI", + "type": "OpenAI", + "baseClasses": ["OpenAI", "BaseLLM", "BaseLanguageModel", "BaseLangChain"], + "category": "LLMs", + "description": "Wrapper around OpenAI large language models", + "inputParams": [ + { + "label": "OpenAI Api Key", + "name": "openAIApiKey", + "type": "password", + "id": "openAI_0-input-openAIApiKey-password" + }, + { + "label": "Model Name", + "name": "modelName", + "type": "options", + "options": [ + { + "label": "text-davinci-003", + "name": "text-davinci-003" + }, + { + "label": "text-davinci-002", + "name": "text-davinci-002" + }, + { + "label": "text-curie-001", + "name": "text-curie-001" + }, + { + "label": "text-babbage-001", + "name": "text-babbage-001" + } + ], + "default": "text-davinci-003", + "optional": true, + "id": "openAI_0-input-modelName-options" + }, + { + "label": "Temperature", + "name": "temperature", + "type": "number", + "default": 0.7, + "optional": true, + "id": "openAI_0-input-temperature-number" + }, + { + "label": "Max Tokens", + "name": "maxTokens", + "type": "number", + "optional": true, + "additionalParams": true, + "id": "openAI_0-input-maxTokens-number" + }, + { + "label": "Top Probability", + "name": "topP", + "type": "number", + "optional": true, + "additionalParams": true, + "id": "openAI_0-input-topP-number" + }, + { + "label": "Best Of", + "name": "bestOf", + "type": "number", + "optional": true, + "additionalParams": true, + "id": "openAI_0-input-bestOf-number" + }, + { + "label": "Frequency Penalty", + "name": "frequencyPenalty", + "type": "number", + "optional": true, + "additionalParams": true, + "id": "openAI_0-input-frequencyPenalty-number" + }, + { + "label": "Presence Penalty", + "name": "presencePenalty", + "type": "number", + "optional": true, + "additionalParams": true, + "id": "openAI_0-input-presencePenalty-number" + }, + { + "label": "Batch Size", + "name": "batchSize", + "type": "number", + "optional": true, + "additionalParams": true, + "id": "openAI_0-input-batchSize-number" + }, + { + "label": "Timeout", + "name": "timeout", + "type": "number", + "optional": true, + "additionalParams": true, + "id": "openAI_0-input-timeout-number" + } + ], + "inputAnchors": [], + "inputs": { + "modelName": "text-davinci-003", + "temperature": 0.7, + "maxTokens": "", + "topP": "", + "bestOf": "", + "frequencyPenalty": "", + "presencePenalty": "", + "batchSize": "", + "timeout": "" + }, + "outputAnchors": [ + { + "id": "openAI_0-output-openAI-OpenAI|BaseLLM|BaseLanguageModel|BaseLangChain", + "name": "openAI", + "label": "OpenAI", + "type": "OpenAI | BaseLLM | BaseLanguageModel | BaseLangChain" + } + ], + "outputs": {}, + "selected": false + }, + "selected": false, + "positionAbsolute": { + "x": 547.3867724775708, + "y": 394.1919189424442 + }, + "dragging": false + } + ], + "edges": [ + { + "source": "zapierNLA_0", + "sourceHandle": "zapierNLA_0-output-zapierNLA-ZapierNLA|Tool", + "target": "mrklAgentLLM_0", + "targetHandle": "mrklAgentLLM_0-input-tools-Tool", + "type": "buttonedge", + "id": "zapierNLA_0-zapierNLA_0-output-zapierNLA-ZapierNLA|Tool-mrklAgentLLM_0-mrklAgentLLM_0-input-tools-Tool", + "data": { + "label": "" + } + }, + { + "source": "openAI_0", + "sourceHandle": "openAI_0-output-openAI-OpenAI|BaseLLM|BaseLanguageModel|BaseLangChain", + "target": "mrklAgentLLM_0", + "targetHandle": "mrklAgentLLM_0-input-model-BaseLLM", + "type": "buttonedge", + "id": "openAI_0-openAI_0-output-openAI-OpenAI|BaseLLM|BaseLanguageModel|BaseLangChain-mrklAgentLLM_0-mrklAgentLLM_0-input-model-BaseLLM", + "data": { + "label": "" + } + } + ] +}