Skip to content

Commit cc0ee2c

Browse files
committed
Fix regression: validate tool_choice=auto when enable_auto_tools=True but tool_parser=None
The previous logic missed the case where: - tool_choice="auto" - enable_auto_tools=True - tool_parser=None In this scenario, no error was returned, but it should error since tool_parser is still required. Also added regression test to cover this case. Signed-off-by: majiayu000 <[email protected]>
1 parent c680b7b commit cc0ee2c

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

tests/entrypoints/openai/test_serving_chat.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,3 +1440,27 @@ async def test_tool_choice_validation_without_parser():
14401440
error_body = response_named.body.decode()
14411441
assert "tool_choice" in error_body
14421442
assert "--tool-call-parser" in error_body
1443+
1444+
# Test tool_choice="auto" with enable_auto_tools=True but no tool_parser
1445+
# This is a regression test: enable_auto_tools is set but tool_parser is None
1446+
serving_chat_auto_enabled = OpenAIServingChat(
1447+
mock_engine,
1448+
models,
1449+
response_role="assistant",
1450+
chat_template=CHAT_TEMPLATE,
1451+
chat_template_content_format="auto",
1452+
request_logger=None,
1453+
enable_auto_tools=True, # Enabled but no tool_parser configured
1454+
)
1455+
1456+
req_auto = ChatCompletionRequest(
1457+
model=MODEL_NAME,
1458+
messages=[{"role": "user", "content": "What's the weather?"}],
1459+
tools=tools,
1460+
tool_choice="auto",
1461+
)
1462+
response_auto = await serving_chat_auto_enabled.create_chat_completion(req_auto)
1463+
assert hasattr(response_auto, "body")
1464+
error_body = response_auto.body.decode()
1465+
assert "auto" in error_body
1466+
assert "--tool-call-parser" in error_body

vllm/entrypoints/openai/serving_chat.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,21 @@ async def create_chat_completion(
216216
None,
217217
"none",
218218
):
219-
if request.tool_choice == "auto" and not self.enable_auto_tools:
220-
# for hf tokenizers, "auto" tools requires
221-
# --enable-auto-tool-choice and --tool-call-parser
219+
if request.tool_choice == "auto":
220+
if not self.enable_auto_tools:
221+
# for hf tokenizers, "auto" tools requires
222+
# --enable-auto-tool-choice and --tool-call-parser
223+
return self.create_error_response(
224+
'"auto" tool choice requires '
225+
"--enable-auto-tool-choice and "
226+
"--tool-call-parser to be set"
227+
)
228+
# enable_auto_tools is set but tool_parser is None
222229
return self.create_error_response(
223230
'"auto" tool choice requires '
224-
"--enable-auto-tool-choice and --tool-call-parser to be set"
231+
"--tool-call-parser to be set"
225232
)
226-
elif request.tool_choice != "auto":
233+
else:
227234
# "required" or named tool requires tool parser
228235
return self.create_error_response(
229236
f'tool_choice="{request.tool_choice}" requires '

0 commit comments

Comments
 (0)