add additional params

This commit is contained in:
Henry
2023-04-27 23:14:42 +01:00
parent 0f6da4c44f
commit e53651a415
6 changed files with 161 additions and 11 deletions
@@ -1,5 +1,5 @@
import { INode, INodeData, INodeParams } from '../../../src/Interface'
import { initializeAgentExecutorWithOptions, AgentExecutor } from 'langchain/agents'
import { initializeAgentExecutorWithOptions, AgentExecutor, InitializeAgentExecutorOptions } from 'langchain/agents'
import { Tool } from 'langchain/tools'
import { BaseChatModel } from 'langchain/chat_models/base'
import { BaseChatMemory } from 'langchain/memory'
@@ -39,6 +39,22 @@ class ConversationalAgent_Agents implements INode {
label: 'Memory',
name: 'memory',
type: 'BaseChatMemory'
},
{
label: 'System Message',
name: 'systemMessage',
type: 'string',
rows: 4,
optional: true,
additionalParams: true
},
{
label: 'Human Message',
name: 'humanMessage',
type: 'string',
rows: 4,
optional: true,
additionalParams: true
}
]
}
@@ -47,11 +63,25 @@ class ConversationalAgent_Agents implements INode {
const model = nodeData.inputs?.model as BaseChatModel
const tools = nodeData.inputs?.tools as Tool[]
const memory = nodeData.inputs?.memory as BaseChatMemory
const humanMessage = nodeData.inputs?.humanMessage as string
const systemMessage = nodeData.inputs?.systemMessage as string
const executor = await initializeAgentExecutorWithOptions(tools, model, {
const obj: InitializeAgentExecutorOptions = {
agentType: 'chat-conversational-react-description',
verbose: true
})
}
const agentArgs: any = {}
if (humanMessage) {
agentArgs.humanMessage = humanMessage
}
if (systemMessage) {
agentArgs.systemMessage = systemMessage
}
if (Object.keys(agentArgs).length) obj.agentArgs = agentArgs
const executor = await initializeAgentExecutorWithOptions(tools, model, obj)
executor.memory = memory
return executor
}