Skip to content

Commit 5e8cce0

Browse files
committed
[Refactor] to simplify and extract the shared logic between chat completion and responses
Signed-off-by: chaunceyjiang <[email protected]>
1 parent c3cba61 commit 5e8cce0

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

vllm/entrypoints/openai/serving_engine.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,12 +1321,7 @@ def _parse_tool_calls_from_content(
13211321
content: str | None = None,
13221322
) -> tuple[list[FunctionCall] | None, str | None]:
13231323
function_calls = list[FunctionCall]()
1324-
if request.tool_choice is None:
1325-
# No tool calls.
1326-
return None, content
1327-
elif request.tool_choice and isinstance(
1328-
request.tool_choice, ToolChoiceFunction
1329-
):
1324+
if request.tool_choice and isinstance(request.tool_choice, ToolChoiceFunction):
13301325
assert content is not None
13311326
# Forced Function Call
13321327
function_calls.append(
@@ -1355,8 +1350,11 @@ def _parse_tool_calls_from_content(
13551350
]
13561351
)
13571352
content = None # Clear content since tool is called.
1358-
elif request.tool_choice == "auto" or request.tool_choice == "none":
1359-
assert tool_parser_cls is not None
1353+
elif (
1354+
tool_parser_cls
1355+
and enable_auto_tools
1356+
and (request.tool_choice == "auto" or request.tool_choice is None)
1357+
):
13601358
# Automatic Tool Call Parsing
13611359
try:
13621360
tool_parser = tool_parser_cls(tokenizer)
@@ -1380,8 +1378,7 @@ def _parse_tool_calls_from_content(
13801378
else:
13811379
# No tool calls.
13821380
return None, content
1383-
else:
1384-
raise ValueError(f"Invalid tool_choice: {request.tool_choice}")
1381+
13851382
return function_calls, content
13861383

13871384
@staticmethod

0 commit comments

Comments
 (0)