From aead48726e8b092430c74492ae3ab33116d03cb6 Mon Sep 17 00:00:00 2001 From: Jimmyy <43959617+Jimmy0769@users.noreply.github.com> Date: Wed, 16 Apr 2025 09:56:46 +0800 Subject: [PATCH] fix: cannot regenerate with image(#15060) (#16611) Co-authored-by: werido <359066432@qq.com> --- api/fields/conversation_fields.py | 1 + api/models/model.py | 2 +- web/app/components/base/chat/chat-with-history/hooks.tsx | 4 ++-- web/app/components/base/file-uploader/utils.ts | 2 +- web/types/workflow.ts | 1 + 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/api/fields/conversation_fields.py b/api/fields/conversation_fields.py index 80d1f0baf5..78e0794833 100644 --- a/api/fields/conversation_fields.py +++ b/api/fields/conversation_fields.py @@ -42,6 +42,7 @@ message_file_fields = { "size": fields.Integer, "transfer_method": fields.String, "belongs_to": fields.String(default="user"), + "upload_file_id": fields.String(default=None), } agent_thought_fields = { diff --git a/api/models/model.py b/api/models/model.py index dfc1322d92..a826d13e7d 100644 --- a/api/models/model.py +++ b/api/models/model.py @@ -1155,7 +1155,7 @@ class Message(db.Model): # type: ignore[name-defined] files.append(file) result = [ - {"belongs_to": message_file.belongs_to, **file.to_dict()} + {"belongs_to": message_file.belongs_to, "upload_file_id": message_file.upload_file_id, **file.to_dict()} for (file, message_file) in zip(files, message_files) ] diff --git a/web/app/components/base/chat/chat-with-history/hooks.tsx b/web/app/components/base/chat/chat-with-history/hooks.tsx index 0a4cbae964..9afaca2568 100644 --- a/web/app/components/base/chat/chat-with-history/hooks.tsx +++ b/web/app/components/base/chat/chat-with-history/hooks.tsx @@ -52,7 +52,7 @@ function getFormattedChatList(messages: any[]) { id: `question-${item.id}`, content: item.query, isAnswer: false, - message_files: getProcessedFilesFromResponse(questionFiles.map((item: any) => ({ ...item, related_id: item.id }))), + message_files: getProcessedFilesFromResponse(questionFiles.map((item: any) => ({ ...item, related_id: item.id, upload_file_id: item.upload_file_id }))), parentMessageId: item.parent_message_id || undefined, }) const answerFiles = item.message_files?.filter((file: any) => file.belongs_to === 'assistant') || [] @@ -63,7 +63,7 @@ function getFormattedChatList(messages: any[]) { feedback: item.feedback, isAnswer: true, citation: item.retriever_resources, - message_files: getProcessedFilesFromResponse(answerFiles.map((item: any) => ({ ...item, related_id: item.id }))), + message_files: getProcessedFilesFromResponse(answerFiles.map((item: any) => ({ ...item, related_id: item.id, upload_file_id: item.upload_file_id }))), parentMessageId: `question-${item.id}`, }) }) diff --git a/web/app/components/base/file-uploader/utils.ts b/web/app/components/base/file-uploader/utils.ts index e095d4aa93..e05c0b2087 100644 --- a/web/app/components/base/file-uploader/utils.ts +++ b/web/app/components/base/file-uploader/utils.ts @@ -134,7 +134,7 @@ export const getProcessedFilesFromResponse = (files: FileResponse[]) => { progress: 100, transferMethod: fileItem.transfer_method, supportFileType: fileItem.type, - uploadedId: fileItem.related_id, + uploadedId: fileItem.upload_file_id || fileItem.related_id, url: fileItem.url, } }) diff --git a/web/types/workflow.ts b/web/types/workflow.ts index 43af64e5ca..bd7334a261 100644 --- a/web/types/workflow.ts +++ b/web/types/workflow.ts @@ -197,6 +197,7 @@ export type FileResponse = { transfer_method: TransferMethod type: string url: string + upload_file_id: string } export type NodeFinishedResponse = {