You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: enhance Qwen35ChatHandler with preserve_thinking and Qwen3.6 template fixes
- Add `preserve_thinking` parameter to optionally retain `<think>` reasoning
blocks across all historical conversational turns (defaults to False to save tokens).
- Improve template robustness by adding an `is defined` safety check for `enable_thinking`.
- Simplify JSON serialization logic for tool call arguments in the Jinja template.
- Update class docstring to explicitly indicate support for Qwen 3.5 and Qwen 3.6 models.
- Include `preserve_thinking` state in verbose processing logs.
@@ -5516,7 +5519,7 @@ class Qwen35ChatHandler(MTMDChatHandler):
5516
5519
" {%- if tool_call.arguments is defined -%}"
5517
5520
" {%- for (args_name, args_value) in tool_call.arguments | items -%}"
5518
5521
" {{- '<parameter=' + args_name + '>\n' -}}"
5519
-
" {%- set args_value = args_value | tojson | safe if args_value is mapping or args_value is sequence and args_value is not string else args_value | string -%}"
5522
+
" {%- set args_value = args_value | string if args_value is string else args_value | tojson | safe %}"
5520
5523
" {{- args_value -}}"
5521
5524
" {{- '\n</parameter>' -}}"
5522
5525
" {%- endfor -%}"
@@ -5543,7 +5546,7 @@ class Qwen35ChatHandler(MTMDChatHandler):
5543
5546
"{%- endfor -%}"
5544
5547
"{%- if add_generation_prompt -%}"
5545
5548
" {{- '<|im_start|>assistant\n' -}}"
5546
-
" {%- if enable_thinking is false -%}"
5549
+
" {%- if enable_thinking is defined and enable_thinking is false -%}"
5547
5550
" {{- '<think>\n\n</think>\n\n' -}}"
5548
5551
" {%- else -%}"
5549
5552
" {{- '<think>\n' -}}"
@@ -5553,23 +5556,29 @@ class Qwen35ChatHandler(MTMDChatHandler):
5553
5556
5554
5557
def__init__(
5555
5558
self,
5556
-
enable_thinking: bool=True,
5557
5559
add_vision_id: bool=True,
5560
+
enable_thinking: bool=True,
5561
+
preserve_thinking: bool=False,
5558
5562
**kwargs,
5559
5563
):
5560
5564
"""
5561
5565
Parameters:
5562
-
- enable_thinking (bool):
5563
-
- True (default): Enables reasoning for better results.
5564
-
- False: Disables reasoning for faster results.
5565
5566
- add_vision_id (bool):
5566
5567
- True (default): Count all the images. Recommended for multi-image.
5567
5568
- False: Doesn't count the images. Can save tokens with single-image.
5569
+
- enable_thinking (bool):
5570
+
- True (default): Enables reasoning for better results.
5571
+
- False: Disables reasoning for faster results.
5572
+
- preserve_thinking (bool):
5573
+
- True: Keeps <think> reasoning process for ALL historical conversational turns.
5574
+
- False (default): Only keeps <think> for the latest assistant reply to save tokens.
0 commit comments