fix: properly handle thinking mode switching in qwenThinkingMiddleware
Fix issue #11612 where Ollama couldn't disable Qwen3 thinking mode. The middleware now properly removes existing /think or /no_think suffixes before adding the correct suffix based on current reasoning_effort setting. Previously, messages with existing suffixes were skipped, causing thinking mode to persist even when user switched back to non-thinking mode. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -23,8 +23,10 @@ export function qwenThinkingMiddleware(enableThinking: boolean): LanguageModelMi
|
||||
// Process content array
|
||||
if (Array.isArray(message.content)) {
|
||||
for (const part of message.content) {
|
||||
if (part.type === 'text' && !part.text.endsWith('/think') && !part.text.endsWith('/no_think')) {
|
||||
part.text += suffix
|
||||
if (part.type === 'text') {
|
||||
// Remove any existing thinking suffixes first, then add the correct one
|
||||
const cleanText = part.text.replace(/\s*\/think\s*$/, '').replace(/\s*\/no_think\s*$/, '')
|
||||
part.text = cleanText + suffix
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user