From e78523034ac2ab3a6d4a08786a553ef2ca03576f Mon Sep 17 00:00:00 2001 From: "Apple\\Apple" Date: Mon, 2 Jun 2025 04:45:38 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(playground):=20el?= =?UTF-8?q?iminate=20code=20duplication=20in=20thinking=20content=20render?= =?UTF-8?q?ing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove duplicate thinking content rendering logic from MessageContent component - Import and utilize ThinkingContent component for consistent thinking display - Clean up unused icon imports (ChevronRight, ChevronUp, Brain) - Consolidate "思考中..." header text logic into single component - Reduce code duplication by ~70 lines while maintaining all functionality - Improve component separation of concerns and maintainability The MessageContent component now delegates thinking content rendering to the dedicated ThinkingContent component, eliminating the previously duplicated UI logic and state management for thinking processes. --- .../components/playground/MessageContent.js | 98 +++---------------- .../components/playground/ThinkingContent.js | 4 +- 2 files changed, 13 insertions(+), 89 deletions(-) diff --git a/web/src/components/playground/MessageContent.js b/web/src/components/playground/MessageContent.js index fd2f0a37..7a07aa0b 100644 --- a/web/src/components/playground/MessageContent.js +++ b/web/src/components/playground/MessageContent.js @@ -5,10 +5,8 @@ import { Button, } from '@douyinfe/semi-ui'; import MarkdownRenderer from '../common/markdown/MarkdownRenderer'; +import ThinkingContent from './ThinkingContent'; import { - ChevronRight, - ChevronUp, - Brain, Loader2, Check, X, @@ -127,7 +125,6 @@ const MessageContent = ({ currentDisplayableFinalContent = baseContentForDisplay.replace(/<\/?think>/g, '').trim(); } - const headerText = (isThinkingStatus && !message.isThinkingComplete) ? t('思考中...') : t('思考过程'); const finalExtractedThinkingContent = currentExtractedThinkingContent; const finalDisplayableFinalContent = currentDisplayableFinalContent; @@ -136,8 +133,8 @@ const MessageContent = ({ !finalExtractedThinkingContent && (!finalDisplayableFinalContent || finalDisplayableFinalContent.trim() === '')) { return ( -
-
+
+
@@ -146,7 +143,6 @@ const MessageContent = ({ return (
- {/* 为system角色添加特殊标识 */} {message.role === 'system' && (
@@ -160,86 +156,17 @@ const MessageContent = ({
)} - {/* 渲染推理内容 */} - {message.role === 'assistant' && finalExtractedThinkingContent && ( -
-
onToggleReasoningExpansion(message.id)} - > -
-
-
-
-
-
- -
-
- - {headerText} - - {thinkingSource && ( - - 来源: {thinkingSource} - - )} -
-
-
- {isThinkingStatus && !message.isThinkingComplete && ( -
- - - 思考中 - -
- )} - {(!isThinkingStatus || message.isThinkingComplete) && ( -
- {message.isReasoningExpanded ? - : - - } -
- )} -
-
-
- {message.isReasoningExpanded && ( -
-
-
- -
-
-
- )} -
-
+ {message.role === 'assistant' && ( + )} - {/* 渲染消息内容 */} {isEditing ? ( - /* 编辑模式 */