mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-23 21:00:32 +03:00
add conversational retrieval agent
This commit is contained in:
@@ -2,6 +2,7 @@ import path from 'path'
|
||||
import { IChildProcessMessage, IReactFlowNode, IReactFlowObject, IRunChatflowMessageValue, INodeData } from './Interface'
|
||||
import {
|
||||
buildLangchain,
|
||||
checkMemorySessionId,
|
||||
constructGraphs,
|
||||
getEndingNode,
|
||||
getStartingNodes,
|
||||
@@ -137,7 +138,10 @@ export class ChildProcess {
|
||||
const nodeInstance = new nodeModule.nodeClass()
|
||||
|
||||
logger.debug(`[server] [mode:child]: Running ${nodeToExecuteData.label} (${nodeToExecuteData.id})`)
|
||||
const result = await nodeInstance.run(nodeToExecuteData, incomingInput.question, { chatHistory: incomingInput.history })
|
||||
|
||||
if (nodeToExecuteData.instance) checkMemorySessionId(nodeToExecuteData.instance, chatId)
|
||||
|
||||
const result = await nodeInstance.run(nodeToExecuteData, incomingInput.question, { chatHistory: incomingInput.history, chatId })
|
||||
logger.debug(`[server] [mode:child]: Finished running ${nodeToExecuteData.label} (${nodeToExecuteData.id})`)
|
||||
|
||||
await sendToParentProcess('finish', { result, addToChatFlowPool })
|
||||
|
||||
@@ -45,7 +45,8 @@ import {
|
||||
decryptCredentialData,
|
||||
clearSessionMemory,
|
||||
replaceInputsWithConfig,
|
||||
getEncryptionKey
|
||||
getEncryptionKey,
|
||||
checkMemorySessionId
|
||||
} from './utils'
|
||||
import { cloneDeep, omit } from 'lodash'
|
||||
import { getDataSource } from './DataSource'
|
||||
@@ -661,7 +662,11 @@ export class App {
|
||||
templates.push(template)
|
||||
})
|
||||
const FlowiseDocsQnA = templates.find((tmp) => tmp.name === 'Flowise Docs QnA')
|
||||
if (FlowiseDocsQnA) templates.unshift(FlowiseDocsQnA)
|
||||
const FlowiseDocsQnAIndex = templates.findIndex((tmp) => tmp.name === 'Flowise Docs QnA')
|
||||
if (FlowiseDocsQnA && FlowiseDocsQnAIndex > 0) {
|
||||
templates.splice(FlowiseDocsQnAIndex, 1)
|
||||
templates.unshift(FlowiseDocsQnA)
|
||||
}
|
||||
return res.json(templates)
|
||||
})
|
||||
|
||||
@@ -988,14 +993,24 @@ export class App {
|
||||
|
||||
isStreamValid = isStreamValid && !isVectorStoreFaiss(nodeToExecuteData)
|
||||
logger.debug(`[server]: Running ${nodeToExecuteData.label} (${nodeToExecuteData.id})`)
|
||||
|
||||
if (nodeToExecuteData.instance) checkMemorySessionId(nodeToExecuteData.instance, chatId)
|
||||
|
||||
const result = isStreamValid
|
||||
? await nodeInstance.run(nodeToExecuteData, incomingInput.question, {
|
||||
chatHistory: incomingInput.history,
|
||||
socketIO,
|
||||
socketIOClientId: incomingInput.socketIOClientId,
|
||||
logger
|
||||
logger,
|
||||
appDataSource: this.AppDataSource,
|
||||
databaseEntities
|
||||
})
|
||||
: await nodeInstance.run(nodeToExecuteData, incomingInput.question, {
|
||||
chatHistory: incomingInput.history,
|
||||
logger,
|
||||
appDataSource: this.AppDataSource,
|
||||
databaseEntities
|
||||
})
|
||||
: await nodeInstance.run(nodeToExecuteData, incomingInput.question, { chatHistory: incomingInput.history, logger })
|
||||
|
||||
logger.debug(`[server]: Finished running ${nodeToExecuteData.label} (${nodeToExecuteData.id})`)
|
||||
return res.json(result)
|
||||
|
||||
@@ -787,7 +787,7 @@ export const isFlowValidForStream = (reactFlowNodes: IReactFlowNode[], endingNod
|
||||
isValidChainOrAgent = !blacklistChains.includes(endingNodeData.name)
|
||||
} else if (endingNodeData.category === 'Agents') {
|
||||
// Agent that are available to stream
|
||||
const whitelistAgents = ['openAIFunctionAgent', 'csvAgent', 'airtableAgent']
|
||||
const whitelistAgents = ['openAIFunctionAgent', 'csvAgent', 'airtableAgent', 'conversationalRetrievalAgent']
|
||||
isValidChainOrAgent = whitelistAgents.includes(endingNodeData.name)
|
||||
}
|
||||
|
||||
@@ -908,3 +908,15 @@ export const redactCredentialWithPasswordType = (
|
||||
}
|
||||
return plainDataObj
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace sessionId with new chatId
|
||||
* Ex: after clear chat history, use the new chatId as sessionId
|
||||
* @param {any} instance
|
||||
* @param {string} chatId
|
||||
*/
|
||||
export const checkMemorySessionId = (instance: any, chatId: string) => {
|
||||
if (instance.memory && instance.memory.isSessionIdUsingChatMessageId && chatId) {
|
||||
instance.memory.sessionId = chatId
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user