From a94d841bb72693bd12e746afb3bd0e25eacfa783 Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 11 Apr 2023 15:10:39 +0100 Subject: [PATCH 1/6] add tools for plugins --- .../nodes/tools/AIPlugin/AIPlugin.ts | 43 +++++++++++++++++++ .../nodes/tools/AIPlugin/aiplugin.svg | 7 +++ .../nodes/tools/RequestsGet/RequestsGet.ts | 33 ++++++++++++++ .../nodes/tools/RequestsGet/requestsget.svg | 8 ++++ .../nodes/tools/RequestsPost/RequestsPost.ts | 33 ++++++++++++++ .../nodes/tools/RequestsPost/requestspost.svg | 6 +++ packages/components/package.json | 1 + 7 files changed, 131 insertions(+) create mode 100644 packages/components/nodes/tools/AIPlugin/AIPlugin.ts create mode 100644 packages/components/nodes/tools/AIPlugin/aiplugin.svg create mode 100644 packages/components/nodes/tools/RequestsGet/RequestsGet.ts create mode 100644 packages/components/nodes/tools/RequestsGet/requestsget.svg create mode 100644 packages/components/nodes/tools/RequestsPost/RequestsPost.ts create mode 100644 packages/components/nodes/tools/RequestsPost/requestspost.svg diff --git a/packages/components/nodes/tools/AIPlugin/AIPlugin.ts b/packages/components/nodes/tools/AIPlugin/AIPlugin.ts new file mode 100644 index 000000000..6e7d9f8cf --- /dev/null +++ b/packages/components/nodes/tools/AIPlugin/AIPlugin.ts @@ -0,0 +1,43 @@ +import { INode, INodeData, INodeParams } from '../../../src/Interface' + +class AIPlugin implements INode { + label: string + name: string + description: string + type: string + icon: string + category: string + baseClasses: string[] + inputs?: INodeParams[] + + constructor() { + this.label = 'AI Plugin' + this.name = 'aiPlugin' + this.type = 'AIPlugin' + this.icon = 'aiplugin.svg' + this.category = 'Tools' + this.description = 'Execute actions using ChatGPT Plugin Url' + this.inputs = [ + { + label: 'Plugin Url', + name: 'pluginUrl', + type: 'string', + placeholder: 'https://www.klarna.com/.well-known/ai-plugin.json' + } + ] + } + + async getBaseClasses(): Promise { + return ['Tool'] + } + + async init(nodeData: INodeData): Promise { + const { AIPluginTool } = await import('langchain/tools') + const pluginUrl = nodeData.inputs?.pluginUrl as string + + const aiplugin = await AIPluginTool.fromPluginUrl(pluginUrl) + return aiplugin + } +} + +module.exports = { nodeClass: AIPlugin } diff --git a/packages/components/nodes/tools/AIPlugin/aiplugin.svg b/packages/components/nodes/tools/AIPlugin/aiplugin.svg new file mode 100644 index 000000000..e617e45c0 --- /dev/null +++ b/packages/components/nodes/tools/AIPlugin/aiplugin.svg @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/packages/components/nodes/tools/RequestsGet/RequestsGet.ts b/packages/components/nodes/tools/RequestsGet/RequestsGet.ts new file mode 100644 index 000000000..379aa8dcb --- /dev/null +++ b/packages/components/nodes/tools/RequestsGet/RequestsGet.ts @@ -0,0 +1,33 @@ +import { INode } from '../../../src/Interface' +import { getBaseClasses } from '../../../src/utils' + +class RequestsGet implements INode { + label: string + name: string + description: string + type: string + icon: string + category: string + baseClasses: string[] + + constructor() { + this.label = 'Requests Get' + this.name = 'requestsGet' + this.type = 'RequestsGet' + this.icon = 'requestsget.svg' + this.category = 'Tools' + this.description = 'Execute HTTP GET requests' + } + + async getBaseClasses(): Promise { + const { RequestsGetTool } = await import('langchain/tools') + return getBaseClasses(RequestsGetTool) + } + + async init(): Promise { + const { RequestsGetTool } = await import('langchain/tools') + return new RequestsGetTool() + } +} + +module.exports = { nodeClass: RequestsGet } diff --git a/packages/components/nodes/tools/RequestsGet/requestsget.svg b/packages/components/nodes/tools/RequestsGet/requestsget.svg new file mode 100644 index 000000000..03777e7cd --- /dev/null +++ b/packages/components/nodes/tools/RequestsGet/requestsget.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/packages/components/nodes/tools/RequestsPost/RequestsPost.ts b/packages/components/nodes/tools/RequestsPost/RequestsPost.ts new file mode 100644 index 000000000..cc9946eab --- /dev/null +++ b/packages/components/nodes/tools/RequestsPost/RequestsPost.ts @@ -0,0 +1,33 @@ +import { INode } from '../../../src/Interface' +import { getBaseClasses } from '../../../src/utils' + +class RequestsPost implements INode { + label: string + name: string + description: string + type: string + icon: string + category: string + baseClasses: string[] + + constructor() { + this.label = 'Requests Post' + this.name = 'requestsPost' + this.type = 'RequestsPost' + this.icon = 'requestspost.svg' + this.category = 'Tools' + this.description = 'Execute HTTP POST requests' + } + + async getBaseClasses(): Promise { + const { RequestsPostTool } = await import('langchain/tools') + return getBaseClasses(RequestsPostTool) + } + + async init(): Promise { + const { RequestsPostTool } = await import('langchain/tools') + return new RequestsPostTool() + } +} + +module.exports = { nodeClass: RequestsPost } diff --git a/packages/components/nodes/tools/RequestsPost/requestspost.svg b/packages/components/nodes/tools/RequestsPost/requestspost.svg new file mode 100644 index 000000000..2bea6e967 --- /dev/null +++ b/packages/components/nodes/tools/RequestsPost/requestspost.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/packages/components/package.json b/packages/components/package.json index 0a211553d..2409969c6 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -27,6 +27,7 @@ "langchain": "^0.0.44", "moment": "^2.29.3", "node-fetch": "2", + "openai": "^3.2.1", "pdfjs-dist": "^3.5.141", "ws": "^8.9.0" }, From 1558225a25a4eaac029f568abad08590f07bf146 Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 11 Apr 2023 15:17:55 +0100 Subject: [PATCH 2/6] update node version for github actions --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index afc430796..a89846a62 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: platform: [ubuntu-latest] - node-version: [14.x, 16.x] + node-version: [18.15.0] runs-on: ${{ matrix.platform }} steps: From ed81dc228f9b59b60875e20686e61fad21853233 Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 17 Apr 2023 20:26:57 +0100 Subject: [PATCH 3/6] add aiplugintools --- .../agents/MRKLAgentChat/MRKLAgentChat.ts | 17 +++++-- .../nodes/tools/AIPlugin/AIPlugin.ts | 15 +++--- .../ui/src/store/context/ReactFlowContext.js | 48 +++++++++++++++++-- packages/ui/src/utils/genericHelper.js | 17 +++++++ packages/ui/src/views/canvas/index.js | 8 +++- 5 files changed, 88 insertions(+), 17 deletions(-) diff --git a/packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts b/packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts index a60ccf7bf..f583ac026 100644 --- a/packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts +++ b/packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts @@ -1,6 +1,6 @@ import { INode, INodeData, INodeParams } from '../../../src/Interface' import { initializeAgentExecutor, AgentExecutor } from 'langchain/agents' -import { Tool } from 'langchain/tools' +import { AIPluginTool } from 'langchain/tools' import { BaseChatModel } from 'langchain/chat_models/base' import { getBaseClasses } from '../../../src/utils' @@ -39,9 +39,20 @@ class MRKLAgentChat_Agents implements INode { async init(nodeData: INodeData): Promise { const model = nodeData.inputs?.model as BaseChatModel - const tools = nodeData.inputs?.tools as Tool[] + const tools = nodeData.inputs?.tools - const executor = await initializeAgentExecutor(tools, model, 'chat-zero-shot-react-description', true) + const allowedTools = [] + for (let i = 0; i < tools.length; i += 1) { + if (tools[i].pluginUrl) { + const pluginURL: string = tools[i].pluginUrl + const aiplugin = await AIPluginTool.fromPluginUrl(pluginURL) + allowedTools.push(aiplugin) + } else { + allowedTools.push(tools[i]) + } + } + + const executor = await initializeAgentExecutor(allowedTools, model, 'chat-zero-shot-react-description', true) return executor } diff --git a/packages/components/nodes/tools/AIPlugin/AIPlugin.ts b/packages/components/nodes/tools/AIPlugin/AIPlugin.ts index 6e7d9f8cf..156b138d2 100644 --- a/packages/components/nodes/tools/AIPlugin/AIPlugin.ts +++ b/packages/components/nodes/tools/AIPlugin/AIPlugin.ts @@ -1,4 +1,6 @@ import { INode, INodeData, INodeParams } from '../../../src/Interface' +import { AIPluginTool } from 'langchain/tools' +import { getBaseClasses } from '../../../src/utils' class AIPlugin implements INode { label: string @@ -17,6 +19,7 @@ class AIPlugin implements INode { this.icon = 'aiplugin.svg' this.category = 'Tools' this.description = 'Execute actions using ChatGPT Plugin Url' + this.baseClasses = [this.type, ...getBaseClasses(AIPluginTool)] this.inputs = [ { label: 'Plugin Url', @@ -27,15 +30,13 @@ class AIPlugin implements INode { ] } - async getBaseClasses(): Promise { - return ['Tool'] - } - async init(nodeData: INodeData): Promise { - const { AIPluginTool } = await import('langchain/tools') const pluginUrl = nodeData.inputs?.pluginUrl as string - - const aiplugin = await AIPluginTool.fromPluginUrl(pluginUrl) + // Doesn't work currently + // const aiplugin = await AIPluginTool.fromPluginUrl(pluginUrl) + const aiplugin = { + pluginUrl: pluginUrl + } return aiplugin } } diff --git a/packages/ui/src/store/context/ReactFlowContext.js b/packages/ui/src/store/context/ReactFlowContext.js index b8b32606b..1a6b979f1 100644 --- a/packages/ui/src/store/context/ReactFlowContext.js +++ b/packages/ui/src/store/context/ReactFlowContext.js @@ -13,13 +13,51 @@ export const flowContext = createContext(initialValue) export const ReactFlowContext = ({ children }) => { const [reactFlowInstance, setReactFlowInstance] = useState(null) - const deleteNode = (id) => { - reactFlowInstance.setNodes(reactFlowInstance.getNodes().filter((n) => n.id !== id)) - reactFlowInstance.setEdges(reactFlowInstance.getEdges().filter((ns) => ns.source !== id && ns.target !== id)) + const deleteNode = (nodeid) => { + deleteConnectedInput(nodeid, 'node') + reactFlowInstance.setNodes(reactFlowInstance.getNodes().filter((n) => n.id !== nodeid)) + reactFlowInstance.setEdges(reactFlowInstance.getEdges().filter((ns) => ns.source !== nodeid && ns.target !== nodeid)) } - const deleteEdge = (id) => { - reactFlowInstance.setEdges(reactFlowInstance.getEdges().filter((edge) => edge.id !== id)) + const deleteEdge = (edgeid) => { + deleteConnectedInput(edgeid, 'edge') + reactFlowInstance.setEdges(reactFlowInstance.getEdges().filter((edge) => edge.id !== edgeid)) + } + + const deleteConnectedInput = (id, type) => { + const connectedEdges = + type === 'node' + ? reactFlowInstance.getEdges().filter((edge) => edge.source === id) + : reactFlowInstance.getEdges().filter((edge) => edge.id === id) + + for (const edge of connectedEdges) { + const targetNodeId = edge.target + const sourceNodeId = edge.source + const targetInput = edge.targetHandle.split('-')[2] + + reactFlowInstance.setNodes((nds) => + nds.map((node) => { + if (node.id === targetNodeId) { + let value + const inputAnchor = node.data.inputAnchors.find((ancr) => ancr.name === targetInput) + if (inputAnchor && inputAnchor.list) { + const values = node.data.inputs[targetInput] || [] + value = values.filter((item) => !item.includes(sourceNodeId)) + } else { + value = '' + } + node.data = { + ...node.data, + inputs: { + ...node.data.inputs, + [targetInput]: value + } + } + } + return node + }) + ) + } } return ( diff --git a/packages/ui/src/utils/genericHelper.js b/packages/ui/src/utils/genericHelper.js index 749e12021..378449d51 100644 --- a/packages/ui/src/utils/genericHelper.js +++ b/packages/ui/src/utils/genericHelper.js @@ -233,3 +233,20 @@ export const copyToClipboard = (e) => { navigator.clipboard.writeText(src) } } + +export const rearrangeToolsOrdering = (newValues, sourceNodeId) => { + // RequestsGet and RequestsPost have to be in order before other tools + newValues.push(`{{${sourceNodeId}.data.instance}}`) + + const sortKey = (item) => { + if (item.includes('requestsGet')) { + return 0 + } else if (item.includes('requestsPost')) { + return 1 + } else { + return 2 + } + } + + newValues.sort((a, b) => sortKey(a) - sortKey(b)) +} diff --git a/packages/ui/src/views/canvas/index.js b/packages/ui/src/views/canvas/index.js index edbfbacc3..4c9d580d3 100644 --- a/packages/ui/src/views/canvas/index.js +++ b/packages/ui/src/views/canvas/index.js @@ -38,7 +38,7 @@ import useConfirm from 'hooks/useConfirm' import { IconX } from '@tabler/icons' // utils -import { getUniqueNodeId, initNode, getEdgeLabelName } from 'utils/genericHelper' +import { getUniqueNodeId, initNode, getEdgeLabelName, rearrangeToolsOrdering } from 'utils/genericHelper' import useNotifier from 'utils/useNotifier' const nodeTypes = { customNode: CanvasNode } @@ -110,7 +110,11 @@ const Canvas = () => { const inputAnchor = node.data.inputAnchors.find((ancr) => ancr.name === targetInput) if (inputAnchor && inputAnchor.list) { const newValues = node.data.inputs[targetInput] || [] - newValues.push(`{{${sourceNodeId}.data.instance}}`) + if (targetInput === 'tools') { + rearrangeToolsOrdering(newValues, sourceNodeId) + } else { + newValues.push(`{{${sourceNodeId}.data.instance}}`) + } value = newValues } else { value = `{{${sourceNodeId}.data.instance}}` From e1624d11d5ae069b58b9095029a643e695ca6647 Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 18 Apr 2023 00:36:18 +0100 Subject: [PATCH 4/6] add sqldbchain and example --- .../SqlDatabaseChain/SqlDatabaseChain.ts | 81 +++++++++ .../chains/SqlDatabaseChain/sqlchain.svg | 7 + .../server/marketplaces/SQL DB Chain.json | 163 ++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts create mode 100644 packages/components/nodes/chains/SqlDatabaseChain/sqlchain.svg create mode 100644 packages/server/marketplaces/SQL DB Chain.json diff --git a/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts b/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts new file mode 100644 index 000000000..1f6d9fddb --- /dev/null +++ b/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts @@ -0,0 +1,81 @@ +import { INode, INodeData, INodeParams } from '../../../src/Interface' +import { SqlDatabaseChain } from 'langchain/chains' +import { getBaseClasses } from '../../../src/utils' +import { DataSource } from 'typeorm' +import { SqlDatabase } from 'langchain/sql_db' +import { BaseLLM } from 'langchain/llms/base' + +class SqlDatabaseChain_Chains implements INode { + label: string + name: string + type: string + icon: string + category: string + baseClasses: string[] + description: string + inputs: INodeParams[] + + constructor() { + this.label = 'Sql Database Chain' + this.name = 'sqlDatabaseChain' + this.type = 'SqlDatabaseChain' + this.icon = 'sqlchain.svg' + this.category = 'Chains' + this.description = 'Answer questions over a SQL database' + this.baseClasses = [this.type, ...getBaseClasses(SqlDatabaseChain)] + this.inputs = [ + { + label: 'LLM', + name: 'llm', + type: 'BaseLLM' + }, + { + label: 'Database', + name: 'database', + type: 'options', + options: [ + { + label: 'SQlite', + name: 'sqlite' + } + ], + default: 'sqlite' + }, + { + label: 'Database File Path', + name: 'dbFilePath', + type: 'string', + placeholder: 'C:/Users/chinook.db' + } + ] + } + + async init(nodeData: INodeData): Promise { + const databaseType = nodeData.inputs?.database + const llm = nodeData.inputs?.llm as BaseLLM + const dbFilePath = nodeData.inputs?.dbFilePath + + const datasource = new DataSource({ + type: databaseType, + database: dbFilePath + }) + + const db = await SqlDatabase.fromDataSourceParams({ + appDataSource: datasource + }) + + const chain = new SqlDatabaseChain({ + llm, + database: db + }) + return chain + } + + async run(nodeData: INodeData, input: string): Promise { + const chain = nodeData.instance as SqlDatabaseChain + const res = await chain.run(input) + return res + } +} + +module.exports = { nodeClass: SqlDatabaseChain_Chains } diff --git a/packages/components/nodes/chains/SqlDatabaseChain/sqlchain.svg b/packages/components/nodes/chains/SqlDatabaseChain/sqlchain.svg new file mode 100644 index 000000000..dcf937b35 --- /dev/null +++ b/packages/components/nodes/chains/SqlDatabaseChain/sqlchain.svg @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/packages/server/marketplaces/SQL DB Chain.json b/packages/server/marketplaces/SQL DB Chain.json new file mode 100644 index 000000000..4d8b35c8a --- /dev/null +++ b/packages/server/marketplaces/SQL DB Chain.json @@ -0,0 +1,163 @@ +{ + "description": "Answer questions over a SQL database", + "nodes": [ + { + "width": 300, + "height": 424, + "id": "sqlDatabaseChain_0", + "position": { + "x": 1271.2742585099204, + "y": 232.91561199714107 + }, + "type": "customNode", + "data": { + "id": "sqlDatabaseChain_0", + "label": "Sql Database Chain", + "name": "sqlDatabaseChain", + "type": "SqlDatabaseChain", + "baseClasses": ["SqlDatabaseChain", "BaseChain"], + "category": "Chains", + "description": "Answer questions over a SQL database", + "inputParams": [ + { + "label": "Database", + "name": "database", + "type": "options", + "options": [ + { + "label": "SQlite", + "name": "sqlite" + } + ], + "default": "sqlite" + }, + { + "label": "Database File Path", + "name": "dbFilePath", + "type": "string", + "placeholder": "C:/Users/chinook.db" + } + ], + "inputAnchors": [ + { + "label": "LLM", + "name": "llm", + "type": "BaseLLM", + "id": "sqlDatabaseChain_0-input-llm-BaseLLM" + } + ], + "inputs": { + "llm": "{{openAI_0.data.instance}}", + "database": "sqlite", + "dbFilePath": "" + }, + "outputAnchors": [ + { + "id": "sqlDatabaseChain_0-output-sqlDatabaseChain-SqlDatabaseChain|BaseChain", + "name": "sqlDatabaseChain", + "label": "SqlDatabaseChain", + "type": "SqlDatabaseChain | BaseChain" + } + ], + "selected": false + }, + "selected": false, + "positionAbsolute": { + "x": 1271.2742585099204, + "y": 232.91561199714107 + }, + "dragging": false + }, + { + "width": 300, + "height": 472, + "id": "openAI_0", + "position": { + "x": 867.8574087065126, + "y": 209.58625096303308 + }, + "type": "customNode", + "data": { + "id": "openAI_0", + "label": "OpenAI", + "name": "openAI", + "type": "OpenAI", + "baseClasses": ["OpenAI", "BaseLLM", "BaseLanguageModel"], + "category": "LLMs", + "description": "Wrapper around OpenAI large language models", + "inputParams": [ + { + "label": "OpenAI Api Key", + "name": "openAIApiKey", + "type": "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 + }, + { + "label": "Temperature", + "name": "temperature", + "type": "number", + "default": 0.7, + "optional": true + } + ], + "inputAnchors": [], + "inputs": { + "modelName": "text-davinci-003", + "temperature": "0" + }, + "outputAnchors": [ + { + "id": "openAI_0-output-openAI-OpenAI|BaseLLM|BaseLanguageModel", + "name": "openAI", + "label": "OpenAI", + "type": "OpenAI | BaseLLM | BaseLanguageModel" + } + ], + "selected": false + }, + "selected": false, + "positionAbsolute": { + "x": 867.8574087065126, + "y": 209.58625096303308 + }, + "dragging": false + } + ], + "edges": [ + { + "source": "openAI_0", + "sourceHandle": "openAI_0-output-openAI-OpenAI|BaseLLM|BaseLanguageModel", + "target": "sqlDatabaseChain_0", + "targetHandle": "sqlDatabaseChain_0-input-llm-BaseLLM", + "type": "buttonedge", + "id": "openAI_0-openAI_0-output-openAI-OpenAI|BaseLLM|BaseLanguageModel-sqlDatabaseChain_0-sqlDatabaseChain_0-input-llm-BaseLLM", + "data": { + "label": "" + } + } + ] +} From aad473d94692a8fc0345d342867ac2ced90a222e Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 19 Apr 2023 14:48:31 +0100 Subject: [PATCH 5/6] add chatgpt plugin --- .../agents/MRKLAgentChat/MRKLAgentChat.ts | 18 +- .../nodes/tools/AIPlugin/AIPlugin.ts | 7 +- .../server/marketplaces/ChatGPTPlugin.json | 307 ++++++++++++++++++ 3 files changed, 312 insertions(+), 20 deletions(-) create mode 100644 packages/server/marketplaces/ChatGPTPlugin.json diff --git a/packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts b/packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts index f583ac026..d74f0b32c 100644 --- a/packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts +++ b/packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts @@ -1,6 +1,5 @@ import { INode, INodeData, INodeParams } from '../../../src/Interface' -import { initializeAgentExecutor, AgentExecutor } from 'langchain/agents' -import { AIPluginTool } from 'langchain/tools' +import { initializeAgentExecutor, AgentExecutor, Tool } from 'langchain/agents' import { BaseChatModel } from 'langchain/chat_models/base' import { getBaseClasses } from '../../../src/utils' @@ -39,20 +38,9 @@ class MRKLAgentChat_Agents implements INode { async init(nodeData: INodeData): Promise { const model = nodeData.inputs?.model as BaseChatModel - const tools = nodeData.inputs?.tools + const tools = nodeData.inputs?.tools as Tool[] - const allowedTools = [] - for (let i = 0; i < tools.length; i += 1) { - if (tools[i].pluginUrl) { - const pluginURL: string = tools[i].pluginUrl - const aiplugin = await AIPluginTool.fromPluginUrl(pluginURL) - allowedTools.push(aiplugin) - } else { - allowedTools.push(tools[i]) - } - } - - const executor = await initializeAgentExecutor(allowedTools, model, 'chat-zero-shot-react-description', true) + const executor = await initializeAgentExecutor(tools, model, 'chat-zero-shot-react-description', true) return executor } diff --git a/packages/components/nodes/tools/AIPlugin/AIPlugin.ts b/packages/components/nodes/tools/AIPlugin/AIPlugin.ts index 156b138d2..ad21f8dbc 100644 --- a/packages/components/nodes/tools/AIPlugin/AIPlugin.ts +++ b/packages/components/nodes/tools/AIPlugin/AIPlugin.ts @@ -32,11 +32,8 @@ class AIPlugin implements INode { async init(nodeData: INodeData): Promise { const pluginUrl = nodeData.inputs?.pluginUrl as string - // Doesn't work currently - // const aiplugin = await AIPluginTool.fromPluginUrl(pluginUrl) - const aiplugin = { - pluginUrl: pluginUrl - } + const aiplugin = await AIPluginTool.fromPluginUrl(pluginUrl) + return aiplugin } } diff --git a/packages/server/marketplaces/ChatGPTPlugin.json b/packages/server/marketplaces/ChatGPTPlugin.json new file mode 100644 index 000000000..7a65a665f --- /dev/null +++ b/packages/server/marketplaces/ChatGPTPlugin.json @@ -0,0 +1,307 @@ +{ + "description": "Use ChatGPT Plugins within LangChain abstractions with GET and POST Tools", + "nodes": [ + { + "width": 300, + "height": 278, + "id": "aiPlugin_0", + "position": { + "x": 992.9213747553727, + "y": 115.80946637479596 + }, + "type": "customNode", + "data": { + "id": "aiPlugin_0", + "label": "AI Plugin", + "name": "aiPlugin", + "type": "AIPlugin", + "baseClasses": ["AIPlugin", "Tool"], + "category": "Tools", + "description": "Execute actions using ChatGPT Plugin Url", + "inputParams": [ + { + "label": "Plugin Url", + "name": "pluginUrl", + "type": "string", + "placeholder": "https://www.klarna.com/.well-known/ai-plugin.json" + } + ], + "inputAnchors": [], + "inputs": { + "pluginUrl": "https://www.klarna.com/.well-known/ai-plugin.json" + }, + "outputAnchors": [ + { + "id": "aiPlugin_0-output-aiPlugin-AIPlugin|Tool", + "name": "aiPlugin", + "label": "AIPlugin", + "type": "AIPlugin | Tool" + } + ], + "selected": false + }, + "selected": false, + "positionAbsolute": { + "x": 992.9213747553727, + "y": 115.80946637479596 + }, + "dragging": false + }, + { + "width": 300, + "height": 143, + "id": "requestsPost_0", + "position": { + "x": 638.2831241951309, + "y": 294.0784991300699 + }, + "type": "customNode", + "data": { + "id": "requestsPost_0", + "label": "Requests Post", + "name": "requestsPost", + "type": "RequestsPost", + "baseClasses": ["RequestsPost", "Tool"], + "category": "Tools", + "description": "Execute HTTP POST requests", + "inputParams": [], + "inputAnchors": [], + "inputs": {}, + "outputAnchors": [ + { + "id": "requestsPost_0-output-requestsPost-RequestsPost|Tool", + "name": "requestsPost", + "label": "RequestsPost", + "type": "RequestsPost | Tool" + } + ], + "selected": false + }, + "positionAbsolute": { + "x": 638.2831241951309, + "y": 294.0784991300699 + }, + "selected": false, + "dragging": false + }, + { + "width": 300, + "height": 143, + "id": "requestsGet_0", + "position": { + "x": 703.0477667387721, + "y": 476.8955204497346 + }, + "type": "customNode", + "data": { + "id": "requestsGet_0", + "label": "Requests Get", + "name": "requestsGet", + "type": "RequestsGet", + "baseClasses": ["RequestsGet", "Tool"], + "category": "Tools", + "description": "Execute HTTP GET requests", + "inputParams": [], + "inputAnchors": [], + "inputs": {}, + "outputAnchors": [ + { + "id": "requestsGet_0-output-requestsGet-RequestsGet|Tool", + "name": "requestsGet", + "label": "RequestsGet", + "type": "RequestsGet | Tool" + } + ], + "selected": false + }, + "selected": false, + "positionAbsolute": { + "x": 703.0477667387721, + "y": 476.8955204497346 + }, + "dragging": false + }, + { + "width": 300, + "height": 280, + "id": "mrklAgentChat_0", + "position": { + "x": 1363.057715565282, + "y": 479.27393467974 + }, + "type": "customNode", + "data": { + "id": "mrklAgentChat_0", + "label": "MRKL Agent for Chat Models", + "name": "mrklAgentChat", + "type": "AgentExecutor", + "baseClasses": ["AgentExecutor", "BaseChain"], + "category": "Agents", + "description": "Agent that uses the ReAct Framework to decide what action to take, optimized to be used with Chat Models", + "inputParams": [], + "inputAnchors": [ + { + "label": "Allowed Tools", + "name": "tools", + "type": "Tool", + "list": true, + "id": "mrklAgentChat_0-input-tools-Tool" + }, + { + "label": "Chat Model", + "name": "model", + "type": "BaseChatModel", + "id": "mrklAgentChat_0-input-model-BaseChatModel" + } + ], + "inputs": { + "tools": ["{{requestsGet_0.data.instance}}", "{{requestsPost_0.data.instance}}", "{{aiPlugin_0.data.instance}}"], + "model": "{{chatOpenAI_0.data.instance}}" + }, + "outputAnchors": [ + { + "id": "mrklAgentChat_0-output-mrklAgentChat-AgentExecutor|BaseChain", + "name": "mrklAgentChat", + "label": "AgentExecutor", + "type": "AgentExecutor | BaseChain" + } + ], + "selected": false + }, + "selected": false, + "positionAbsolute": { + "x": 1363.057715565282, + "y": 479.27393467974 + }, + "dragging": false + }, + { + "width": 300, + "height": 472, + "id": "chatOpenAI_0", + "position": { + "x": 724.4534948088211, + "y": 668.3578659651726 + }, + "type": "customNode", + "data": { + "id": "chatOpenAI_0", + "label": "ChatOpenAI", + "name": "chatOpenAI", + "type": "ChatOpenAI", + "baseClasses": ["ChatOpenAI", "BaseChatModel", "BaseLanguageModel"], + "category": "Chat Models", + "description": "Wrapper around OpenAI large language models that use the Chat endpoint", + "inputParams": [ + { + "label": "OpenAI Api Key", + "name": "openAIApiKey", + "type": "password" + }, + { + "label": "Model Name", + "name": "modelName", + "type": "options", + "options": [ + { + "label": "gpt-4", + "name": "gpt-4" + }, + { + "label": "gpt-4-0314", + "name": "gpt-4-0314" + }, + { + "label": "gpt-4-32k-0314", + "name": "gpt-4-32k-0314" + }, + { + "label": "gpt-3.5-turbo", + "name": "gpt-3.5-turbo" + }, + { + "label": "gpt-3.5-turbo-0301", + "name": "gpt-3.5-turbo-0301" + } + ], + "default": "gpt-3.5-turbo", + "optional": true + }, + { + "label": "Temperature", + "name": "temperature", + "type": "number", + "default": 0.9, + "optional": true + } + ], + "inputAnchors": [], + "inputs": { + "modelName": "gpt-3.5-turbo", + "temperature": "0" + }, + "outputAnchors": [ + { + "id": "chatOpenAI_0-output-chatOpenAI-ChatOpenAI|BaseChatModel|BaseLanguageModel", + "name": "chatOpenAI", + "label": "ChatOpenAI", + "type": "ChatOpenAI | BaseChatModel | BaseLanguageModel" + } + ], + "selected": false + }, + "selected": false, + "positionAbsolute": { + "x": 724.4534948088211, + "y": 668.3578659651726 + }, + "dragging": false + } + ], + "edges": [ + { + "source": "aiPlugin_0", + "sourceHandle": "aiPlugin_0-output-aiPlugin-AIPlugin|Tool", + "target": "mrklAgentChat_0", + "targetHandle": "mrklAgentChat_0-input-tools-Tool", + "type": "buttonedge", + "id": "aiPlugin_0-aiPlugin_0-output-aiPlugin-AIPlugin|Tool-mrklAgentChat_0-mrklAgentChat_0-input-tools-Tool", + "data": { + "label": "" + } + }, + { + "source": "requestsGet_0", + "sourceHandle": "requestsGet_0-output-requestsGet-RequestsGet|Tool", + "target": "mrklAgentChat_0", + "targetHandle": "mrklAgentChat_0-input-tools-Tool", + "type": "buttonedge", + "id": "requestsGet_0-requestsGet_0-output-requestsGet-RequestsGet|Tool-mrklAgentChat_0-mrklAgentChat_0-input-tools-Tool", + "data": { + "label": "" + } + }, + { + "source": "requestsPost_0", + "sourceHandle": "requestsPost_0-output-requestsPost-RequestsPost|Tool", + "target": "mrklAgentChat_0", + "targetHandle": "mrklAgentChat_0-input-tools-Tool", + "type": "buttonedge", + "id": "requestsPost_0-requestsPost_0-output-requestsPost-RequestsPost|Tool-mrklAgentChat_0-mrklAgentChat_0-input-tools-Tool", + "data": { + "label": "" + } + }, + { + "source": "chatOpenAI_0", + "sourceHandle": "chatOpenAI_0-output-chatOpenAI-ChatOpenAI|BaseChatModel|BaseLanguageModel", + "target": "mrklAgentChat_0", + "targetHandle": "mrklAgentChat_0-input-model-BaseChatModel", + "type": "buttonedge", + "id": "chatOpenAI_0-chatOpenAI_0-output-chatOpenAI-ChatOpenAI|BaseChatModel|BaseLanguageModel-mrklAgentChat_0-mrklAgentChat_0-input-model-BaseChatModel", + "data": { + "label": "" + } + } + ] +} From 557f50e52d07dfbcc129cd2219041de1a3b5ca47 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 19 Apr 2023 14:55:32 +0100 Subject: [PATCH 6/6] add yarn build-force --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index cfc2aee50..82ade94ce 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ ], "scripts": { "build": "turbo run build", + "build-force": "turbo run build --force", "dev": "turbo run dev --parallel", "start": "run-script-os", "start:windows": "cd packages/server/bin && run start",