[RL][TITO] Preserve whitespace in reasoning parser outputs (#24251)
This commit is contained in:
@@ -216,7 +216,7 @@ class DeepSeekV32Detector(BaseFormatDetector):
|
||||
:return: ParseResult indicating success or failure, consumed text, leftover text, and parsed calls.
|
||||
"""
|
||||
idx = text.find(self.bot_token)
|
||||
normal_text = text[:idx].strip() if idx != -1 else text
|
||||
normal_text = text[:idx].removesuffix("\n\n") if idx != -1 else text
|
||||
if self.bot_token not in text:
|
||||
return StreamingParseResult(normal_text=normal_text, calls=[])
|
||||
|
||||
|
||||
@@ -70,9 +70,10 @@ class BaseReasoningFormatDetector:
|
||||
return StreamingParseResult(normal_text=text)
|
||||
|
||||
# The text is considered to be in a reasoning block.
|
||||
processed_text = text.replace(
|
||||
self.think_start_token + self.think_start_self_label, ""
|
||||
).strip()
|
||||
think_start_text = self.think_start_token + self.think_start_self_label
|
||||
processed_text = text
|
||||
while processed_text.startswith(think_start_text):
|
||||
processed_text = processed_text[len(think_start_text) :]
|
||||
|
||||
if (
|
||||
self.think_end_token not in processed_text
|
||||
@@ -86,7 +87,7 @@ class BaseReasoningFormatDetector:
|
||||
):
|
||||
# Find the first occurrence of tool_start_token and split there
|
||||
tool_idx = processed_text.find(self.tool_start_token)
|
||||
reasoning_text = processed_text[:tool_idx].strip()
|
||||
reasoning_text = processed_text[:tool_idx]
|
||||
# Preserve tool_start_token in normal text
|
||||
normal_text = processed_text[tool_idx:]
|
||||
return StreamingParseResult(
|
||||
@@ -99,7 +100,7 @@ class BaseReasoningFormatDetector:
|
||||
if self.think_end_token in processed_text:
|
||||
splits = processed_text.split(self.think_end_token, maxsplit=1)
|
||||
reasoning_text = splits[0]
|
||||
normal_text = splits[1].strip()
|
||||
normal_text = splits[1]
|
||||
|
||||
return StreamingParseResult(
|
||||
normal_text=normal_text, reasoning_text=reasoning_text
|
||||
@@ -150,7 +151,7 @@ class BaseReasoningFormatDetector:
|
||||
normal_text = current_text[end_idx + len(self.think_end_token) :]
|
||||
|
||||
return StreamingParseResult(
|
||||
normal_text=normal_text, reasoning_text=reasoning_text.rstrip()
|
||||
normal_text=normal_text, reasoning_text=reasoning_text
|
||||
)
|
||||
|
||||
# Continue with reasoning content
|
||||
|
||||
Reference in New Issue
Block a user