mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-27 05:00:29 +03:00
code cleanup
This commit is contained in:
@@ -298,14 +298,14 @@ export const buildLangchain = async (
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear memory
|
||||
* Clear all session memories on the canvas
|
||||
* @param {IReactFlowNode[]} reactFlowNodes
|
||||
* @param {IComponentNodes} componentNodes
|
||||
* @param {string} chatId
|
||||
* @param {DataSource} appDataSource
|
||||
* @param {string} sessionId
|
||||
*/
|
||||
export const clearSessionMemory = async (
|
||||
export const clearAllSessionMemory = async (
|
||||
reactFlowNodes: IReactFlowNode[],
|
||||
componentNodes: IComponentNodes,
|
||||
chatId: string,
|
||||
@@ -317,9 +317,46 @@ export const clearSessionMemory = async (
|
||||
const nodeInstanceFilePath = componentNodes[node.data.name].filePath as string
|
||||
const nodeModule = await import(nodeInstanceFilePath)
|
||||
const newNodeInstance = new nodeModule.nodeClass()
|
||||
|
||||
if (sessionId && node.data.inputs) node.data.inputs.sessionId = sessionId
|
||||
if (newNodeInstance.clearSessionMemory)
|
||||
|
||||
if (newNodeInstance.clearSessionMemory) {
|
||||
await newNodeInstance?.clearSessionMemory(node.data, { chatId, appDataSource, databaseEntities, logger })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear specific session memory from View Message Dialog UI
|
||||
* @param {IReactFlowNode[]} reactFlowNodes
|
||||
* @param {IComponentNodes} componentNodes
|
||||
* @param {string} chatId
|
||||
* @param {DataSource} appDataSource
|
||||
* @param {string} sessionId
|
||||
* @param {string} memoryType
|
||||
*/
|
||||
export const clearSessionMemoryFromViewMessageDialog = async (
|
||||
reactFlowNodes: IReactFlowNode[],
|
||||
componentNodes: IComponentNodes,
|
||||
chatId: string,
|
||||
appDataSource: DataSource,
|
||||
sessionId?: string,
|
||||
memoryType?: string
|
||||
) => {
|
||||
if (!sessionId) return
|
||||
for (const node of reactFlowNodes) {
|
||||
if (node.data.category !== 'Memory') continue
|
||||
if (node.data.label !== memoryType) continue
|
||||
const nodeInstanceFilePath = componentNodes[node.data.name].filePath as string
|
||||
const nodeModule = await import(nodeInstanceFilePath)
|
||||
const newNodeInstance = new nodeModule.nodeClass()
|
||||
|
||||
if (sessionId && node.data.inputs) node.data.inputs.sessionId = sessionId
|
||||
|
||||
if (newNodeInstance.clearSessionMemory) {
|
||||
await newNodeInstance?.clearSessionMemory(node.data, { chatId, appDataSource, databaseEntities, logger })
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -933,5 +970,5 @@ export const checkMemorySessionId = (instance: any, chatId: string): string => {
|
||||
instance.memory.sessionId = chatId
|
||||
instance.memory.chatHistory.sessionId = chatId
|
||||
}
|
||||
return instance.memory.sessionId
|
||||
return instance.memory ? instance.memory.sessionId ?? instance.memory.chatHistory.sessionId : undefined
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user