reasoning_content -> reasoning (#27752)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
Harry Mellor
2025-11-08 04:15:08 -08:00
committed by GitHub
parent 608bb14462
commit d9ab1ad9d1
46 changed files with 428 additions and 438 deletions

View File

@@ -40,7 +40,7 @@ class Step3ReasoningParser(ReasoningParser):
"token in the tokenizer!"
)
def extract_reasoning_content_streaming(
def extract_reasoning_streaming(
self,
previous_text: str,
current_text: str,
@@ -54,7 +54,7 @@ class Step3ReasoningParser(ReasoningParser):
Handles streaming output where previous + delta = current.
Uses token IDs for faster processing.
For text "abc</think>xyz":
- 'abc' goes to reasoning_content
- 'abc' goes to reasoning
- 'xyz' goes to content
"""
# Skip single special token
@@ -64,10 +64,10 @@ class Step3ReasoningParser(ReasoningParser):
if self.think_end_token_id in delta_token_ids:
# </think> in delta, extract reasoning content and remaining content
end_index = delta_text.find(self.think_end_token)
reasoning_content = delta_text[:end_index]
reasoning = delta_text[:end_index]
content = delta_text[end_index + len(self.think_end_token) :]
return DeltaMessage(
reasoning_content=reasoning_content,
reasoning=reasoning,
content=content if content else None,
)
elif self.think_end_token_id in previous_token_ids:
@@ -75,9 +75,9 @@ class Step3ReasoningParser(ReasoningParser):
return DeltaMessage(content=delta_text)
else:
# No </think> seen yet, everything is reasoning
return DeltaMessage(reasoning_content=delta_text)
return DeltaMessage(reasoning=delta_text)
def extract_reasoning_content(
def extract_reasoning(
self, model_output: str, request: ChatCompletionRequest
) -> tuple[str | None, str | None]:
# Check if the model output contains the </think> token
@@ -87,7 +87,7 @@ class Step3ReasoningParser(ReasoningParser):
else:
# Find the first occurrence of </think>
end_index = model_output.find(self.think_end_token)
reasoning_content = model_output[:end_index]
reasoning = model_output[:end_index]
# Content after </think> token
content = model_output[end_index + len(self.think_end_token) :]
@@ -95,7 +95,7 @@ class Step3ReasoningParser(ReasoningParser):
if len(content) == 0:
content = None
return reasoning_content, content
return reasoning, content
def is_reasoning_end(self, input_ids: list[int]) -> bool:
return self.think_end_token_id in input_ids