Skip to content

Commit 32a35fb

Browse files
committed
feat: prevent tool parsing if tool_choice is 'none'
Signed-off-by: Guillaume Calmettes <gcalmettes@scaleway.com>
1 parent bb9940b commit 32a35fb

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

vllm/entrypoints/openai/serving_engine.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,19 @@ async def _preprocess_chat(
469469

470470
mm_data = await mm_data_future
471471

472-
if tool_parser is not None:
472+
# tool parsing is done only if a tool_parser has been set and if
473+
# tool_choice is not "none" (if tool_choice is "none" but a tool_parser
474+
# is set, we want to prevent parsing a tool_call hallucinated by the LLM
475+
should_parse_tools = tool_parser is not None and (hasattr(
476+
request, "tool_choice") and request.tool_choice != "none")
477+
478+
if should_parse_tools:
473479
if not isinstance(request, ChatCompletionRequest):
474480
msg = "Tool usage is only supported for Chat Completions API"
475481
raise NotImplementedError(msg)
476482

477-
request = tool_parser(tokenizer).adjust_request(request=request)
483+
request = tool_parser(tokenizer).adjust_request( # type: ignore
484+
request=request)
478485

479486
if isinstance(request_prompt, str):
480487
prompt_inputs = self._tokenize_prompt_input(

0 commit comments

Comments
 (0)