Compare commits

...

1 Commits

Author SHA1 Message Date
suyao
163ae9c085 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>
2025-12-01 20:43:14 +08:00

View File

@@ -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
}
}
}