Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(web): show completed label for think block after streaming ends (#17149)

euvred757303fa4bf
diff --git a/web/src/components/markdown-content/index.tsx b/web/src/components/markdown-content/index.tsx
index 7f3e4b21a2..f6378bfea0 100644
--- a/web/src/components/markdown-content/index.tsx
+++ b/web/src/components/markdown-content/index.tsx
@@ -75,12 +75,15 @@ const MarkdownContent = ({
text = t('chat.searching');
}
const nextText = replaceTextByOldReg(text);
+ const thinkSummary = loading
+ ? `${t('chat.thinking')}...`
+ : t('chat.thought');
return pipe(
- replaceThinkToSection,
+ (value: string) => replaceThinkToSection(value, thinkSummary),
replaceRetrievingToSection,
preprocessLaTeX,
)(nextText);
- }, [content, t]);
+ }, [content, loading, t]);
useEffect(() => {
const docAggs = reference?.doc_aggs;
diff --git a/web/src/components/next-markdown-content/index.tsx b/web/src/components/next-markdown-content/index.tsx
index c30656912a..b56b584f4b 100644
--- a/web/src/components/next-markdown-content/index.tsx
+++ b/web/src/components/next-markdown-content/index.tsx
@@ -181,12 +181,15 @@ function MarkdownContent({
text = t('chat.searching');
}
const nextText = replaceTextByOldReg(text);
+ const thinkSummary = loading
+ ? `${t('chat.thinking')}...`
+ : t('chat.thought');
return pipe(
- replaceThinkToSection,
+ (value: string) => replaceThinkToSection(value, thinkSummary),
replaceRetrievingToSection,
preprocessLaTeX,
)(nextText);
- }, [content, t]);
+ }, [content, loading, t]);
useEffect(() => {
const docAggs = reference?.doc_aggs;
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index 21debc71cc..6b54ef8546 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -1120,6 +1120,7 @@ This auto-tagging feature enhances retrieval by adding another layer of domain-s
maxTokensInvalidMessage: 'Please enter a valid number for Max tokens.',
maxTokensMinMessage: 'Max tokens cannot be less than 0.',
thinking: 'Thinking',
+ thought: 'Thought',
thinkingDefault: 'System default',
thinkingEnabled: 'Enabled',
thinkingDisabled: 'Disabled',
diff --git a/web/src/utils/chat.ts b/web/src/utils/chat.ts
index 923a4a9e3e..5b5bfd2cae 100644
--- a/web/src/utils/chat.ts
+++ b/web/src/utils/chat.ts
@@ -78,10 +78,16 @@ export const preprocessLaTeX = (content: string) => {
return inlineProcessedContent;
};
-export function replaceThinkToSection(text: string = '') {
+export function replaceThinkToSection(
+ text: string = '',
+ summary: string = 'Thinking...',
+) {
const pattern = /<think>([\s\S]*?)<\/think>/g;
- const result = text.replace(pattern, '<details class="think"><summary>Thinking...</summary>$1</details>');
+ const result = text.replace(
+ pattern,
+ `<details class="think"><summary>${summary}</summary>$1</details>`,
+ );
return result;
}
@@ -89,7 +95,10 @@ export function replaceThinkToSection(text: string = '') {
export function replaceRetrievingToSection(text: string = '') {
const pattern = /<retrieving>([\s\S]*?)<\/retrieving>/g;
- const result = text.replace(pattern, '<details class="retrieving"><summary>Retrieving...</summary>$1</details>');
+ const result = text.replace(
+ pattern,
+ '<details class="retrieving"><summary>Retrieving...</summary>$1</details>',
+ );
return result;
}