mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 15:00:57 +03:00
clear session memory
This commit is contained in:
@@ -65,37 +65,47 @@ class DynamoDb_Memory implements INode {
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
const tableName = nodeData.inputs?.tableName as string
|
||||
const partitionKey = nodeData.inputs?.partitionKey as string
|
||||
const sessionId = nodeData.inputs?.sessionId as string
|
||||
const region = nodeData.inputs?.region as string
|
||||
const accessKey = nodeData.inputs?.accessKey as string
|
||||
const secretAccessKey = nodeData.inputs?.secretAccessKey as string
|
||||
const memoryKey = nodeData.inputs?.memoryKey as string
|
||||
return initalizeDynamoDB(nodeData, options)
|
||||
}
|
||||
|
||||
const chatId = options.chatId
|
||||
|
||||
const dynamoDb = new DynamoDBChatMessageHistory({
|
||||
tableName,
|
||||
partitionKey,
|
||||
sessionId: sessionId ? sessionId : chatId,
|
||||
config: {
|
||||
region,
|
||||
credentials: {
|
||||
accessKeyId: accessKey,
|
||||
secretAccessKey
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const memory = new BufferMemory({
|
||||
memoryKey,
|
||||
chatHistory: dynamoDb,
|
||||
returnMessages: true
|
||||
})
|
||||
return memory
|
||||
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
|
||||
const dynamodbMemory = initalizeDynamoDB(nodeData, options)
|
||||
dynamodbMemory.clear()
|
||||
}
|
||||
}
|
||||
|
||||
const initalizeDynamoDB = (nodeData: INodeData, options: ICommonObject): BufferMemory => {
|
||||
const tableName = nodeData.inputs?.tableName as string
|
||||
const partitionKey = nodeData.inputs?.partitionKey as string
|
||||
const sessionId = nodeData.inputs?.sessionId as string
|
||||
const region = nodeData.inputs?.region as string
|
||||
const accessKey = nodeData.inputs?.accessKey as string
|
||||
const secretAccessKey = nodeData.inputs?.secretAccessKey as string
|
||||
const memoryKey = nodeData.inputs?.memoryKey as string
|
||||
|
||||
const chatId = options.chatId
|
||||
|
||||
const dynamoDb = new DynamoDBChatMessageHistory({
|
||||
tableName,
|
||||
partitionKey,
|
||||
sessionId: sessionId ? sessionId : chatId,
|
||||
config: {
|
||||
region,
|
||||
credentials: {
|
||||
accessKeyId: accessKey,
|
||||
secretAccessKey
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const memory = new BufferMemory({
|
||||
memoryKey,
|
||||
chatHistory: dynamoDb,
|
||||
returnMessages: true
|
||||
})
|
||||
return memory
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: DynamoDb_Memory }
|
||||
|
||||
@@ -64,35 +64,44 @@ class MotorMemory_Memory implements INode {
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
const memoryKey = nodeData.inputs?.memoryKey as string
|
||||
const baseURL = nodeData.inputs?.baseURL as string
|
||||
const sessionId = nodeData.inputs?.sessionId as string
|
||||
const apiKey = nodeData.inputs?.apiKey as string
|
||||
const clientId = nodeData.inputs?.clientId as string
|
||||
return initalizeMotorhead(nodeData, options)
|
||||
}
|
||||
|
||||
const chatId = options?.chatId as string
|
||||
|
||||
let obj: MotorheadMemoryInput = {
|
||||
returnMessages: true,
|
||||
sessionId: sessionId ? sessionId : chatId,
|
||||
memoryKey
|
||||
}
|
||||
|
||||
if (baseURL) {
|
||||
obj = {
|
||||
...obj,
|
||||
url: baseURL
|
||||
}
|
||||
} else {
|
||||
obj = {
|
||||
...obj,
|
||||
apiKey,
|
||||
clientId
|
||||
}
|
||||
}
|
||||
|
||||
return new MotorheadMemory(obj)
|
||||
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
|
||||
const motorhead = initalizeMotorhead(nodeData, options)
|
||||
motorhead.clear()
|
||||
}
|
||||
}
|
||||
|
||||
const initalizeMotorhead = (nodeData: INodeData, options: ICommonObject): MotorheadMemory => {
|
||||
const memoryKey = nodeData.inputs?.memoryKey as string
|
||||
const baseURL = nodeData.inputs?.baseURL as string
|
||||
const sessionId = nodeData.inputs?.sessionId as string
|
||||
const apiKey = nodeData.inputs?.apiKey as string
|
||||
const clientId = nodeData.inputs?.clientId as string
|
||||
|
||||
const chatId = options?.chatId as string
|
||||
|
||||
let obj: MotorheadMemoryInput = {
|
||||
returnMessages: true,
|
||||
sessionId: sessionId ? sessionId : chatId,
|
||||
memoryKey
|
||||
}
|
||||
|
||||
if (baseURL) {
|
||||
obj = {
|
||||
...obj,
|
||||
url: baseURL
|
||||
}
|
||||
} else {
|
||||
obj = {
|
||||
...obj,
|
||||
apiKey,
|
||||
clientId
|
||||
}
|
||||
}
|
||||
|
||||
return new MotorheadMemory(obj)
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: MotorMemory_Memory }
|
||||
|
||||
@@ -56,31 +56,40 @@ class RedisBackedChatMemory_Memory implements INode {
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
const baseURL = nodeData.inputs?.baseURL as string
|
||||
const sessionId = nodeData.inputs?.sessionId as string
|
||||
const sessionTTL = nodeData.inputs?.sessionTTL as number
|
||||
const memoryKey = nodeData.inputs?.memoryKey as string
|
||||
return initalizeRedis(nodeData, options)
|
||||
}
|
||||
|
||||
const chatId = options?.chatId as string
|
||||
|
||||
const redisClient = createClient({ url: baseURL })
|
||||
let obj: RedisChatMessageHistoryInput = {
|
||||
sessionId: sessionId ? sessionId : chatId,
|
||||
client: redisClient
|
||||
}
|
||||
|
||||
if (sessionTTL) {
|
||||
obj = {
|
||||
...obj,
|
||||
sessionTTL
|
||||
}
|
||||
}
|
||||
|
||||
let redisChatMessageHistory = new RedisChatMessageHistory(obj)
|
||||
let redis = new BufferMemory({ memoryKey, chatHistory: redisChatMessageHistory, returnMessages: true })
|
||||
|
||||
return redis
|
||||
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
|
||||
const redis = initalizeRedis(nodeData, options)
|
||||
redis.clear()
|
||||
}
|
||||
}
|
||||
|
||||
const initalizeRedis = (nodeData: INodeData, options: ICommonObject): BufferMemory => {
|
||||
const baseURL = nodeData.inputs?.baseURL as string
|
||||
const sessionId = nodeData.inputs?.sessionId as string
|
||||
const sessionTTL = nodeData.inputs?.sessionTTL as number
|
||||
const memoryKey = nodeData.inputs?.memoryKey as string
|
||||
|
||||
const chatId = options?.chatId as string
|
||||
|
||||
const redisClient = createClient({ url: baseURL })
|
||||
let obj: RedisChatMessageHistoryInput = {
|
||||
sessionId: sessionId ? sessionId : chatId,
|
||||
client: redisClient
|
||||
}
|
||||
|
||||
if (sessionTTL) {
|
||||
obj = {
|
||||
...obj,
|
||||
sessionTTL
|
||||
}
|
||||
}
|
||||
|
||||
let redisChatMessageHistory = new RedisChatMessageHistory(obj)
|
||||
let redis = new BufferMemory({ memoryKey, chatHistory: redisChatMessageHistory, returnMessages: true })
|
||||
|
||||
return redis
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: RedisBackedChatMemory_Memory }
|
||||
|
||||
@@ -104,31 +104,11 @@ class ZepMemory_Memory implements INode {
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
const baseURL = nodeData.inputs?.baseURL 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 = nodeData.inputs?.sessionId as string
|
||||
const apiKey = nodeData.inputs?.apiKey as string
|
||||
const k = nodeData.inputs?.k as string
|
||||
|
||||
const chatId = options?.chatId as string
|
||||
|
||||
const obj: ZepMemoryInput = {
|
||||
baseURL,
|
||||
sessionId: sessionId ? sessionId : chatId,
|
||||
aiPrefix,
|
||||
humanPrefix,
|
||||
returnMessages: true,
|
||||
memoryKey,
|
||||
inputKey
|
||||
}
|
||||
if (apiKey) obj.apiKey = apiKey
|
||||
|
||||
let zep = new ZepMemory(obj)
|
||||
let zep = initalizeZep(nodeData, options)
|
||||
|
||||
// hack to support summary
|
||||
let tmpFunc = zep.loadMemoryVariables
|
||||
@@ -153,6 +133,37 @@ class ZepMemory_Memory implements INode {
|
||||
}
|
||||
return zep
|
||||
}
|
||||
|
||||
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
|
||||
const zep = initalizeZep(nodeData, options)
|
||||
zep.clear()
|
||||
}
|
||||
}
|
||||
|
||||
const initalizeZep = (nodeData: INodeData, options: ICommonObject) => {
|
||||
const baseURL = nodeData.inputs?.baseURL 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 sessionId = nodeData.inputs?.sessionId as string
|
||||
const apiKey = nodeData.inputs?.apiKey as string
|
||||
|
||||
const chatId = options?.chatId as string
|
||||
|
||||
const obj: ZepMemoryInput = {
|
||||
baseURL,
|
||||
sessionId: sessionId ? sessionId : chatId,
|
||||
aiPrefix,
|
||||
humanPrefix,
|
||||
returnMessages: true,
|
||||
memoryKey,
|
||||
inputKey
|
||||
}
|
||||
if (apiKey) obj.apiKey = apiKey
|
||||
|
||||
return new ZepMemory(obj)
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: ZepMemory_Memory }
|
||||
|
||||
Reference in New Issue
Block a user