diff --git a/web/app/components/app/log/list.tsx b/web/app/components/app/log/list.tsx index 29e2bfde99..8937da68b6 100644 --- a/web/app/components/app/log/list.tsx +++ b/web/app/components/app/log/list.tsx @@ -96,11 +96,15 @@ const getFormattedChatList = (messages: ChatMessage[]) => { message_files: item.message_files?.filter((file: any) => file.belongs_to === 'assistant') || [], log: [ ...item.message, - { - role: 'assistant', - text: item.answer, - files: item.message_files?.filter((file: any) => file.belongs_to === 'assistant') || [], - }, + ...(item.message[item.message.length - 1].role !== 'assistant' + ? [ + { + role: 'assistant', + text: item.answer, + files: item.message_files?.filter((file: any) => file.belongs_to === 'assistant') || [], + }, + ] + : []), ], workflow_run_id: item.workflow_run_id, more: { diff --git a/web/app/components/app/text-generate/item/index.tsx b/web/app/components/app/text-generate/item/index.tsx index 50f05b8f2f..0db3c301c7 100644 --- a/web/app/components/app/text-generate/item/index.tsx +++ b/web/app/components/app/text-generate/item/index.tsx @@ -200,11 +200,15 @@ const GenerationItem: FC = ({ ...data, log: [ ...data.message, - { - role: 'assistant', - text: data.answer, - files: data.message_files?.filter((file: any) => file.belongs_to === 'assistant') || [], - }, + ...(data.message[data.message.length - 1].role !== 'assistant' + ? [ + { + role: 'assistant', + text: data.answer, + files: data.message_files?.filter((file: any) => file.belongs_to === 'assistant') || [], + }, + ] + : []), ], } setCurrentLogItem(logItem) diff --git a/web/app/components/base/chat/chat/hooks.ts b/web/app/components/base/chat/chat/hooks.ts index 6242105e85..8aeaf1463a 100644 --- a/web/app/components/base/chat/chat/hooks.ts +++ b/web/app/components/base/chat/chat/hooks.ts @@ -324,11 +324,15 @@ export const useChat = ( ...draft[index], log: [ ...newResponseItem.message, - { - role: 'assistant', - text: newResponseItem.answer, - files: newResponseItem.message_files?.filter((file: any) => file.belongs_to === 'assistant') || [], - }, + ...(newResponseItem.message[newResponseItem.message.length - 1].role !== 'assistant' + ? [ + { + role: 'assistant', + text: newResponseItem.answer, + files: newResponseItem.message_files?.filter((file: any) => file.belongs_to === 'assistant') || [], + }, + ] + : []), ], more: { time: dayjs.unix(newResponseItem.created_at).format('hh:mm A'),