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
@@ -0,0 +1,20 @@
import { Request } from 'express'
import { StatusCodes } from 'http-status-codes'
import { createFileAttachment } from '../../utils/createAttachment'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { getErrorMessage } from '../../errors/utils'
const createAttachment = async (req: Request) => {
try {
return await createFileAttachment(req)
} catch (error) {
throw new InternalFlowiseError(
StatusCodes.INTERNAL_SERVER_ERROR,
`Error: attachmentService.createAttachment - ${getErrorMessage(error)}`
)
}
}
export default {
createAttachment
}
@@ -1,6 +1,6 @@
import { DeleteResult, FindOptionsWhere } from 'typeorm'
import { StatusCodes } from 'http-status-codes'
import { ChatMessageRatingType, chatType, IChatMessage } from '../../Interface'
import { ChatMessageRatingType, ChatType, IChatMessage } from '../../Interface'
import { utilGetChatMessage } from '../../utils/getChatMessage'
import { utilAddChatMessage } from '../../utils/addChatMesage'
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
@@ -27,7 +27,7 @@ const createChatMessage = async (chatMessage: Partial<IChatMessage>) => {
// Get all chatmessages from chatflowid
const getAllChatMessages = async (
chatflowId: string,
chatTypeFilter: chatType | undefined,
chatTypeFilter: ChatType | undefined,
sortOrder: string = 'ASC',
chatId?: string,
memoryType?: string,
@@ -64,7 +64,7 @@ const getAllChatMessages = async (
// Get internal chatmessages from chatflowid
const getAllInternalChatMessages = async (
chatflowId: string,
chatTypeFilter: chatType | undefined,
chatTypeFilter: ChatType | undefined,
sortOrder: string = 'ASC',
chatId?: string,
memoryType?: string,
@@ -128,6 +128,35 @@ const removeAllChatMessages = async (
}
}
const removeChatMessagesByMessageIds = async (
chatflowid: string,
chatIdMap: Map<string, ChatMessage[]>,
messageIds: string[]
): Promise<DeleteResult> => {
try {
const appServer = getRunningExpressApp()
for (const [composite_key] of chatIdMap) {
const [chatId] = composite_key.split('_')
// Remove all related feedback records
const feedbackDeleteOptions: FindOptionsWhere<ChatMessageFeedback> = { chatId }
await appServer.AppDataSource.getRepository(ChatMessageFeedback).delete(feedbackDeleteOptions)
// Delete all uploads corresponding to this chatflow/chatId
await removeFilesFromStorage(chatflowid, chatId)
}
const dbResponse = await appServer.AppDataSource.getRepository(ChatMessage).delete(messageIds)
return dbResponse
} catch (error) {
throw new InternalFlowiseError(
StatusCodes.INTERNAL_SERVER_ERROR,
`Error: chatMessagesService.removeAllChatMessages - ${getErrorMessage(error)}`
)
}
}
const abortChatMessage = async (chatId: string, chatflowid: string) => {
try {
const appServer = getRunningExpressApp()
@@ -155,5 +184,6 @@ export default {
getAllChatMessages,
getAllInternalChatMessages,
removeAllChatMessages,
removeChatMessagesByMessageIds,
abortChatMessage
}
@@ -9,7 +9,7 @@ import {
removeSpecificFileFromStorage
} from 'flowise-components'
import {
chatType,
ChatType,
DocumentStoreStatus,
IDocumentStoreFileChunkPagedResponse,
IDocumentStoreLoader,
@@ -995,7 +995,7 @@ const _insertIntoVectorStoreWorkerThread = async (data: ICommonObject) => {
data: {
version: await getAppVersion(),
chatlowId: chatflowid,
type: chatType.INTERNAL,
type: ChatType.INTERNAL,
flowGraph: omit(indexResult['result'], ['totalKeys', 'addedDocs'])
}
})
+2 -2
View File
@@ -1,5 +1,5 @@
import { StatusCodes } from 'http-status-codes'
import { ChatMessageRatingType, chatType } from '../../Interface'
import { ChatMessageRatingType, ChatType } from '../../Interface'
import { ChatMessage } from '../../database/entities/ChatMessage'
import { utilGetChatMessage } from '../../utils/getChatMessage'
import { ChatMessageFeedback } from '../../database/entities/ChatMessageFeedback'
@@ -9,7 +9,7 @@ import { getErrorMessage } from '../../errors/utils'
// get stats for showing in chatflow
const getChatflowStats = async (
chatflowid: string,
chatTypeFilter: chatType | undefined,
chatTypeFilter: ChatType | undefined,
startDate?: string,
endDate?: string,
messageId?: string,