From 9d7ab0400de1d3f6d2995cc325c24970c88724f2 Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Tue, 2 Apr 2024 12:01:12 +0800 Subject: [PATCH] chat error --- .../base/chat/chat/answer/basic-content.tsx | 2 +- web/app/components/base/chat/types.ts | 1 + .../workflow/panel/debug-and-preview/hooks.ts | 18 ++++++++++++++++-- web/service/base.ts | 6 +++--- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/web/app/components/base/chat/chat/answer/basic-content.tsx b/web/app/components/base/chat/chat/answer/basic-content.tsx index d041b9d631..d438610f68 100644 --- a/web/app/components/base/chat/chat/answer/basic-content.tsx +++ b/web/app/components/base/chat/chat/answer/basic-content.tsx @@ -17,7 +17,7 @@ const BasicContent: FC = ({ if (annotation?.logAnnotation) return - return + return } export default memo(BasicContent) diff --git a/web/app/components/base/chat/types.ts b/web/app/components/base/chat/types.ts index e10793cf52..8edc2574dc 100644 --- a/web/app/components/base/chat/types.ts +++ b/web/app/components/base/chat/types.ts @@ -57,6 +57,7 @@ export type WorkflowProcess = { } export type ChatItem = IChatItem & { + isError?: boolean workflowProcess?: WorkflowProcess } diff --git a/web/app/components/workflow/panel/debug-and-preview/hooks.ts b/web/app/components/workflow/panel/debug-and-preview/hooks.ts index 52082600a3..7273c4a22f 100644 --- a/web/app/components/workflow/panel/debug-and-preview/hooks.ts +++ b/web/app/components/workflow/panel/debug-and-preview/hooks.ts @@ -225,11 +225,25 @@ export const useChat = ( questionItem, }) }, - async onCompleted(hasError?: boolean) { + async onCompleted(hasError?: boolean, errorMessage?: string) { handleResponding(false) - if (hasError) + if (hasError) { + if (errorMessage) { + responseItem.content = errorMessage + responseItem.isError = true + const newListWithAnswer = produce( + chatListRef.current.filter(item => item.id !== responseItem.id && item.id !== placeholderAnswerId), + (draft) => { + if (!draft.find(item => item.id === questionId)) + draft.push({ ...questionItem }) + + draft.push({ ...responseItem }) + }) + handleUpdateChatList(newListWithAnswer) + } return + } if (config?.suggested_questions_after_answer?.enabled && !hasStopResponded.current && onGetSuggestedQuestions) { const { data }: any = await onGetSuggestedQuestions( diff --git a/web/service/base.ts b/web/service/base.ts index 1ce66985f3..48baeaeb05 100644 --- a/web/service/base.ts +++ b/web/service/base.ts @@ -44,7 +44,7 @@ export type IOnFile = (file: VisionFile) => void export type IOnMessageEnd = (messageEnd: MessageEnd) => void export type IOnMessageReplace = (messageReplace: MessageReplace) => void export type IOnAnnotationReply = (messageReplace: AnnotationReply) => void -export type IOnCompleted = (hasError?: boolean) => void +export type IOnCompleted = (hasError?: boolean, errorMessage?: string) => void export type IOnError = (msg: string, code?: string) => void export type IOnWorkflowStarted = (workflowStarted: WorkflowStartedResponse) => void @@ -159,7 +159,7 @@ const handleStream = ( errorCode: bufferObj?.code, }) hasError = true - onCompleted?.(true) + onCompleted?.(true, bufferObj?.message) return } if (bufferObj.event === 'message' || bufferObj.event === 'agent_message') { @@ -212,7 +212,7 @@ const handleStream = ( errorMessage: `${e}`, }) hasError = true - onCompleted?.(true) + onCompleted?.(true, e as string) return } if (!hasError)