From fe6737a6cb4f7118c8d26f7d57001a85f17a36f0 Mon Sep 17 00:00:00 2001 From: Jeffrey-Wang Date: Mon, 12 Jun 2023 21:52:46 +0800 Subject: [PATCH] fix: childprocess chatId. --- packages/components/nodes/memory/ZepMemory/ZepMemory.ts | 2 +- packages/server/src/ChildProcess.ts | 4 +--- packages/server/src/Interface.ts | 1 + packages/server/src/index.ts | 7 +++++++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/components/nodes/memory/ZepMemory/ZepMemory.ts b/packages/components/nodes/memory/ZepMemory/ZepMemory.ts index cf1d8e58e..1fb6d9ff6 100644 --- a/packages/components/nodes/memory/ZepMemory/ZepMemory.ts +++ b/packages/components/nodes/memory/ZepMemory/ZepMemory.ts @@ -39,7 +39,7 @@ class ZepMemory_Memory implements INode { label: 'Session Id', name: 'sessionId', type: 'string', - placeholder: 'if empty, chatId will be used automatically', + description: 'if empty, chatId will be used automatically', default: '', additionalParams: true }, diff --git a/packages/server/src/ChildProcess.ts b/packages/server/src/ChildProcess.ts index 07b52909a..08847a521 100644 --- a/packages/server/src/ChildProcess.ts +++ b/packages/server/src/ChildProcess.ts @@ -1,6 +1,5 @@ import { IChildProcessMessage, IReactFlowNode, IReactFlowObject, IRunChatflowMessageValue, INodeData } from './Interface' import { buildLangchain, constructGraphs, getEndingNode, getStartingNodes, resolveVariables } from './utils' -import { getChatId } from './index' export class ChildProcess { /** @@ -24,7 +23,7 @@ export class ChildProcess { await sendToParentProcess('start', '_') // Create a Queue and add our initial node in it - const { endingNodeData, chatflow, incomingInput, componentNodes } = messageValue + const { endingNodeData, chatflow, chatId, incomingInput, componentNodes } = messageValue let nodeToExecuteData: INodeData let addToChatFlowPool: any = {} @@ -77,7 +76,6 @@ export class ChildProcess { const { startingNodeIds, depthQueue } = getStartingNodes(nonDirectedGraph, endingNodeId) /*** BFS to traverse from Starting Nodes to Ending Node ***/ - const chatId = await getChatId(chatflow.id) const reactFlowNodes = await buildLangchain( startingNodeIds, nodes, diff --git a/packages/server/src/Interface.ts b/packages/server/src/Interface.ts index b6876df3f..2c1fe406c 100644 --- a/packages/server/src/Interface.ts +++ b/packages/server/src/Interface.ts @@ -143,6 +143,7 @@ export interface IDatabaseExport { export interface IRunChatflowMessageValue { chatflow: IChatFlow + chatId: string incomingInput: IncomingInput componentNodes: IComponentNodes endingNodeData?: INodeData diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 78be231aa..9379a9221 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -441,9 +441,11 @@ export class App { if (!fs.existsSync(childpath)) childpath = 'ChildProcess.ts' const childProcess = fork(childpath, [], { signal }) + const chatId = await getChatId(chatflow.id) const value = { chatflow, + chatId, incomingInput, componentNodes: cloneDeep(this.nodesPool.componentNodes), endingNodeData @@ -665,6 +667,11 @@ export class App { } } +/** + * Get first chat message id + * @param {string} chatflowid + * @returns {string} + */ export async function getChatId(chatflowid: string) { // first chatmessage id as the unique chat id const firstChatMessage = await getDataSource()