Feature/Full File Uploads & Message Delete API (#3314)

* add functionality for full file uploads, add remove messages from view dialog and API

* add attachments swagger

* update question to include uploadedFilesContent

* make config dialog modal lg size
This commit is contained in:
Henry Heng
2024-10-23 11:00:46 +01:00
committed by GitHub
parent 116d02d0bc
commit 53e504c32f
31 changed files with 1012 additions and 193 deletions
+44 -12
View File
@@ -63,7 +63,8 @@ export const buildAgentGraph = async (
isInternal: boolean,
baseURL?: string,
sseStreamer?: IServerSideEventStreamer,
shouldStreamResponse?: boolean
shouldStreamResponse?: boolean,
uploadedFilesContent?: string
): Promise<any> => {
try {
const appServer = getRunningExpressApp()
@@ -129,7 +130,8 @@ export const buildAgentGraph = async (
cachePool: appServer.cachePool,
isUpsert: false,
uploads: incomingInput.uploads,
baseURL
baseURL,
uploadedFilesContent
})
const options = {
@@ -188,7 +190,8 @@ export const buildAgentGraph = async (
chatHistory,
incomingInput?.overrideConfig,
sessionId || chatId,
seqAgentNodes.some((node) => node.data.inputs?.summarization)
seqAgentNodes.some((node) => node.data.inputs?.summarization),
uploadedFilesContent
)
} else {
isSequential = true
@@ -204,7 +207,8 @@ export const buildAgentGraph = async (
chatHistory,
incomingInput?.overrideConfig,
sessionId || chatId,
incomingInput.action
incomingInput.action,
uploadedFilesContent
)
}
@@ -348,7 +352,6 @@ export const buildAgentGraph = async (
if (isSequential && !finalResult && agentReasoning.length) {
const lastMessages = agentReasoning[agentReasoning.length - 1].messages
const lastAgentReasoningMessage = lastMessages[lastMessages.length - 1]
// If last message is an AI Message with tool calls, that means the last node was interrupted
if (lastMessageRaw.tool_calls && lastMessageRaw.tool_calls.length > 0) {
// The last node that got interrupted
@@ -456,6 +459,7 @@ export const buildAgentGraph = async (
* @param {ICommonObject} overrideConfig
* @param {string} threadId
* @param {boolean} summarization
* @param {string} uploadedFilesContent,
*/
const compileMultiAgentsGraph = async (
chatflow: IChatFlow,
@@ -470,7 +474,8 @@ const compileMultiAgentsGraph = async (
chatHistory: IMessage[] = [],
overrideConfig?: ICommonObject,
threadId?: string,
summarization?: boolean
summarization?: boolean,
uploadedFilesContent?: string
) => {
const appServer = getRunningExpressApp()
const channels: ITeamState = {
@@ -502,7 +507,15 @@ const compileMultiAgentsGraph = async (
let flowNodeData = cloneDeep(workerNode.data)
if (overrideConfig) flowNodeData = replaceInputsWithConfig(flowNodeData, overrideConfig)
flowNodeData = await resolveVariables(appServer.AppDataSource, flowNodeData, reactflowNodes, question, chatHistory, overrideConfig)
flowNodeData = await resolveVariables(
appServer.AppDataSource,
flowNodeData,
reactflowNodes,
question,
chatHistory,
overrideConfig,
uploadedFilesContent
)
try {
const workerResult: IMultiAgentNode = await newNodeInstance.init(flowNodeData, question, options)
@@ -533,7 +546,15 @@ const compileMultiAgentsGraph = async (
let flowNodeData = cloneDeep(supervisorNode.data)
if (overrideConfig) flowNodeData = replaceInputsWithConfig(flowNodeData, overrideConfig)
flowNodeData = await resolveVariables(appServer.AppDataSource, flowNodeData, reactflowNodes, question, chatHistory, overrideConfig)
flowNodeData = await resolveVariables(
appServer.AppDataSource,
flowNodeData,
reactflowNodes,
question,
chatHistory,
overrideConfig,
uploadedFilesContent
)
if (flowNodeData.inputs) flowNodeData.inputs.workerNodes = supervisorWorkers[supervisor]
@@ -603,9 +624,10 @@ const compileMultiAgentsGraph = async (
}
// Return stream result as we should only have 1 supervisor
const finalQuestion = uploadedFilesContent ? `${uploadedFilesContent}\n\n${question}` : question
return await graph.stream(
{
messages: [...prependMessages, new HumanMessage({ content: question })]
messages: [...prependMessages, new HumanMessage({ content: finalQuestion })]
},
{ recursionLimit: supervisorResult?.recursionLimit ?? 100, callbacks: [loggerHandler, ...callbacks], configurable: config }
)
@@ -641,7 +663,8 @@ const compileSeqAgentsGraph = async (
chatHistory: IMessage[] = [],
overrideConfig?: ICommonObject,
threadId?: string,
action?: IAction
action?: IAction,
uploadedFilesContent?: string
) => {
const appServer = getRunningExpressApp()
@@ -693,7 +716,15 @@ const compileSeqAgentsGraph = async (
flowNodeData = cloneDeep(node.data)
if (overrideConfig) flowNodeData = replaceInputsWithConfig(flowNodeData, overrideConfig)
flowNodeData = await resolveVariables(appServer.AppDataSource, flowNodeData, reactflowNodes, question, chatHistory, overrideConfig)
flowNodeData = await resolveVariables(
appServer.AppDataSource,
flowNodeData,
reactflowNodes,
question,
chatHistory,
overrideConfig,
uploadedFilesContent
)
const seqAgentNode: ISeqAgentNode = await newNodeInstance.init(flowNodeData, question, options)
return seqAgentNode
@@ -997,8 +1028,9 @@ const compileSeqAgentsGraph = async (
}
}
const finalQuestion = uploadedFilesContent ? `${uploadedFilesContent}\n\n${question}` : question
let humanMsg: { messages: HumanMessage[] | ToolMessage[] } | null = {
messages: [...prependMessages, new HumanMessage({ content: question })]
messages: [...prependMessages, new HumanMessage({ content: finalQuestion })]
}
if (action && action.mapping && question === action.mapping.approve) {