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
+34 -6
View File
@@ -48,6 +48,7 @@ import { InternalFlowiseError } from '../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
const QUESTION_VAR_PREFIX = 'question'
const FILE_ATTACHMENT_PREFIX = 'file_attachment'
const CHAT_HISTORY_VAR_PREFIX = 'chat_history'
const REDACTED_CREDENTIAL_VALUE = '_FLOWISE_BLANK_07167752-1a71-43b1-bf8f-4f32252165db'
@@ -438,6 +439,7 @@ type BuildFlowParams = {
stopNodeId?: string
uploads?: IFileUpload[]
baseURL?: string
uploadedFilesContent?: string
}
/**
@@ -452,6 +454,7 @@ export const buildFlow = async ({
depthQueue,
componentNodes,
question,
uploadedFilesContent,
chatHistory,
apiMessageId,
chatId,
@@ -516,7 +519,8 @@ export const buildFlow = async ({
flowNodes,
question,
chatHistory,
flowData
flowData,
uploadedFilesContent
)
if (isUpsert && stopNodeId && nodeId === stopNodeId) {
@@ -546,7 +550,8 @@ export const buildFlow = async ({
initializedNodes.add(nodeId)
} else {
logger.debug(`[server]: Initializing ${reactFlowNode.data.label} (${reactFlowNode.data.id})`)
let outputResult = await newNodeInstance.init(reactFlowNodeData, question, {
const finalQuestion = uploadedFilesContent ? `${uploadedFilesContent}\n\n${question}` : question
let outputResult = await newNodeInstance.init(reactFlowNodeData, finalQuestion, {
chatId,
sessionId,
chatflowid,
@@ -770,7 +775,8 @@ export const getVariableValue = async (
question: string,
chatHistory: IMessage[],
isAcceptVariable = false,
flowData?: ICommonObject
flowData?: ICommonObject,
uploadedFilesContent?: string
) => {
const isObject = typeof paramValue === 'object'
const initialValue = (isObject ? JSON.stringify(paramValue) : paramValue) ?? ''
@@ -803,6 +809,10 @@ export const getVariableValue = async (
variableDict[`{{${variableFullPath}}}`] = handleEscapeCharacters(question, false)
}
if (isAcceptVariable && variableFullPath === FILE_ATTACHMENT_PREFIX) {
variableDict[`{{${variableFullPath}}}`] = handleEscapeCharacters(uploadedFilesContent, false)
}
if (isAcceptVariable && variableFullPath === CHAT_HISTORY_VAR_PREFIX) {
variableDict[`{{${variableFullPath}}}`] = handleEscapeCharacters(convertChatHistoryToText(chatHistory), false)
}
@@ -916,7 +926,8 @@ export const resolveVariables = async (
reactFlowNodes: IReactFlowNode[],
question: string,
chatHistory: IMessage[],
flowData?: ICommonObject
flowData?: ICommonObject,
uploadedFilesContent?: string
): Promise<INodeData> => {
let flowNodeData = cloneDeep(reactFlowNodeData)
const types = 'inputs'
@@ -934,7 +945,8 @@ export const resolveVariables = async (
question,
chatHistory,
undefined,
flowData
flowData,
uploadedFilesContent
)
resolvedInstances.push(resolvedInstance)
}
@@ -948,7 +960,8 @@ export const resolveVariables = async (
question,
chatHistory,
isAcceptVariable,
flowData
flowData,
uploadedFilesContent
)
paramsObj[key] = resolvedInstance
}
@@ -1572,3 +1585,18 @@ export const convertToValidFilename = (word: string) => {
.replace(' ', '')
.toLowerCase()
}
export const setDateToStartOrEndOfDay = (dateTimeStr: string, setHours: 'start' | 'end') => {
const date = new Date(dateTimeStr)
if (isNaN(date.getTime())) {
return undefined
}
setHours === 'start' ? date.setHours(0, 0, 0, 0) : date.setHours(23, 59, 59, 999)
return date
}
export const aMonthAgo = () => {
const date = new Date()
date.setMonth(new Date().getMonth() - 1)
return date
}