fix: Clean think tags from reasoning content before display
- Add cleaning logic to remove <think> and </think> tags from reasoning - Trim whitespace after tag removal for clean display - Add debug logging to show before/after cleaning - The middleware extracts reasoning but includes the original tags This ensures the reasoning blocks show clean thinking content without the XML tags that were being captured along with the reasoning text.
This commit is contained in:
parent
33c914e19b
commit
68ecdebbc0
1 changed files with 12 additions and 2 deletions
|
|
@ -323,14 +323,24 @@ export const useStreamResponse = ({
|
|||
// Add reasoning to the final message if we collected any
|
||||
if (reasoning && assistantMessageCreated) {
|
||||
debugLog(`[useStreamResponse] Adding collected reasoning:`, reasoning.substring(0, 100))
|
||||
|
||||
// Clean the reasoning content by removing think tags
|
||||
let cleanedReasoning = reasoning
|
||||
// Remove opening and closing think tags
|
||||
cleanedReasoning = cleanedReasoning.replace(/<think>/g, '').replace(/<\/think>/g, '')
|
||||
// Trim any leading/trailing whitespace
|
||||
cleanedReasoning = cleanedReasoning.trim()
|
||||
|
||||
debugLog(`[useStreamResponse] Cleaned reasoning:`, cleanedReasoning.substring(0, 100))
|
||||
|
||||
setConversations((prev) => {
|
||||
const updated = [...prev]
|
||||
const conv = updated.find((c) => c.id === conversationId)
|
||||
if (conv && assistantMessageIndex >= 0) {
|
||||
const assistantMessage = conv.messages[assistantMessageIndex]
|
||||
if (assistantMessage && hasContent(assistantMessage) && assistantMessage.role === 'assistant') {
|
||||
assistantMessage.reasoning = reasoning
|
||||
debugLog(`[useStreamResponse] Added reasoning to assistant message at index ${assistantMessageIndex}`)
|
||||
assistantMessage.reasoning = cleanedReasoning
|
||||
debugLog(`[useStreamResponse] Added cleaned reasoning to assistant message at index ${assistantMessageIndex}`)
|
||||
}
|
||||
}
|
||||
return updated
|
||||
|
|
|
|||
Loading…
Reference in a new issue