mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 21:00:58 +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> {
|
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
|
||||||
const dynamodbMemory = await initalizeDynamoDB(nodeData, options)
|
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()
|
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> {
|
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
|
||||||
const motorhead = await initalizeMotorhead(nodeData, options)
|
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()
|
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> {
|
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
|
||||||
const redis = initalizeRedis(nodeData, options)
|
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> {
|
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
|
||||||
const zep = await initalizeZep(nodeData, options)
|
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()
|
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
|
const nodes = parsedFlowData.nodes
|
||||||
let chatId = await getChatId(chatflow.id)
|
let chatId = await getChatId(chatflow.id)
|
||||||
if (!chatId) chatId = 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 })
|
const results = await this.AppDataSource.getRepository(ChatMessage).delete({ chatflowid: req.params.id })
|
||||||
return res.json(results)
|
return res.json(results)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
IComponentCredentials,
|
IComponentCredentials,
|
||||||
ICredentialReqBody
|
ICredentialReqBody
|
||||||
} from '../Interface'
|
} 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 { ICommonObject, getInputVariables, IDatabaseEntity, handleEscapeCharacters } from 'flowise-components'
|
||||||
import { scryptSync, randomBytes, timingSafeEqual } from 'crypto'
|
import { scryptSync, randomBytes, timingSafeEqual } from 'crypto'
|
||||||
import { lib, PBKDF2, AES, enc } from 'crypto-js'
|
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
|
* Build langchain from start to end
|
||||||
* @param {string} startingNodeId
|
* @param {string[]} startingNodeIds
|
||||||
* @param {IReactFlowNode[]} reactFlowNodes
|
* @param {IReactFlowNode[]} reactFlowNodes
|
||||||
* @param {INodeDirectedGraph} graph
|
* @param {INodeDirectedGraph} graph
|
||||||
* @param {IDepthQueue} depthQueue
|
* @param {IDepthQueue} depthQueue
|
||||||
@@ -286,12 +286,14 @@ export const buildLangchain = async (
|
|||||||
* @param {IReactFlowNode[]} reactFlowNodes
|
* @param {IReactFlowNode[]} reactFlowNodes
|
||||||
* @param {IComponentNodes} componentNodes
|
* @param {IComponentNodes} componentNodes
|
||||||
* @param {string} chatId
|
* @param {string} chatId
|
||||||
|
* @param {DataSource} appDataSource
|
||||||
* @param {string} sessionId
|
* @param {string} sessionId
|
||||||
*/
|
*/
|
||||||
export const clearSessionMemory = async (
|
export const clearSessionMemory = async (
|
||||||
reactFlowNodes: IReactFlowNode[],
|
reactFlowNodes: IReactFlowNode[],
|
||||||
componentNodes: IComponentNodes,
|
componentNodes: IComponentNodes,
|
||||||
chatId: string,
|
chatId: string,
|
||||||
|
appDataSource: DataSource,
|
||||||
sessionId?: string
|
sessionId?: string
|
||||||
) => {
|
) => {
|
||||||
for (const node of reactFlowNodes) {
|
for (const node of reactFlowNodes) {
|
||||||
@@ -300,7 +302,8 @@ export const clearSessionMemory = async (
|
|||||||
const nodeModule = await import(nodeInstanceFilePath)
|
const nodeModule = await import(nodeInstanceFilePath)
|
||||||
const newNodeInstance = new nodeModule.nodeClass()
|
const newNodeInstance = new nodeModule.nodeClass()
|
||||||
if (sessionId && node.data.inputs) node.data.inputs.sessionId = sessionId
|
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 &&
|
Object.keys(existingOverrideConfig).length &&
|
||||||
newOverrideConfig &&
|
newOverrideConfig &&
|
||||||
Object.keys(newOverrideConfig).length &&
|
Object.keys(newOverrideConfig).length &&
|
||||||
JSON.stringify(existingOverrideConfig) === JSON.stringify(newOverrideConfig)
|
isEqual(existingOverrideConfig, newOverrideConfig)
|
||||||
) {
|
) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -660,8 +663,18 @@ export const mapMimeTypeToInputField = (mimeType: string) => {
|
|||||||
return 'jsonFile'
|
return 'jsonFile'
|
||||||
case 'text/csv':
|
case 'text/csv':
|
||||||
return 'csvFile'
|
return 'csvFile'
|
||||||
|
case 'application/json-lines':
|
||||||
|
case 'application/jsonl':
|
||||||
|
case 'text/jsonl':
|
||||||
|
return 'jsonlinesFile'
|
||||||
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
|
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
|
||||||
return 'docxFile'
|
return 'docxFile'
|
||||||
|
case 'application/vnd.yaml':
|
||||||
|
case 'application/x-yaml':
|
||||||
|
case 'text/vnd.yaml':
|
||||||
|
case 'text/x-yaml':
|
||||||
|
case 'text/yaml':
|
||||||
|
return 'yamlFile'
|
||||||
default:
|
default:
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user