[ROCm][CI] Restore Mistral tool-parser compatibility after unification (#50515)
Signed-off-by: Andreas Karatzas <Andreas.Karatzas@amd.com>
This commit is contained in:
+11
-4
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user