Revert "perf: <tool_use> display (#5489)"

This reverts commit 0782b24790.
This commit is contained in:
kangfenmao 2025-05-07 21:08:16 +08:00
parent 5fe1d077e3
commit 06a590328c
2 changed files with 8 additions and 3 deletions

View File

@ -30,6 +30,8 @@ interface Props {
role: Message['role'] role: Message['role']
} }
const toolUseRegex = /<tool_use>([\s\S]*?)<\/tool_use>/g
const MainTextBlock: React.FC<Props> = ({ block, citationBlockId, role, mentions = [] }) => { const MainTextBlock: React.FC<Props> = ({ block, citationBlockId, role, mentions = [] }) => {
// Use the passed citationBlockId directly in the selector // Use the passed citationBlockId directly in the selector
const { renderInputMessageAsMarkdown } = useSettings() const { renderInputMessageAsMarkdown } = useSettings()
@ -66,6 +68,10 @@ const MainTextBlock: React.FC<Props> = ({ block, citationBlockId, role, mentions
return content return content
}, [block.content, block.citationReferences, citationBlockId, formattedCitations]) }, [block.content, block.citationReferences, citationBlockId, formattedCitations])
const ignoreToolUse = useMemo(() => {
return processedContent.replace(toolUseRegex, '')
}, [processedContent])
return ( return (
<> <>
{/* Render mentions associated with the message */} {/* Render mentions associated with the message */}
@ -79,7 +85,7 @@ const MainTextBlock: React.FC<Props> = ({ block, citationBlockId, role, mentions
{role === 'user' && !renderInputMessageAsMarkdown ? ( {role === 'user' && !renderInputMessageAsMarkdown ? (
<p style={{ marginBottom: 5, whiteSpace: 'pre-wrap' }}>{block.content}</p> <p style={{ marginBottom: 5, whiteSpace: 'pre-wrap' }}>{block.content}</p>
) : ( ) : (
<Markdown block={{ ...block, content: processedContent }} /> <Markdown block={{ ...block, content: ignoreToolUse }} />
)} )}
</> </>
) )

View File

@ -56,8 +56,7 @@ export function createStreamProcessor(callbacks: StreamProcessorCallbacks = {})
callbacks.onTextChunk(data.text) callbacks.onTextChunk(data.text)
} }
if (data.type === ChunkType.TEXT_COMPLETE && callbacks.onTextComplete) { if (data.type === ChunkType.TEXT_COMPLETE && callbacks.onTextComplete) {
// 消除工具使用对信息流的影响 callbacks.onTextComplete(data.text)
callbacks.onTextComplete(data.text.replace(/<tool_use>([\s\S]*?)<\/tool_use>/g, ''))
} }
if (data.type === ChunkType.THINKING_DELTA && callbacks.onThinkingChunk) { if (data.type === ChunkType.THINKING_DELTA && callbacks.onThinkingChunk) {
callbacks.onThinkingChunk(data.text, data.thinking_millsec) callbacks.onThinkingChunk(data.text, data.thinking_millsec)