mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-22 09:01:09 +03:00
add clearSessionMemory fix
This commit is contained in:
@@ -72,7 +72,11 @@ class DynamoDb_Memory implements INode {
|
||||
|
||||
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
|
||||
const dynamodbMemory = await initalizeDynamoDB(nodeData, options)
|
||||
const sessionId = nodeData.inputs?.sessionId as string
|
||||
const chatId = options?.chatId as string
|
||||
options.logger.info(`Clearing DynamoDb memory session ${sessionId ? sessionId : chatId}`)
|
||||
await dynamodbMemory.clear()
|
||||
options.logger.info(`Successfully cleared DynamoDb memory session ${sessionId ? sessionId : chatId}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,11 @@ class MotorMemory_Memory implements INode {
|
||||
|
||||
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
|
||||
const motorhead = await initalizeMotorhead(nodeData, options)
|
||||
const sessionId = nodeData.inputs?.sessionId as string
|
||||
const chatId = options?.chatId as string
|
||||
options.logger.info(`Clearing Motorhead memory session ${sessionId ? sessionId : chatId}`)
|
||||
await motorhead.clear()
|
||||
options.logger.info(`Successfully cleared Motorhead memory session ${sessionId ? sessionId : chatId}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,11 @@ class RedisBackedChatMemory_Memory implements INode {
|
||||
|
||||
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
|
||||
const redis = initalizeRedis(nodeData, options)
|
||||
redis.clear()
|
||||
const sessionId = nodeData.inputs?.sessionId as string
|
||||
const chatId = options?.chatId as string
|
||||
options.logger.info(`Clearing Redis memory session ${sessionId ? sessionId : chatId}`)
|
||||
await redis.clear()
|
||||
options.logger.info(`Successfully cleared Redis memory session ${sessionId ? sessionId : chatId}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,11 @@ class ZepMemory_Memory implements INode {
|
||||
|
||||
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
|
||||
const zep = await initalizeZep(nodeData, options)
|
||||
const sessionId = nodeData.inputs?.sessionId as string
|
||||
const chatId = options?.chatId as string
|
||||
options.logger.info(`Clearing Zep memory session ${sessionId ? sessionId : chatId}`)
|
||||
await zep.clear()
|
||||
options.logger.info(`Successfully cleared Zep memory session ${sessionId ? sessionId : chatId}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -405,7 +405,7 @@ export class App {
|
||||
const nodes = parsedFlowData.nodes
|
||||
let chatId = await getChatId(chatflow.id)
|
||||
if (!chatId) chatId = chatflow.id
|
||||
clearSessionMemory(nodes, this.nodesPool.componentNodes, chatId, req.query.sessionId as string)
|
||||
clearSessionMemory(nodes, this.nodesPool.componentNodes, chatId, this.AppDataSource, req.query.sessionId as string)
|
||||
const results = await this.AppDataSource.getRepository(ChatMessage).delete({ chatflowid: req.params.id })
|
||||
return res.json(results)
|
||||
})
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
IComponentCredentials,
|
||||
ICredentialReqBody
|
||||
} from '../Interface'
|
||||
import { cloneDeep, get, omit, merge } from 'lodash'
|
||||
import { cloneDeep, get, omit, merge, isEqual } from 'lodash'
|
||||
import { ICommonObject, getInputVariables, IDatabaseEntity, handleEscapeCharacters } from 'flowise-components'
|
||||
import { scryptSync, randomBytes, timingSafeEqual } from 'crypto'
|
||||
import { lib, PBKDF2, AES, enc } from 'crypto-js'
|
||||
@@ -182,7 +182,7 @@ export const getEndingNode = (nodeDependencies: INodeDependencies, graph: INodeD
|
||||
|
||||
/**
|
||||
* Build langchain from start to end
|
||||
* @param {string} startingNodeId
|
||||
* @param {string[]} startingNodeIds
|
||||
* @param {IReactFlowNode[]} reactFlowNodes
|
||||
* @param {INodeDirectedGraph} graph
|
||||
* @param {IDepthQueue} depthQueue
|
||||
@@ -286,12 +286,14 @@ export const buildLangchain = async (
|
||||
* @param {IReactFlowNode[]} reactFlowNodes
|
||||
* @param {IComponentNodes} componentNodes
|
||||
* @param {string} chatId
|
||||
* @param {DataSource} appDataSource
|
||||
* @param {string} sessionId
|
||||
*/
|
||||
export const clearSessionMemory = async (
|
||||
reactFlowNodes: IReactFlowNode[],
|
||||
componentNodes: IComponentNodes,
|
||||
chatId: string,
|
||||
appDataSource: DataSource,
|
||||
sessionId?: string
|
||||
) => {
|
||||
for (const node of reactFlowNodes) {
|
||||
@@ -300,7 +302,8 @@ export const clearSessionMemory = async (
|
||||
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 })
|
||||
if (newNodeInstance.clearSessionMemory)
|
||||
await newNodeInstance?.clearSessionMemory(node.data, { chatId, appDataSource, databaseEntities, logger })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -495,7 +498,7 @@ export const isSameOverrideConfig = (
|
||||
Object.keys(existingOverrideConfig).length &&
|
||||
newOverrideConfig &&
|
||||
Object.keys(newOverrideConfig).length &&
|
||||
JSON.stringify(existingOverrideConfig) === JSON.stringify(newOverrideConfig)
|
||||
isEqual(existingOverrideConfig, newOverrideConfig)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
@@ -660,8 +663,18 @@ export const mapMimeTypeToInputField = (mimeType: string) => {
|
||||
return 'jsonFile'
|
||||
case 'text/csv':
|
||||
return 'csvFile'
|
||||
case 'application/json-lines':
|
||||
case 'application/jsonl':
|
||||
case 'text/jsonl':
|
||||
return 'jsonlinesFile'
|
||||
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
|
||||
return 'docxFile'
|
||||
case 'application/vnd.yaml':
|
||||
case 'application/x-yaml':
|
||||
case 'text/vnd.yaml':
|
||||
case 'text/x-yaml':
|
||||
case 'text/yaml':
|
||||
return 'yamlFile'
|
||||
default:
|
||||
return ''
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user