perf: <tool_use> display (#5489)

This commit is contained in:
karl 2025-04-29 16:39:19 +08:00 committed by GitHub
parent 760c402bc7
commit 44ee736a10
2 changed files with 3 additions and 8 deletions

View File

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

View File

@ -56,7 +56,8 @@ export function createStreamProcessor(callbacks: StreamProcessorCallbacks = {})
callbacks.onTextChunk(data.text)
}
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) {
callbacks.onThinkingChunk(data.text, data.thinking_millsec)