[Bugfix]: Fix the incompatibility issue with tool_choice 'required' when Thinking is enabled (#19075)

Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
This commit is contained in:
Chauncey 2025-06-04 07:27:24 +08:00 committed by GitHub
parent b5fd9506c1
commit 4de790fcad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View File

@ -9,7 +9,7 @@ import pytest_asyncio
from ...utils import RemoteOpenAIServer
# any model with a chat template should work here
MODEL_NAME = "Qwen/Qwen2.5-1.5B-Instruct"
MODEL_NAME = "Qwen/Qwen3-0.6B"
@pytest.fixture(scope="module")

View File

@ -320,10 +320,13 @@ class OpenAIServingChat(OpenAIServing):
def extract_tool_call_required_streaming(
self,
previous_text: str,
current_text: str,
current_text: Optional[str],
delta_text: str,
function_name_returned: bool,
) -> tuple[Optional[DeltaMessage], bool]:
if current_text is None or current_text == "":
# if the current text is empty, we cannot parse it
return None, function_name_returned
try:
obj = partial_json_parser.loads(current_text)
except partial_json_parser.core.exceptions.MalformedJSON:
@ -650,10 +653,18 @@ class OpenAIServingChat(OpenAIServing):
current_text = previous_text + delta_text
fn_name_returned = function_name_returned[i]
if self.reasoning_parser:
_, content = \
reasoning_parser.extract_reasoning_content(
current_text,
request
)
else:
content = current_text
delta_message, function_name_returned[i] = (
self.extract_tool_call_required_streaming(
previous_text=previous_text,
current_text=current_text,
current_text=content,
delta_text=delta_text,
function_name_returned=fn_name_returned))
@ -981,8 +992,9 @@ class OpenAIServingChat(OpenAIServing):
# the fields of FunctionDefinition are a superset of the
# tool call outputs and can be used for parsing
assert content is not None
tool_calls = TypeAdapter(
list[FunctionDefinition]).validate_json(output.text)
list[FunctionDefinition]).validate_json(content)
message = ChatMessage(
role=role,
content="",