From 8d8a4e0f2b118dc975bbba930aeb7c6cbd623c2a Mon Sep 17 00:00:00 2001 From: Andreas Karatzas Date: Fri, 31 Jul 2026 11:32:43 -0500 Subject: [PATCH] [ROCm][CI] Restore Mistral tool-parser compatibility after unification (#50515) Signed-off-by: Andreas Karatzas --- vllm/parser/mistral.py | 15 +++++++++++---- vllm/tool_parsers/mistral_tool_parser.py | 10 ++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/vllm/parser/mistral.py b/vllm/parser/mistral.py index 4f7c199202..edc7018620 100644 --- a/vllm/parser/mistral.py +++ b/vllm/parser/mistral.py @@ -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() diff --git a/vllm/tool_parsers/mistral_tool_parser.py b/vllm/tool_parsers/mistral_tool_parser.py index 36a23764c6..01bddd4ed6 100644 --- a/vllm/tool_parsers/mistral_tool_parser.py +++ b/vllm/tool_parsers/mistral_tool_parser.py @@ -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,