[fix] </think> to none
This commit is contained in:
@@ -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))
|
||||
@@ -46,10 +46,14 @@ class Qwen3ReasoningParser(BaseThinkingReasoningParser):
|
||||
|
||||
if self.end_token not in model_output:
|
||||
# Thinking enabled but output truncated before </think>.
|
||||
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 </think> 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)
|
||||
Reference in New Issue
Block a user