From d83ab51908a4167e02dbd857cd421fdf6fa4aaaf Mon Sep 17 00:00:00 2001 From: root Date: Wed, 2 Sep 2026 06:43:19 +0000 Subject: [PATCH] [fix] to none --- .../reasoning/abs_reasoning_parsers.py | 16 +++++++++------- .../reasoning/qwen3_reasoning_parser.py | 10 +++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/qwen3_6_scripts/reasoning/abs_reasoning_parsers.py b/qwen3_6_scripts/reasoning/abs_reasoning_parsers.py index c6141074..bb996040 100644 --- a/qwen3_6_scripts/reasoning/abs_reasoning_parsers.py +++ b/qwen3_6_scripts/reasoning/abs_reasoning_parsers.py @@ -144,9 +144,9 @@ class BaseThinkingReasoningParser(ReasoningParser): model_output = parts[2] if parts[1] else parts[0] if self.end_token not in model_output: - return model_output, None + return model_output or None, None reasoning, _, content = model_output.partition(self.end_token) - return reasoning, content or None + return reasoning or None, content or None def extract_reasoning_streaming( self, @@ -180,9 +180,9 @@ class BaseThinkingReasoningParser(ReasoningParser): content=content or None, ) elif end_in_prev: - return _DeltaMessage(content=delta_text) + return _DeltaMessage(content=delta_text) if delta_text else None else: - return _DeltaMessage(reasoning_content=delta_text) + return _DeltaMessage(reasoning_content=delta_text) if delta_text else None elif start_in_delta: if end_in_delta: @@ -190,15 +190,17 @@ class BaseThinkingReasoningParser(ReasoningParser): end_idx = delta_text.find(self.end_token) reasoning = delta_text[start_idx + len(self.start_token):end_idx] content = delta_text[end_idx + len(self.end_token):] + if not reasoning and not content: + return None return _DeltaMessage( reasoning_content=reasoning or None, content=content or None, ) else: - return _DeltaMessage(reasoning_content=delta_text) + return _DeltaMessage(reasoning_content=delta_text) if delta_text else None else: - return _DeltaMessage(content=delta_text) + return _DeltaMessage(content=delta_text) if delta_text else None class ReasoningParserManager: @@ -240,4 +242,4 @@ class ReasoningParserManager: @classmethod def list_registered(cls) -> list: - return sorted(set(cls._parsers) | set(cls._lazy)) + return sorted(set(cls._parsers) | set(cls._lazy)) \ No newline at end of file diff --git a/qwen3_6_scripts/reasoning/qwen3_reasoning_parser.py b/qwen3_6_scripts/reasoning/qwen3_reasoning_parser.py index f7fddfec..574c603c 100644 --- a/qwen3_6_scripts/reasoning/qwen3_reasoning_parser.py +++ b/qwen3_6_scripts/reasoning/qwen3_reasoning_parser.py @@ -46,10 +46,14 @@ class Qwen3ReasoningParser(BaseThinkingReasoningParser): if self.end_token not in model_output: # Thinking enabled but output truncated before . - return model_output, None + return model_output or None, None reasoning, _, content = model_output.partition(self.end_token) - return reasoning, content or None + # Normalize empty strings to None. When the model skips thinking + # (outputs immediately), reasoning is "" — returning None + # keeps reasoning_content out of the JSON response so the test + # framework sees "no reasoning" rather than "empty reasoning". + return reasoning or None, content or None def count_reasoning_tokens(self, token_ids: Sequence[int]) -> int: token_ids = list(token_ids) @@ -109,4 +113,4 @@ class Qwen3ReasoningParser(BaseThinkingReasoningParser): # Register immediately when this module is imported. -ReasoningParserManager.register_module("qwen3", Qwen3ReasoningParser) +ReasoningParserManager.register_module("qwen3", Qwen3ReasoningParser) \ No newline at end of file