mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +03:00
Feature/Add prepend messages to memory (#2410)
add prepend messages to memory
This commit is contained in:
@@ -145,6 +145,9 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
|
||||
const memoryType = memoryNode?.data.label
|
||||
let sessionId = getMemorySessionId(memoryNode, incomingInput, chatId, isInternal)
|
||||
|
||||
// Get prepend messages
|
||||
const prependMessages = incomingInput.history
|
||||
|
||||
/* Reuse the flow without having to rebuild (to avoid duplicated upsert, recomputation, reinitialization of memory) when all these conditions met:
|
||||
* - Node Data already exists in pool
|
||||
* - Still in sync (i.e the flow has not been modified since)
|
||||
@@ -226,7 +229,8 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
|
||||
appServer.nodesPool.componentNodes,
|
||||
appServer.AppDataSource,
|
||||
databaseEntities,
|
||||
logger
|
||||
logger,
|
||||
prependMessages
|
||||
)
|
||||
}
|
||||
|
||||
@@ -301,7 +305,8 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
|
||||
analytic: chatflow.analytic,
|
||||
uploads: incomingInput.uploads,
|
||||
socketIO,
|
||||
socketIOClientId: incomingInput.socketIOClientId
|
||||
socketIOClientId: incomingInput.socketIOClientId,
|
||||
prependMessages
|
||||
})
|
||||
: await nodeInstance.run(nodeToExecuteData, incomingInput.question, {
|
||||
chatId,
|
||||
@@ -310,7 +315,8 @@ export const utilBuildChatflow = async (req: Request, socketIO?: Server, isInter
|
||||
appDataSource: appServer.AppDataSource,
|
||||
databaseEntities,
|
||||
analytic: chatflow.analytic,
|
||||
uploads: incomingInput.uploads
|
||||
uploads: incomingInput.uploads,
|
||||
prependMessages
|
||||
})
|
||||
result = typeof result === 'string' ? { text: result } : result
|
||||
|
||||
|
||||
@@ -1306,7 +1306,8 @@ export const getSessionChatHistory = async (
|
||||
componentNodes: IComponentNodes,
|
||||
appDataSource: DataSource,
|
||||
databaseEntities: IDatabaseEntity,
|
||||
logger: any
|
||||
logger: any,
|
||||
prependMessages?: IMessage[]
|
||||
): Promise<IMessage[]> => {
|
||||
const nodeInstanceFilePath = componentNodes[memoryNode.data.name].filePath as string
|
||||
const nodeModule = await import(nodeInstanceFilePath)
|
||||
@@ -1324,7 +1325,7 @@ export const getSessionChatHistory = async (
|
||||
logger
|
||||
})
|
||||
|
||||
return (await initializedInstance.getChatMessages(sessionId)) as IMessage[]
|
||||
return (await initializedInstance.getChatMessages(sessionId, undefined, prependMessages)) as IMessage[]
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user