From 5ef0324304a1a78ebd68477a91fd76a50c91c5cb Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 7 Aug 2023 00:14:00 +0100 Subject: [PATCH] add output keys fix --- .../ConversationalRetrievalAgent.ts | 10 ++++------ packages/components/src/utils.ts | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/components/nodes/agents/ConversationalRetrievalAgent/ConversationalRetrievalAgent.ts b/packages/components/nodes/agents/ConversationalRetrievalAgent/ConversationalRetrievalAgent.ts index 01215fc2d..ed39fbc86 100644 --- a/packages/components/nodes/agents/ConversationalRetrievalAgent/ConversationalRetrievalAgent.ts +++ b/packages/components/nodes/agents/ConversationalRetrievalAgent/ConversationalRetrievalAgent.ts @@ -76,12 +76,10 @@ class ConversationalRetrievalAgent_Agents implements INode { async run(nodeData: INodeData, input: string, options: ICommonObject): Promise { const executor = nodeData.instance as AgentExecutor - if (options && options.chatHistory) { - if (executor.memory) { - ;(executor.memory as any).memoryKey = 'chat_history' - ;(executor.memory as any).outputKey = 'output' - ;(executor.memory as any).chatHistory = mapChatHistory(options) - } + if (executor.memory) { + ;(executor.memory as any).memoryKey = 'chat_history' + ;(executor.memory as any).outputKey = 'output' + ;(executor.memory as any).chatHistory = mapChatHistory(options) } const loggerHandler = new ConsoleCallbackHandler(options.logger) diff --git a/packages/components/src/utils.ts b/packages/components/src/utils.ts index 2f4e7f5b1..bcca834ae 100644 --- a/packages/components/src/utils.ts +++ b/packages/components/src/utils.ts @@ -509,7 +509,7 @@ export const getUserHome = (): string => { */ export const mapChatHistory = (options: ICommonObject): ChatMessageHistory => { const chatHistory = [] - const histories: IMessage[] = options.chatHistory + const histories: IMessage[] = options.chatHistory ?? [] for (const message of histories) { if (message.type === 'apiMessage') {