diff --git a/packages/components/nodes/agents/AutoGPT/AutoGPT.ts b/packages/components/nodes/agents/AutoGPT/AutoGPT.ts new file mode 100644 index 000000000..9ae9e90e3 --- /dev/null +++ b/packages/components/nodes/agents/AutoGPT/AutoGPT.ts @@ -0,0 +1,97 @@ +import { INode, INodeData, INodeParams } from '../../../src/Interface' +import { BaseChatModel } from 'langchain/chat_models' +import { AutoGPT } from 'langchain/experimental/autogpt' +import { Tool } from 'langchain/tools' +import { VectorStoreRetriever } from 'langchain/vectorstores/base' + +class AutoGPT_Agents implements INode { + label: string + name: string + description: string + type: string + icon: string + category: string + baseClasses: string[] + inputs: INodeParams[] + + constructor() { + this.label = 'AutoGPT' + this.name = 'autoGPT' + this.type = 'AutoGPT' + this.category = 'Agents' + this.icon = 'autogpt.png' + this.description = 'Autonomous agent with chain of thoughts by GPT4' + this.baseClasses = ['AutoGPT'] + this.inputs = [ + { + label: 'Allowed Tools', + name: 'tools', + type: 'Tool', + list: true + }, + { + label: 'Chat Model', + name: 'model', + type: 'BaseChatModel' + }, + { + label: 'Vector Store Retriever', + name: 'vectorStoreRetriever', + type: 'BaseRetriever' + }, + { + label: 'AutoGPT Name', + name: 'aiName', + type: 'string', + placeholder: 'Tom', + optional: true + }, + { + label: 'AutoGPT Role', + name: 'aiRole', + type: 'string', + placeholder: 'Assistant', + optional: true + }, + { + label: 'Maximum Loop', + name: 'maxLoop', + type: 'number', + default: 5, + optional: true + } + ] + } + + 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[] + const aiName = (nodeData.inputs?.aiName as string) || 'AutoGPT' + const aiRole = (nodeData.inputs?.aiRole as string) || 'Assistant' + const maxLoop = nodeData.inputs?.maxLoop as string + + const autogpt = AutoGPT.fromLLMAndTools(model, tools, { + memory: vectorStoreRetriever, + aiName, + aiRole + }) + + autogpt.maxIterations = parseInt(maxLoop, 10) + + return autogpt + } + + async run(nodeData: INodeData, input: string): Promise { + const executor = nodeData.instance as AutoGPT + try { + const res = await executor.run([input]) + return res || 'I have completed all my tasks.' + } catch (e) { + console.error(e) + throw new Error(e) + } + } +} + +module.exports = { nodeClass: AutoGPT_Agents } diff --git a/packages/components/nodes/agents/AutoGPT/autogpt.png b/packages/components/nodes/agents/AutoGPT/autogpt.png new file mode 100644 index 000000000..bdeff726c Binary files /dev/null and b/packages/components/nodes/agents/AutoGPT/autogpt.png differ diff --git a/packages/components/nodes/tools/ReadFile/ReadFile.ts b/packages/components/nodes/tools/ReadFile/ReadFile.ts new file mode 100644 index 000000000..b66789438 --- /dev/null +++ b/packages/components/nodes/tools/ReadFile/ReadFile.ts @@ -0,0 +1,42 @@ +import { INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses } from '../../../src/utils' +import { ReadFileTool } from 'langchain/tools' +import { NodeFileStore } from 'langchain/stores/file/node' + +class ReadFile_Tools implements INode { + label: string + name: string + description: string + type: string + icon: string + category: string + baseClasses: string[] + inputs: INodeParams[] + + constructor() { + this.label = 'Read File' + this.name = 'readFile' + this.type = 'ReadFile' + this.icon = 'readfile.svg' + this.category = 'Tools' + this.description = 'Read file from disk' + this.baseClasses = [this.type, 'Tool', ...getBaseClasses(ReadFileTool)] + this.inputs = [ + { + label: 'Base Path', + name: 'basePath', + placeholder: `C:\\Users\\User\\Desktop`, + type: 'string', + optional: true + } + ] + } + + async init(nodeData: INodeData): Promise { + const basePath = nodeData.inputs?.basePath as string + const store = basePath ? new NodeFileStore(basePath) : new NodeFileStore() + return new ReadFileTool({ store }) + } +} + +module.exports = { nodeClass: ReadFile_Tools } diff --git a/packages/components/nodes/tools/ReadFile/readfile.svg b/packages/components/nodes/tools/ReadFile/readfile.svg new file mode 100644 index 000000000..3a57a762c --- /dev/null +++ b/packages/components/nodes/tools/ReadFile/readfile.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/packages/components/nodes/tools/WriteFile/WriteFile.ts b/packages/components/nodes/tools/WriteFile/WriteFile.ts new file mode 100644 index 000000000..208166d86 --- /dev/null +++ b/packages/components/nodes/tools/WriteFile/WriteFile.ts @@ -0,0 +1,42 @@ +import { INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses } from '../../../src/utils' +import { WriteFileTool } from 'langchain/tools' +import { NodeFileStore } from 'langchain/stores/file/node' + +class WriteFile_Tools implements INode { + label: string + name: string + description: string + type: string + icon: string + category: string + baseClasses: string[] + inputs: INodeParams[] + + constructor() { + this.label = 'Write File' + this.name = 'writeFile' + this.type = 'WriteFile' + this.icon = 'writefile.svg' + this.category = 'Tools' + this.description = 'Write file to disk' + this.baseClasses = [this.type, 'Tool', ...getBaseClasses(WriteFileTool)] + this.inputs = [ + { + label: 'Base Path', + name: 'basePath', + placeholder: `C:\\Users\\User\\Desktop`, + type: 'string', + optional: true + } + ] + } + + async init(nodeData: INodeData): Promise { + const basePath = nodeData.inputs?.basePath as string + const store = basePath ? new NodeFileStore(basePath) : new NodeFileStore() + return new WriteFileTool({ store }) + } +} + +module.exports = { nodeClass: WriteFile_Tools } diff --git a/packages/components/nodes/tools/WriteFile/writefile.svg b/packages/components/nodes/tools/WriteFile/writefile.svg new file mode 100644 index 000000000..72500bf64 --- /dev/null +++ b/packages/components/nodes/tools/WriteFile/writefile.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/packages/components/nodes/vectorstores/Chroma_Existing/Chroma_Existing.ts b/packages/components/nodes/vectorstores/Chroma_Existing/Chroma_Existing.ts index 904c44edc..ec9d28a17 100644 --- a/packages/components/nodes/vectorstores/Chroma_Existing/Chroma_Existing.ts +++ b/packages/components/nodes/vectorstores/Chroma_Existing/Chroma_Existing.ts @@ -21,7 +21,7 @@ class Chroma_Existing_VectorStores implements INode { this.icon = 'chroma.svg' this.category = 'Vector Stores' this.description = 'Load existing index from Chroma (i.e: Document has been upserted)' - this.baseClasses = [this.type, 'BaseRetriever'] + this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever'] this.inputs = [ { label: 'Embeddings', @@ -38,7 +38,7 @@ class Chroma_Existing_VectorStores implements INode { { label: 'Chroma Retriever', name: 'retriever', - baseClasses: [this.type, 'BaseRetriever'] + baseClasses: this.baseClasses }, { label: 'Chroma Vector Store', diff --git a/packages/components/nodes/vectorstores/Chroma_Upsert/Chroma_Upsert.ts b/packages/components/nodes/vectorstores/Chroma_Upsert/Chroma_Upsert.ts index d71f96ec9..3f3001709 100644 --- a/packages/components/nodes/vectorstores/Chroma_Upsert/Chroma_Upsert.ts +++ b/packages/components/nodes/vectorstores/Chroma_Upsert/Chroma_Upsert.ts @@ -22,7 +22,7 @@ class ChromaUpsert_VectorStores implements INode { this.icon = 'chroma.svg' this.category = 'Vector Stores' this.description = 'Upsert documents to Chroma' - this.baseClasses = [this.type, 'BaseRetriever'] + this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever'] this.inputs = [ { label: 'Document', @@ -44,7 +44,7 @@ class ChromaUpsert_VectorStores implements INode { { label: 'Chroma Retriever', name: 'retriever', - baseClasses: [this.type, 'BaseRetriever'] + baseClasses: this.baseClasses }, { label: 'Chroma Vector Store', diff --git a/packages/components/nodes/vectorstores/Pinecone_Existing/Pinecone_Existing.ts b/packages/components/nodes/vectorstores/Pinecone_Existing/Pinecone_Existing.ts index fd55de484..7b3223c89 100644 --- a/packages/components/nodes/vectorstores/Pinecone_Existing/Pinecone_Existing.ts +++ b/packages/components/nodes/vectorstores/Pinecone_Existing/Pinecone_Existing.ts @@ -22,7 +22,7 @@ class Pinecone_Existing_VectorStores implements INode { this.icon = 'pinecone.png' this.category = 'Vector Stores' this.description = 'Load existing index from Pinecone (i.e: Document has been upserted)' - this.baseClasses = [this.type, 'BaseRetriever'] + this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever'] this.inputs = [ { label: 'Embeddings', @@ -49,7 +49,7 @@ class Pinecone_Existing_VectorStores implements INode { { label: 'Pinecone Retriever', name: 'retriever', - baseClasses: [this.type, 'BaseRetriever'] + baseClasses: this.baseClasses }, { label: 'Pinecone Vector Store', diff --git a/packages/components/nodes/vectorstores/Pinecone_Upsert/Pinecone_Upsert.ts b/packages/components/nodes/vectorstores/Pinecone_Upsert/Pinecone_Upsert.ts index cbce7b4b2..6f72eb83a 100644 --- a/packages/components/nodes/vectorstores/Pinecone_Upsert/Pinecone_Upsert.ts +++ b/packages/components/nodes/vectorstores/Pinecone_Upsert/Pinecone_Upsert.ts @@ -23,7 +23,7 @@ class PineconeUpsert_VectorStores implements INode { this.icon = 'pinecone.png' this.category = 'Vector Stores' this.description = 'Upsert documents to Pinecone' - this.baseClasses = [this.type, 'BaseRetriever'] + this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever'] this.inputs = [ { label: 'Document', @@ -55,7 +55,7 @@ class PineconeUpsert_VectorStores implements INode { { label: 'Pinecone Retriever', name: 'retriever', - baseClasses: [this.type, 'BaseRetriever'] + baseClasses: this.baseClasses }, { label: 'Pinecone Vector Store', diff --git a/packages/components/package.json b/packages/components/package.json index 56b43d040..79782ca16 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -27,7 +27,7 @@ "dotenv": "^16.0.0", "express": "^4.17.3", "form-data": "^4.0.0", - "langchain": "^0.0.59", + "langchain": "^0.0.60", "moment": "^2.29.3", "node-fetch": "2", "pdf-parse": "^1.1.1", diff --git a/packages/ui/src/utils/genericHelper.js b/packages/ui/src/utils/genericHelper.js index dd63c1313..199373754 100644 --- a/packages/ui/src/utils/genericHelper.js +++ b/packages/ui/src/utils/genericHelper.js @@ -292,9 +292,9 @@ export const rearrangeToolsOrdering = (newValues, sourceNodeId) => { newValues.push(`{{${sourceNodeId}.data.instance}}`) const sortKey = (item) => { - if (item.includes('requestsGet')) { + if (item.includes('requestsGet') || item.includes('readFile')) { return 0 - } else if (item.includes('requestsPost')) { + } else if (item.includes('requestsPost') || item.includes('writeFile')) { return 1 } else { return 2