[Refactor] Derive is_reasoning_end from the engine grammar (#56200)
Signed-off-by: sfeng33 <4florafeng@gmail.com>
This commit is contained in:
+1
-18
@@ -193,6 +193,7 @@ def mistral_config(
|
||||
return ParserEngineConfig(
|
||||
name=name,
|
||||
initial_state=ParserState.CONTENT,
|
||||
wait_for_reasoning=reasoning_encoding != "none",
|
||||
terminals={
|
||||
**reasoning_terminals,
|
||||
"TOOL_CALLS": _TOOL_CALLS,
|
||||
@@ -891,24 +892,6 @@ class MistralParser(ParserEngine):
|
||||
|
||||
return (delta_to_be_parsed, "")
|
||||
|
||||
def is_reasoning_end(self, input_ids: list[int]) -> bool:
|
||||
if self._reasoning_encoding == "none":
|
||||
return True
|
||||
if super().is_reasoning_end(input_ids):
|
||||
return True
|
||||
# [TOOL_CALLS] acts as an implicit reasoning-end marker
|
||||
if self.bot_token_id is not None:
|
||||
reasoning_start_id = self._reasoning_start_token_id
|
||||
for i in range(len(input_ids) - 1, -1, -1):
|
||||
if (
|
||||
reasoning_start_id is not None
|
||||
and input_ids[i] == reasoning_start_id
|
||||
):
|
||||
return False
|
||||
if input_ids[i] == self.bot_token_id:
|
||||
return True
|
||||
return False
|
||||
|
||||
def extract_reasoning(
|
||||
self,
|
||||
model_output: str,
|
||||
|
||||
Reference in New Issue
Block a user