[ROCm][CI] Restore Mistral tool-parser compatibility after unification (#50515)

Signed-off-by: Andreas Karatzas <Andreas.Karatzas@amd.com>
This commit is contained in:
Andreas Karatzas
2026-07-31 16:32:43 +00:00
committed by GitHub
parent 7c08664f5c
commit 8d8a4e0f2b
2 changed files with 21 additions and 4 deletions
+11 -4
View File
@@ -526,14 +526,21 @@ class MistralParser(ParserEngine):
def _legacy_extract_tool_calls(
self,
model_output: str,
request: ChatCompletionRequest,
request: ChatCompletionRequest | None,
) -> ExtractedToolCallInformation:
"""Pre-v11 non-streaming extraction.
Handles ``[TOOL_CALLS][{...}]`` and guided bare-array formats.
"""
if request is None:
tool_choice = None
tools = None
else:
tool_choice = request.tool_choice
tools = request.tools
# tool_choice="none" with tools: never produce tool calls.
if request.tool_choice == "none" and request.tools:
if tool_choice == "none" and tools:
return ExtractedToolCallInformation(
tools_called=False, tool_calls=[], content=model_output
)
@@ -550,8 +557,8 @@ class MistralParser(ParserEngine):
f"but got {model_output}."
)
stringified_tool_calls = raw_tool_calls[0].strip()
elif request.tool_choice == "required" or isinstance(
request.tool_choice, ChatCompletionNamedToolChoiceParam
elif tool_choice == "required" or isinstance(
tool_choice, ChatCompletionNamedToolChoiceParam
):
# Guided bare-array output (no [TOOL_CALLS] marker).
stringified_tool_calls = model_output.strip()
+10
View File
@@ -25,6 +25,16 @@ class MistralToolParser(MistralParserToolAdapter): # type: ignore[valid-type, m
# correctly instead of crashing or dumping the raw envelope into arguments.
supports_required_and_named = False
@property
def bot_token(self) -> str:
"""Return the Mistral tool-call marker exposed by the legacy parser."""
return self._parser_engine.bot_token
@property
def bot_token_id(self) -> int | None:
"""Return the token id for :attr:`bot_token`."""
return self._parser_engine.bot_token_id
def adjust_request(
self,
request: ChatCompletionRequest | ResponsesRequest,