[Bugfix][Parser] Scope reasoning-end detection to the current turn via turn-boundary tokens (#54089)
Signed-off-by: Mikhail Podvitskii <podvitskiymichael@gmail.com>
This commit is contained in:
@@ -147,6 +147,11 @@ class ParserEngine(Parser):
|
||||
self._reasoning_start_token_id = vocab.get(start_text)
|
||||
if end_text:
|
||||
self._reasoning_end_token_id = vocab.get(end_text)
|
||||
self._turn_boundary_token_ids: frozenset[int] = frozenset(
|
||||
token_id
|
||||
for token in parser_engine_config.turn_boundary_tokens
|
||||
if (token_id := vocab.get(token)) is not None
|
||||
)
|
||||
|
||||
@property
|
||||
def reasoning_start_str(self) -> str | None:
|
||||
@@ -601,11 +606,17 @@ class ParserEngine(Parser):
|
||||
if end_id is not None:
|
||||
if not input_ids:
|
||||
return self.parser_engine_config.initial_state != ParserState.REASONING
|
||||
boundary_ids = self._turn_boundary_token_ids
|
||||
for i in range(len(input_ids) - 1, -1, -1):
|
||||
if input_ids[i] == end_id:
|
||||
token_id = input_ids[i]
|
||||
if token_id == end_id:
|
||||
return True
|
||||
if start_id is not None and input_ids[i] == start_id:
|
||||
if start_id is not None and token_id == start_id:
|
||||
return False
|
||||
if token_id in boundary_ids:
|
||||
return (
|
||||
self.parser_engine_config.initial_state != ParserState.REASONING
|
||||
)
|
||||
return False
|
||||
return self._reasoning_ended
|
||||
|
||||
|
||||
Reference in New Issue
Block a user