Skip to content

Commit 4de790f

Browse files
[Bugfix]: Fix the incompatibility issue with tool_choice 'required' when Thinking is enabled (vllm-project#19075)
Signed-off-by: chaunceyjiang <[email protected]>
1 parent b5fd950 commit 4de790f

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

tests/entrypoints/openai/test_completion_with_function_calling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ...utils import RemoteOpenAIServer
1010

1111
# any model with a chat template should work here
12-
MODEL_NAME = "Qwen/Qwen2.5-1.5B-Instruct"
12+
MODEL_NAME = "Qwen/Qwen3-0.6B"
1313

1414

1515
@pytest.fixture(scope="module")

vllm/entrypoints/openai/serving_chat.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,13 @@ def _filter_delta_text(delta_text: str,
320320
def extract_tool_call_required_streaming(
321321
self,
322322
previous_text: str,
323-
current_text: str,
323+
current_text: Optional[str],
324324
delta_text: str,
325325
function_name_returned: bool,
326326
) -> tuple[Optional[DeltaMessage], bool]:
327+
if current_text is None or current_text == "":
328+
# if the current text is empty, we cannot parse it
329+
return None, function_name_returned
327330
try:
328331
obj = partial_json_parser.loads(current_text)
329332
except partial_json_parser.core.exceptions.MalformedJSON:
@@ -650,10 +653,18 @@ async def chat_completion_stream_generator(
650653
current_text = previous_text + delta_text
651654
fn_name_returned = function_name_returned[i]
652655

656+
if self.reasoning_parser:
657+
_, content = \
658+
reasoning_parser.extract_reasoning_content(
659+
current_text,
660+
request
661+
)
662+
else:
663+
content = current_text
653664
delta_message, function_name_returned[i] = (
654665
self.extract_tool_call_required_streaming(
655666
previous_text=previous_text,
656-
current_text=current_text,
667+
current_text=content,
657668
delta_text=delta_text,
658669
function_name_returned=fn_name_returned))
659670

@@ -981,8 +992,9 @@ async def chat_completion_full_generator(
981992

982993
# the fields of FunctionDefinition are a superset of the
983994
# tool call outputs and can be used for parsing
995+
assert content is not None
984996
tool_calls = TypeAdapter(
985-
list[FunctionDefinition]).validate_json(output.text)
997+
list[FunctionDefinition]).validate_json(content)
986998
message = ChatMessage(
987999
role=role,
9881000
content="",

0 commit comments

Comments
 (0)