From bf7e713eecd98093a60a5634384fd29281a0ed9c Mon Sep 17 00:00:00 2001 From: SuYao Date: Sun, 6 Jul 2025 14:40:55 +0800 Subject: [PATCH] fix: qwen3 empty think block (#7873) --- .../feat/ThinkingTagExtractionMiddleware.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/renderer/src/aiCore/middleware/feat/ThinkingTagExtractionMiddleware.ts b/src/renderer/src/aiCore/middleware/feat/ThinkingTagExtractionMiddleware.ts index fe2d51d8de..2fcefc1b34 100644 --- a/src/renderer/src/aiCore/middleware/feat/ThinkingTagExtractionMiddleware.ts +++ b/src/renderer/src/aiCore/middleware/feat/ThinkingTagExtractionMiddleware.ts @@ -69,7 +69,7 @@ export const ThinkingTagExtractionMiddleware: CompletionsMiddleware = const extractionResults = tagExtractor.processText(textChunk.text) for (const extractionResult of extractionResults) { - if (extractionResult.complete && extractionResult.tagContentExtracted) { + if (extractionResult.complete && extractionResult.tagContentExtracted?.trim()) { // 生成 THINKING_COMPLETE 事件 const thinkingCompleteChunk: ThinkingCompleteChunk = { type: ChunkType.THINKING_COMPLETE, @@ -89,12 +89,14 @@ export const ThinkingTagExtractionMiddleware: CompletionsMiddleware = thinkingStartTime = Date.now() } - const thinkingDeltaChunk: ThinkingDeltaChunk = { - type: ChunkType.THINKING_DELTA, - text: extractionResult.content, - thinking_millsec: thinkingStartTime > 0 ? Date.now() - thinkingStartTime : 0 + if (extractionResult.content?.trim()) { + const thinkingDeltaChunk: ThinkingDeltaChunk = { + type: ChunkType.THINKING_DELTA, + text: extractionResult.content, + thinking_millsec: thinkingStartTime > 0 ? Date.now() - thinkingStartTime : 0 + } + controller.enqueue(thinkingDeltaChunk) } - controller.enqueue(thinkingDeltaChunk) } else { // 发送清理后的文本内容 const cleanTextChunk: TextDeltaChunk = {