diff --git a/packages/components/nodes/memory/ZepMemory/ZepMemory.ts b/packages/components/nodes/memory/ZepMemory/ZepMemory.ts index f833b4e3..95b83bbb 100644 --- a/packages/components/nodes/memory/ZepMemory/ZepMemory.ts +++ b/packages/components/nodes/memory/ZepMemory/ZepMemory.ts @@ -2,6 +2,7 @@ import { SystemChatMessage } from 'langchain/schema' import { INode, INodeData, INodeParams } from '../../../src/Interface' import { getBaseClasses } from '../../../src/utils' import { ZepMemory, ZepMemoryInput } from 'langchain/memory/zep' +import { ICommonObject } from '../../../src' class ZepMemory_Memory implements INode { label: string @@ -28,13 +29,6 @@ class ZepMemory_Memory implements INode { type: 'string', default: 'http://127.0.0.1:8000' }, - { - label: 'Session Id', - name: 'sessionId', - type: 'string', - placeholder: 'unique and manually change in every conversion!', - default: '' - }, { label: 'Auto Summary', name: 'autoSummary', @@ -86,15 +80,15 @@ class ZepMemory_Memory implements INode { ] } - async init(nodeData: INodeData): Promise { + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { const baseURL = nodeData.inputs?.baseURL as string - const sessionId = nodeData.inputs?.sessionId as string const aiPrefix = nodeData.inputs?.aiPrefix as string const humanPrefix = nodeData.inputs?.humanPrefix as string const memoryKey = nodeData.inputs?.memoryKey as string const inputKey = nodeData.inputs?.inputKey as string const autoSummaryTemplate = nodeData.inputs?.autoSummaryTemplate as string const autoSummary = nodeData.inputs?.autoSummary as boolean + const sessionId = options?.chatId as string const obj: ZepMemoryInput = { baseURL, diff --git a/packages/server/src/ChildProcess.ts b/packages/server/src/ChildProcess.ts index 483379d0..e5f95170 100644 --- a/packages/server/src/ChildProcess.ts +++ b/packages/server/src/ChildProcess.ts @@ -83,6 +83,7 @@ export class ChildProcess { depthQueue, componentNodes, incomingInput.question, + '', incomingInput?.overrideConfig ) diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 3a0c64cd..5e91a30a 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -506,6 +506,16 @@ export class App { }) if (!chatflow) return res.status(404).send(`Chatflow ${chatflowid} not found`) + // first chatmessage id as the unique chat id + const firstChatMessage = await this.AppDataSource.getRepository(ChatMessage) + .createQueryBuilder('cm') + .select('cm.id') + .where('chatflowid = :chatflowid', { chatflowid }) + .orderBy('cm.createdDate', 'ASC') + .getOne() + if (!firstChatMessage) return res.status(500).send(`Chatflow ${chatflowid} first message not found`) + const chatId = firstChatMessage.id + if (!isInternal) { await this.validateKey(req, res, chatflow) } @@ -618,6 +628,7 @@ export class App { depthQueue, this.nodesPool.componentNodes, incomingInput.question, + chatId, incomingInput?.overrideConfig ) diff --git a/packages/server/src/utils/index.ts b/packages/server/src/utils/index.ts index 18473c51..b993b958 100644 --- a/packages/server/src/utils/index.ts +++ b/packages/server/src/utils/index.ts @@ -182,6 +182,7 @@ export const buildLangchain = async ( depthQueue: IDepthQueue, componentNodes: IComponentNodes, question: string, + chatId: string, overrideConfig?: ICommonObject ) => { const flowNodes = cloneDeep(reactFlowNodes) @@ -214,7 +215,7 @@ export const buildLangchain = async ( if (overrideConfig) flowNodeData = replaceInputsWithConfig(flowNodeData, overrideConfig) const reactFlowNodeData: INodeData = resolveVariables(flowNodeData, flowNodes, question) - flowNodes[nodeIndex].data.instance = await newNodeInstance.init(reactFlowNodeData, question) + flowNodes[nodeIndex].data.instance = await newNodeInstance.init(reactFlowNodeData, question, { chatId }) } catch (e: any) { console.error(e) throw new Error(e) diff --git a/packages/ui/src/views/chatmessage/ChatMessage.js b/packages/ui/src/views/chatmessage/ChatMessage.js index 077419f1..2f5415d0 100644 --- a/packages/ui/src/views/chatmessage/ChatMessage.js +++ b/packages/ui/src/views/chatmessage/ChatMessage.js @@ -118,7 +118,8 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => { setLoading(true) setMessages((prevMessages) => [...prevMessages, { message: userInput, type: 'userMessage' }]) - addChatMessage(userInput, 'userMessage') + // waiting for first chatmessage uploaded, the first chatmessage id will be chatId for every components + await addChatMessage(userInput, 'userMessage') // Send user question and history to API try {