From 1ebf7409084851afff650da8b6db96e8fe01df54 Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Sun, 4 Feb 2024 18:08:53 +0800 Subject: [PATCH] fix: webapp stop chat & citation (#2376) --- .../components/app/chat/citation/popup.tsx | 24 ++++++++++--------- .../debug/debug-with-single-model/index.tsx | 6 +---- .../app/configuration/debug/hooks.tsx | 1 + .../chat/chat-with-history/chat-wrapper.tsx | 2 ++ .../base/chat/chat/answer/index.tsx | 2 +- web/app/components/base/chat/chat/hooks.ts | 8 ++----- web/app/components/base/chat/types.ts | 1 + 7 files changed, 21 insertions(+), 23 deletions(-) diff --git a/web/app/components/app/chat/citation/popup.tsx b/web/app/components/app/chat/citation/popup.tsx index be3034d374..d039d98e6b 100644 --- a/web/app/components/app/chat/citation/popup.tsx +++ b/web/app/components/app/chat/citation/popup.tsx @@ -32,7 +32,7 @@ const Popup: FC = ({ }) => { const { t } = useTranslation() const [open, setOpen] = useState(false) - const fileType = data.dataSourceType === 'upload_file' + const fileType = data.dataSourceType !== 'notion' ? (/\.([^.]*)$/g.exec(data.documentName)?.[1] || '') : 'notion' @@ -65,22 +65,24 @@ const Popup: FC = ({ data.sources.map((source, index) => (
- { - showHitInfo && ( -
-
- -
{source.segment_position}
-
+
+
+ +
+ {source.segment_position || index + 1} +
+
+ { + showHitInfo && ( {t('common.chat.citation.linkToDataset')} -
- ) - } + ) + } +
{source.content}
{ showHitInfo && ( 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 c235617eeb..6a8a416e81 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 @@ -54,11 +54,7 @@ const DebugWithSingleModel = forwardRef { supportAnnotation: true, appId, + supportCitationHitInfo: true, } return config diff --git a/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx b/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx index 1e58e37b64..a8a58b55f6 100644 --- a/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx +++ b/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx @@ -11,6 +11,7 @@ import ConfigPanel from './config-panel' import { fetchSuggestedQuestions, getUrl, + stopChatMessageResponding, } from '@/service/share' const ChatWrapper = () => { @@ -47,6 +48,7 @@ const ChatWrapper = () => { appConfig, undefined, appPrevChatList, + taskId => stopChatMessageResponding('', taskId, isInstalledApp, appId), ) useEffect(() => { diff --git a/web/app/components/base/chat/chat/answer/index.tsx b/web/app/components/base/chat/chat/answer/index.tsx index b86ecc105a..2c2b06c1e2 100644 --- a/web/app/components/base/chat/chat/answer/index.tsx +++ b/web/app/components/base/chat/chat/answer/index.tsx @@ -97,7 +97,7 @@ const Answer: FC = ({ { !!citation?.length && config?.retriever_resource?.enabled && !responsing && ( - + ) }
diff --git a/web/app/components/base/chat/chat/hooks.ts b/web/app/components/base/chat/chat/hooks.ts index 87cf0a9dc2..71e76f26ad 100644 --- a/web/app/components/base/chat/chat/hooks.ts +++ b/web/app/components/base/chat/chat/hooks.ts @@ -87,7 +87,6 @@ export const useChat = ( const chatListRef = useRef(prevChatList || []) const taskIdRef = useRef('') const [suggestedQuestions, setSuggestQuestions] = useState([]) - const abortControllerRef = useRef(null) const conversationMessagesAbortControllerRef = useRef(null) const suggestedQuestionsAbortControllerRef = useRef(null) const checkPromptVariables = useCheckPromptVariables() @@ -131,8 +130,6 @@ export const useChat = ( handleResponsing(false) if (stopChat && taskIdRef.current) stopChat(taskIdRef.current) - if (abortControllerRef.current) - abortControllerRef.current.abort() if (conversationMessagesAbortControllerRef.current) conversationMessagesAbortControllerRef.current.abort() if (suggestedQuestionsAbortControllerRef.current) @@ -192,6 +189,8 @@ export const useChat = ( }: SendCallback, ) => { setSuggestQuestions([]) + if (!data.query || !data.query.trim()) + return if (isResponsingRef.current) { notify({ type: 'info', message: t('appDebug.errorMessage.waitForResponse') }) return false @@ -257,9 +256,6 @@ export const useChat = ( }, { isPublicAPI, - getAbortController: (abortController) => { - abortControllerRef.current = abortController - }, onData: (message: string, isFirstMessage: boolean, { conversationId: newConversationId, messageId, taskId }: any) => { if (!isAgentMode) { responseItem.content = responseItem.content + message diff --git a/web/app/components/base/chat/types.ts b/web/app/components/base/chat/types.ts index 88cfb986e8..db88a6ddc5 100644 --- a/web/app/components/base/chat/types.ts +++ b/web/app/components/base/chat/types.ts @@ -45,6 +45,7 @@ export type ChatConfig = Omit & { supportAnnotation?: boolean appId?: string supportFeedback?: boolean + supportCitationHitInfo?: boolean } export type ChatItem = IChatItem