mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 23:01:09 +03:00
add autogpt, readfile and writefile tools
This commit is contained in:
@@ -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<any> {
|
||||
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<string> {
|
||||
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 }
|
||||
Reference in New Issue
Block a user