From a8880911e713cf177672a1e28438b930c60a7bce Mon Sep 17 00:00:00 2001 From: xuzuodong Date: Sun, 22 Sep 2024 14:40:33 +0800 Subject: [PATCH] fix: send message error when chatting with opening statement --- .../configuration/debug/debug-with-single-model/index.tsx | 8 +++++++- .../base/chat/chat-with-history/chat-wrapper.tsx | 8 +++++++- .../base/chat/embedded-chatbot/chat-wrapper.tsx | 8 +++++++- .../workflow/panel/debug-and-preview/chat-wrapper.tsx | 8 +++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/web/app/components/app/configuration/debug/debug-with-single-model/index.tsx b/web/app/components/app/configuration/debug/debug-with-single-model/index.tsx index 80e7c98a8f0c9..5faef46d988e0 100644 --- a/web/app/components/app/configuration/debug/debug-with-single-model/index.tsx +++ b/web/app/components/app/configuration/debug/debug-with-single-model/index.tsx @@ -83,11 +83,17 @@ const DebugWithSingleModel = forwardRef { }, []) const doSend: OnSend = useCallback((message, files, last_answer) => { + const lastAnswer = chatListRef.current.at(-1) + const data: any = { query: message, inputs: currentConversationId ? currentConversationItem?.inputs : newConversationInputs, conversation_id: currentConversationId, - parent_message_id: last_answer?.id || chatListRef.current.at(-1)?.id || null, + parent_message_id: last_answer?.id || (lastAnswer + ? lastAnswer.isOpeningStatement + ? null + : lastAnswer.id + : null), } if (appConfig?.file_upload?.image.enabled && files?.length) diff --git a/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx b/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx index 8cb546fd52a0e..ed2f24274dcd7 100644 --- a/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx +++ b/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx @@ -69,11 +69,17 @@ const ChatWrapper = () => { }, []) const doSend: OnSend = useCallback((message, files, last_answer) => { + const lastAnswer = chatListRef.current.at(-1) + const data: any = { query: message, inputs: currentConversationId ? currentConversationItem?.inputs : newConversationInputs, conversation_id: currentConversationId, - parent_message_id: last_answer?.id || chatListRef.current.at(-1)?.id || null, + parent_message_id: last_answer?.id || (lastAnswer + ? lastAnswer.isOpeningStatement + ? null + : lastAnswer.id + : null), } if (appConfig?.file_upload?.image.enabled && files?.length) diff --git a/web/app/components/workflow/panel/debug-and-preview/chat-wrapper.tsx b/web/app/components/workflow/panel/debug-and-preview/chat-wrapper.tsx index 107a5dc698f74..86519af60357d 100644 --- a/web/app/components/workflow/panel/debug-and-preview/chat-wrapper.tsx +++ b/web/app/components/workflow/panel/debug-and-preview/chat-wrapper.tsx @@ -76,13 +76,19 @@ const ChatWrapper = forwardRef(({ showConv ) const doSend = useCallback((query, files, last_answer) => { + const lastAnswer = chatListRef.current.at(-1) + handleSend( { query, files, inputs: workflowStore.getState().inputs, conversation_id: conversationId, - parent_message_id: last_answer?.id || chatListRef.current.at(-1)?.id || null, + parent_message_id: last_answer?.id || (lastAnswer + ? lastAnswer.isOpeningStatement + ? null + : lastAnswer.id + : null), }, { onGetSuggestedQuestions: (messageId, getAbortController) => fetchSuggestedQuestions(appDetail!.id, messageId, getAbortController),