mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 14:59:27 +08:00
perf: <tool_use> display (#5489)
This commit is contained in:
parent
760c402bc7
commit
44ee736a10
@ -31,8 +31,6 @@ 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()
|
||||||
@ -69,10 +67,6 @@ 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 */}
|
||||||
@ -86,7 +80,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: ignoreToolUse }} />
|
<Markdown block={{ ...block, content: processedContent }} />
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -56,7 +56,8 @@ 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)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user