Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
5c213d28
Unverified
Commit
5c213d28
authored
Dec 09, 2025
by
Julien Denize
Committed by
GitHub
Dec 09, 2025
Browse files
[BUGFIX] Mistral tool call parser v11+ (#30332)
Signed-off-by:
juliendenize
<
julien.denize@mistral.ai
>
parent
ee14644b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
20 deletions
+32
-20
tests/tool_use/test_mistral_tool_parser.py
tests/tool_use/test_mistral_tool_parser.py
+16
-0
vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py
vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py
+16
-20
No files found.
tests/tool_use/test_mistral_tool_parser.py
View file @
5c213d28
...
@@ -615,6 +615,7 @@ def test_extract_tool_calls_streaming(
...
@@ -615,6 +615,7 @@ def test_extract_tool_calls_streaming(
"single_tool_weather"
,
"single_tool_weather"
,
"multiple_tool_calls"
,
"multiple_tool_calls"
,
"content_before_tool"
,
"content_before_tool"
,
"complex"
,
],
],
argnames
=
[
"model_output"
,
"expected_tool_calls"
,
"expected_content"
],
argnames
=
[
"model_output"
,
"expected_tool_calls"
,
"expected_content"
],
argvalues
=
[
argvalues
=
[
...
@@ -673,6 +674,21 @@ def test_extract_tool_calls_streaming(
...
@@ -673,6 +674,21 @@ def test_extract_tool_calls_streaming(
],
],
"bla"
,
"bla"
,
),
),
(
# Complex
"""[TOOL_CALLS]bash{"command": "print(
\\
"hello world!
\\
")
\\
nre.compile(r
\'
{}
\'
)"}"""
,
# noqa: E501
[
ToolCall
(
function
=
FunctionCall
(
name
=
"bash"
,
arguments
=
json
.
dumps
(
{
"command"
:
"print(
\"
hello world!
\"
)
\n
re.compile(r'{}')"
}
),
)
)
],
""
,
),
],
],
)
)
def
test_extract_tool_calls_streaming_one_chunk
(
def
test_extract_tool_calls_streaming_one_chunk
(
...
...
vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py
View file @
5c213d28
...
@@ -99,12 +99,7 @@ class MistralToolParser(ToolParser):
...
@@ -99,12 +99,7 @@ class MistralToolParser(ToolParser):
self
.
bot_token
=
"[TOOL_CALLS]"
self
.
bot_token
=
"[TOOL_CALLS]"
self
.
bot_token_id
=
self
.
vocab
.
get
(
self
.
bot_token
)
self
.
bot_token_id
=
self
.
vocab
.
get
(
self
.
bot_token
)
self
.
tool_call_regex
=
re
.
compile
(
r
"\[{.*}\]"
,
re
.
DOTALL
)
self
.
tool_call_regex
=
re
.
compile
(
r
"\[{.*}\]"
,
re
.
DOTALL
)
if
not
_is_pre_v11_tokeniser
(
self
.
model_tokenizer
):
self
.
_is_pre_v11
=
_is_pre_v11_tokeniser
(
self
.
model_tokenizer
)
self
.
fn_name_regex
=
re
.
compile
(
r
"([a-zA-Z0-9_-]+)(\{[\s\S]*?\}+)"
,
re
.
DOTALL
)
else
:
self
.
fn_name_regex
=
None
if
self
.
bot_token_id
is
None
:
if
self
.
bot_token_id
is
None
:
raise
RuntimeError
(
raise
RuntimeError
(
...
@@ -148,23 +143,24 @@ class MistralToolParser(ToolParser):
...
@@ -148,23 +143,24 @@ class MistralToolParser(ToolParser):
tool_content
=
model_output
.
replace
(
self
.
bot_token
,
""
).
strip
()
tool_content
=
model_output
.
replace
(
self
.
bot_token
,
""
).
strip
()
try
:
try
:
# we first try to directly load the json as parsing very nested
# jsons is difficult
try
:
try
:
if
self
.
fn_name_regex
:
if
not
self
.
_is_pre_v11
:
function_call_arr
=
[]
function_call_arr
=
[]
for
single_tool_content
in
model_output
.
split
(
self
.
bot_token
):
for
single_tool_content
in
model_output
.
split
(
self
.
bot_token
):
matches
=
self
.
fn_name_regex
.
findall
(
single_tool_content
)
if
"{"
not
in
single_tool_content
:
continue
for
match
in
matches
:
fn_name
=
match
[
0
]
end_name
=
single_tool_content
.
find
(
"{"
)
args
=
match
[
1
]
fn_name
,
args
=
(
single_tool_content
[:
end_name
],
# fn_name is encoded outside serialized json dump
single_tool_content
[
end_name
:],
# only arguments are serialized
)
function_call_arr
.
append
(
{
"name"
:
fn_name
,
"arguments"
:
json
.
loads
(
args
)}
# fn_name is encoded outside serialized json dump
)
# only arguments are serialized
function_call_arr
.
append
(
{
"name"
:
fn_name
,
"arguments"
:
json
.
loads
(
args
)}
)
else
:
else
:
function_call_arr
=
json
.
loads
(
tool_content
)
function_call_arr
=
json
.
loads
(
tool_content
)
except
json
.
JSONDecodeError
:
except
json
.
JSONDecodeError
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment