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
1b1e35aa
Unverified
Commit
1b1e35aa
authored
Dec 02, 2025
by
Julien Denize
Committed by
GitHub
Dec 02, 2025
Browse files
[BUGFIX] Fix regex pattern for Mistral Tool Call (#29918)
Signed-off-by:
juliendenize
<
julien.denize@mistral.ai
>
parent
5e5646e2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
1 deletion
+36
-1
tests/models/language/generation/test_mistral.py
tests/models/language/generation/test_mistral.py
+35
-0
vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py
vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py
+1
-1
No files found.
tests/models/language/generation/test_mistral.py
View file @
1b1e35aa
...
...
@@ -315,3 +315,38 @@ def test_mistral_function_call_nested_json():
assert
json
.
loads
(
parsed
.
tool_calls
[
0
].
function
.
arguments
)
==
args_dict
# No additional content outside the tool call should be returned.
assert
parsed
.
content
is
None
# multiple calls
multiple_args_dict
=
[
{
"city"
:
"Dallas"
,
"state"
:
"TX"
,
"unit"
:
"fahrenheit"
,
"sub_dict"
:
{
"foo"
:
"bar"
,
"inner"
:
{
"x"
:
1
,
"y"
:
2
}},
},
{},
{
"a"
:
0
},
{
"a"
:
1
,
"b"
:
"c"
},
]
names
=
[
"get_current_weather"
,
"get_current_weather_2"
,
"random"
,
"random_2"
]
model_output
=
""
.
join
(
[
f
"
{
parser
.
bot_token
}{
name
}{
json
.
dumps
(
args
)
}
"
for
name
,
args
in
zip
(
names
,
multiple_args_dict
)
]
)
parsed
=
parser
.
extract_tool_calls
(
model_output
,
None
)
# Assertions: the tool call is detected and the full nested JSON is parsed
# without truncation.
assert
parsed
.
tools_called
assert
len
(
parsed
.
tool_calls
)
==
len
(
multiple_args_dict
)
for
i
,
tool_call
in
enumerate
(
parsed
.
tool_calls
):
assert
MistralToolCall
.
is_valid_id
(
tool_call
.
id
)
assert
tool_call
.
function
.
name
==
names
[
i
]
assert
json
.
loads
(
tool_call
.
function
.
arguments
)
==
multiple_args_dict
[
i
]
# No additional content outside the tool call should be returned.
assert
parsed
.
content
is
None
vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py
View file @
1b1e35aa
...
...
@@ -80,7 +80,7 @@ class MistralToolParser(ToolParser):
self
.
tool_call_regex
=
re
.
compile
(
r
"\[{.*}\]"
,
re
.
DOTALL
)
if
_is_fn_name_regex_support
(
self
.
model_tokenizer
):
self
.
fn_name_regex
=
re
.
compile
(
r
"([a-zA-Z0-9_-]+)(\{[\s\S]*?\})
(?=\s*$|,|\s)?
"
,
re
.
DOTALL
r
"([a-zA-Z0-9_-]+)(\{[\s\S]*?\}
+
)"
,
re
.
DOTALL
)
else
:
self
.
fn_name_regex
=
None
...
...
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