Merge pull request #284 from wangerzi/feature/SupportZepMemoryAndAutoSummary

feature/SupportZepMemoryAndAutoSummary
This commit is contained in:
Henry Heng
2023-06-12 22:33:46 +01:00
committed by GitHub
8 changed files with 181 additions and 6 deletions
+2 -1
View File
@@ -23,7 +23,7 @@ export class ChildProcess {
await sendToParentProcess('start', '_')
// Create a Queue and add our initial node in it
const { endingNodeData, chatflow, incomingInput, componentNodes } = messageValue
const { endingNodeData, chatflow, chatId, incomingInput, componentNodes } = messageValue
let nodeToExecuteData: INodeData
let addToChatFlowPool: any = {}
@@ -83,6 +83,7 @@ export class ChildProcess {
depthQueue,
componentNodes,
incomingInput.question,
chatId,
incomingInput?.overrideConfig
)
+1
View File
@@ -143,6 +143,7 @@ export interface IDatabaseExport {
export interface IRunChatflowMessageValue {
chatflow: IChatFlow
chatId: string
incomingInput: IncomingInput
componentNodes: IComponentNodes
endingNodeData?: INodeData
+25 -3
View File
@@ -432,7 +432,7 @@ export class App {
* @param {IncomingInput} incomingInput
* @param {INodeData} endingNodeData
*/
async startChildProcess(chatflow: ChatFlow, incomingInput: IncomingInput, endingNodeData?: INodeData) {
async startChildProcess(chatflow: ChatFlow, chatId: string, incomingInput: IncomingInput, endingNodeData?: INodeData) {
try {
const controller = new AbortController()
const { signal } = controller
@@ -444,6 +444,7 @@ export class App {
const value = {
chatflow,
chatId,
incomingInput,
componentNodes: cloneDeep(this.nodesPool.componentNodes),
endingNodeData
@@ -506,6 +507,9 @@ export class App {
})
if (!chatflow) return res.status(404).send(`Chatflow ${chatflowid} not found`)
const chatId = await getChatId(chatflow.id)
if (!chatId) return res.status(500).send(`Chatflow ${chatflowid} first message not found`)
if (!isInternal) {
await this.validateKey(req, res, chatflow)
}
@@ -557,7 +561,7 @@ export class App {
if (isRebuildNeeded()) {
nodeToExecuteData = this.chatflowPool.activeChatflows[chatflowid].endingNodeData
try {
const result = await this.startChildProcess(chatflow, incomingInput, nodeToExecuteData)
const result = await this.startChildProcess(chatflow, chatId, incomingInput, nodeToExecuteData)
return res.json(result)
} catch (error) {
@@ -565,7 +569,7 @@ export class App {
}
} else {
try {
const result = await this.startChildProcess(chatflow, incomingInput)
const result = await this.startChildProcess(chatflow, chatId, incomingInput)
return res.json(result)
} catch (error) {
return res.status(500).send(error)
@@ -618,6 +622,7 @@ export class App {
depthQueue,
this.nodesPool.componentNodes,
incomingInput.question,
chatId,
incomingInput?.overrideConfig
)
@@ -661,6 +666,23 @@ export class App {
}
}
/**
* Get first chat message id
* @param {string} chatflowid
* @returns {string}
*/
export async function getChatId(chatflowid: string) {
// first chatmessage id as the unique chat id
const firstChatMessage = await getDataSource()
.getRepository(ChatMessage)
.createQueryBuilder('cm')
.select('cm.id')
.where('chatflowid = :chatflowid', { chatflowid })
.orderBy('cm.createdDate', 'ASC')
.getOne()
return firstChatMessage ? firstChatMessage.id : ''
}
let serverApp: App | undefined
export async function start(): Promise<void> {
+2 -1
View File
@@ -182,6 +182,7 @@ export const buildLangchain = async (
depthQueue: IDepthQueue,
componentNodes: IComponentNodes,
question: string,
chatId: string,
overrideConfig?: ICommonObject
) => {
const flowNodes = cloneDeep(reactFlowNodes)
@@ -214,7 +215,7 @@ export const buildLangchain = async (
if (overrideConfig) flowNodeData = replaceInputsWithConfig(flowNodeData, overrideConfig)
const reactFlowNodeData: INodeData = resolveVariables(flowNodeData, flowNodes, question)
flowNodes[nodeIndex].data.instance = await newNodeInstance.init(reactFlowNodeData, question)
flowNodes[nodeIndex].data.instance = await newNodeInstance.init(reactFlowNodeData, question, { chatId })
} catch (e: any) {
console.error(e)
throw new Error(e)