Skip to content

Commit e008718

Browse files
authored
Merge pull request #27 from FlowiseAI/feature/AutoGPT
Feature/Add AutoGPT, Readfile and Writefile tools
2 parents 237eca2 + aa2308d commit e008718

File tree

13 files changed

+725
-11
lines changed

13 files changed

+725
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { INode, INodeData, INodeParams } from '../../../src/Interface'
2+
import { BaseChatModel } from 'langchain/chat_models'
3+
import { AutoGPT } from 'langchain/experimental/autogpt'
4+
import { Tool } from 'langchain/tools'
5+
import { VectorStoreRetriever } from 'langchain/vectorstores/base'
6+
7+
class AutoGPT_Agents implements INode {
8+
label: string
9+
name: string
10+
description: string
11+
type: string
12+
icon: string
13+
category: string
14+
baseClasses: string[]
15+
inputs: INodeParams[]
16+
17+
constructor() {
18+
this.label = 'AutoGPT'
19+
this.name = 'autoGPT'
20+
this.type = 'AutoGPT'
21+
this.category = 'Agents'
22+
this.icon = 'autogpt.png'
23+
this.description = 'Autonomous agent with chain of thoughts for self-guided task completion'
24+
this.baseClasses = ['AutoGPT']
25+
this.inputs = [
26+
{
27+
label: 'Allowed Tools',
28+
name: 'tools',
29+
type: 'Tool',
30+
list: true
31+
},
32+
{
33+
label: 'Chat Model',
34+
name: 'model',
35+
type: 'BaseChatModel'
36+
},
37+
{
38+
label: 'Vector Store Retriever',
39+
name: 'vectorStoreRetriever',
40+
type: 'BaseRetriever'
41+
},
42+
{
43+
label: 'AutoGPT Name',
44+
name: 'aiName',
45+
type: 'string',
46+
placeholder: 'Tom',
47+
optional: true
48+
},
49+
{
50+
label: 'AutoGPT Role',
51+
name: 'aiRole',
52+
type: 'string',
53+
placeholder: 'Assistant',
54+
optional: true
55+
},
56+
{
57+
label: 'Maximum Loop',
58+
name: 'maxLoop',
59+
type: 'number',
60+
default: 5,
61+
optional: true
62+
}
63+
]
64+
}
65+
66+
async init(nodeData: INodeData): Promise<any> {
67+
const model = nodeData.inputs?.model as BaseChatModel
68+
const vectorStoreRetriever = nodeData.inputs?.vectorStoreRetriever as VectorStoreRetriever
69+
const tools = nodeData.inputs?.tools as Tool[]
70+
const aiName = (nodeData.inputs?.aiName as string) || 'AutoGPT'
71+
const aiRole = (nodeData.inputs?.aiRole as string) || 'Assistant'
72+
const maxLoop = nodeData.inputs?.maxLoop as string
73+
74+
const autogpt = AutoGPT.fromLLMAndTools(model, tools, {
75+
memory: vectorStoreRetriever,
76+
aiName,
77+
aiRole
78+
})
79+
80+
autogpt.maxIterations = parseInt(maxLoop, 10)
81+
82+
return autogpt
83+
}
84+
85+
async run(nodeData: INodeData, input: string): Promise<string> {
86+
const executor = nodeData.instance as AutoGPT
87+
try {
88+
const res = await executor.run([input])
89+
return res || 'I have completed all my tasks.'
90+
} catch (e) {
91+
console.error(e)
92+
throw new Error(e)
93+
}
94+
}
95+
}
96+
97+
module.exports = { nodeClass: AutoGPT_Agents }
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { INode, INodeData, INodeParams } from '../../../src/Interface'
2+
import { getBaseClasses } from '../../../src/utils'
3+
import { ReadFileTool } from 'langchain/tools'
4+
import { NodeFileStore } from 'langchain/stores/file/node'
5+
6+
class ReadFile_Tools implements INode {
7+
label: string
8+
name: string
9+
description: string
10+
type: string
11+
icon: string
12+
category: string
13+
baseClasses: string[]
14+
inputs: INodeParams[]
15+
16+
constructor() {
17+
this.label = 'Read File'
18+
this.name = 'readFile'
19+
this.type = 'ReadFile'
20+
this.icon = 'readfile.svg'
21+
this.category = 'Tools'
22+
this.description = 'Read file from disk'
23+
this.baseClasses = [this.type, 'Tool', ...getBaseClasses(ReadFileTool)]
24+
this.inputs = [
25+
{
26+
label: 'Base Path',
27+
name: 'basePath',
28+
placeholder: `C:\\Users\\User\\Desktop`,
29+
type: 'string',
30+
optional: true
31+
}
32+
]
33+
}
34+
35+
async init(nodeData: INodeData): Promise<any> {
36+
const basePath = nodeData.inputs?.basePath as string
37+
const store = basePath ? new NodeFileStore(basePath) : new NodeFileStore()
38+
return new ReadFileTool({ store })
39+
}
40+
}
41+
42+
module.exports = { nodeClass: ReadFile_Tools }
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { INode, INodeData, INodeParams } from '../../../src/Interface'
2+
import { getBaseClasses } from '../../../src/utils'
3+
import { WriteFileTool } from 'langchain/tools'
4+
import { NodeFileStore } from 'langchain/stores/file/node'
5+
6+
class WriteFile_Tools implements INode {
7+
label: string
8+
name: string
9+
description: string
10+
type: string
11+
icon: string
12+
category: string
13+
baseClasses: string[]
14+
inputs: INodeParams[]
15+
16+
constructor() {
17+
this.label = 'Write File'
18+
this.name = 'writeFile'
19+
this.type = 'WriteFile'
20+
this.icon = 'writefile.svg'
21+
this.category = 'Tools'
22+
this.description = 'Write file to disk'
23+
this.baseClasses = [this.type, 'Tool', ...getBaseClasses(WriteFileTool)]
24+
this.inputs = [
25+
{
26+
label: 'Base Path',
27+
name: 'basePath',
28+
placeholder: `C:\\Users\\User\\Desktop`,
29+
type: 'string',
30+
optional: true
31+
}
32+
]
33+
}
34+
35+
async init(nodeData: INodeData): Promise<any> {
36+
const basePath = nodeData.inputs?.basePath as string
37+
const store = basePath ? new NodeFileStore(basePath) : new NodeFileStore()
38+
return new WriteFileTool({ store })
39+
}
40+
}
41+
42+
module.exports = { nodeClass: WriteFile_Tools }
Loading

packages/components/nodes/vectorstores/Chroma_Existing/Chroma_Existing.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Chroma_Existing_VectorStores implements INode {
2121
this.icon = 'chroma.svg'
2222
this.category = 'Vector Stores'
2323
this.description = 'Load existing index from Chroma (i.e: Document has been upserted)'
24-
this.baseClasses = [this.type, 'BaseRetriever']
24+
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
2525
this.inputs = [
2626
{
2727
label: 'Embeddings',
@@ -38,7 +38,7 @@ class Chroma_Existing_VectorStores implements INode {
3838
{
3939
label: 'Chroma Retriever',
4040
name: 'retriever',
41-
baseClasses: [this.type, 'BaseRetriever']
41+
baseClasses: this.baseClasses
4242
},
4343
{
4444
label: 'Chroma Vector Store',

packages/components/nodes/vectorstores/Chroma_Upsert/Chroma_Upsert.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ChromaUpsert_VectorStores implements INode {
2222
this.icon = 'chroma.svg'
2323
this.category = 'Vector Stores'
2424
this.description = 'Upsert documents to Chroma'
25-
this.baseClasses = [this.type, 'BaseRetriever']
25+
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
2626
this.inputs = [
2727
{
2828
label: 'Document',
@@ -44,7 +44,7 @@ class ChromaUpsert_VectorStores implements INode {
4444
{
4545
label: 'Chroma Retriever',
4646
name: 'retriever',
47-
baseClasses: [this.type, 'BaseRetriever']
47+
baseClasses: this.baseClasses
4848
},
4949
{
5050
label: 'Chroma Vector Store',

packages/components/nodes/vectorstores/Pinecone_Existing/Pinecone_Existing.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Pinecone_Existing_VectorStores implements INode {
2222
this.icon = 'pinecone.png'
2323
this.category = 'Vector Stores'
2424
this.description = 'Load existing index from Pinecone (i.e: Document has been upserted)'
25-
this.baseClasses = [this.type, 'BaseRetriever']
25+
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
2626
this.inputs = [
2727
{
2828
label: 'Embeddings',
@@ -49,7 +49,7 @@ class Pinecone_Existing_VectorStores implements INode {
4949
{
5050
label: 'Pinecone Retriever',
5151
name: 'retriever',
52-
baseClasses: [this.type, 'BaseRetriever']
52+
baseClasses: this.baseClasses
5353
},
5454
{
5555
label: 'Pinecone Vector Store',

packages/components/nodes/vectorstores/Pinecone_Upsert/Pinecone_Upsert.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class PineconeUpsert_VectorStores implements INode {
2323
this.icon = 'pinecone.png'
2424
this.category = 'Vector Stores'
2525
this.description = 'Upsert documents to Pinecone'
26-
this.baseClasses = [this.type, 'BaseRetriever']
26+
this.baseClasses = [this.type, 'VectorStoreRetriever', 'BaseRetriever']
2727
this.inputs = [
2828
{
2929
label: 'Document',
@@ -55,7 +55,7 @@ class PineconeUpsert_VectorStores implements INode {
5555
{
5656
label: 'Pinecone Retriever',
5757
name: 'retriever',
58-
baseClasses: [this.type, 'BaseRetriever']
58+
baseClasses: this.baseClasses
5959
},
6060
{
6161
label: 'Pinecone Vector Store',

packages/components/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"dotenv": "^16.0.0",
2828
"express": "^4.17.3",
2929
"form-data": "^4.0.0",
30-
"langchain": "^0.0.59",
30+
"langchain": "^0.0.60",
3131
"moment": "^2.29.3",
3232
"node-fetch": "2",
3333
"pdf-parse": "^1.1.1",

0 commit comments

Comments
 (0)