mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2025-12-20 06:55:01 +08:00
[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:
parent
b5fd9506c1
commit
4de790fcad
@ -9,7 +9,7 @@ import pytest_asyncio
|
|||||||
from ...utils import RemoteOpenAIServer
|
from ...utils import RemoteOpenAIServer
|
||||||
|
|
||||||
# any model with a chat template should work here
|
# 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")
|
@pytest.fixture(scope="module")
|
||||||
|
|||||||
@ -320,10 +320,13 @@ class OpenAIServingChat(OpenAIServing):
|
|||||||
def extract_tool_call_required_streaming(
|
def extract_tool_call_required_streaming(
|
||||||
self,
|
self,
|
||||||
previous_text: str,
|
previous_text: str,
|
||||||
current_text: str,
|
current_text: Optional[str],
|
||||||
delta_text: str,
|
delta_text: str,
|
||||||
function_name_returned: bool,
|
function_name_returned: bool,
|
||||||
) -> tuple[Optional[DeltaMessage], 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:
|
try:
|
||||||
obj = partial_json_parser.loads(current_text)
|
obj = partial_json_parser.loads(current_text)
|
||||||
except partial_json_parser.core.exceptions.MalformedJSON:
|
except partial_json_parser.core.exceptions.MalformedJSON:
|
||||||
@ -650,10 +653,18 @@ class OpenAIServingChat(OpenAIServing):
|
|||||||
current_text = previous_text + delta_text
|
current_text = previous_text + delta_text
|
||||||
fn_name_returned = function_name_returned[i]
|
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] = (
|
delta_message, function_name_returned[i] = (
|
||||||
self.extract_tool_call_required_streaming(
|
self.extract_tool_call_required_streaming(
|
||||||
previous_text=previous_text,
|
previous_text=previous_text,
|
||||||
current_text=current_text,
|
current_text=content,
|
||||||
delta_text=delta_text,
|
delta_text=delta_text,
|
||||||
function_name_returned=fn_name_returned))
|
function_name_returned=fn_name_returned))
|
||||||
|
|
||||||
@ -981,8 +992,9 @@ class OpenAIServingChat(OpenAIServing):
|
|||||||
|
|
||||||
# the fields of FunctionDefinition are a superset of the
|
# the fields of FunctionDefinition are a superset of the
|
||||||
# tool call outputs and can be used for parsing
|
# tool call outputs and can be used for parsing
|
||||||
|
assert content is not None
|
||||||
tool_calls = TypeAdapter(
|
tool_calls = TypeAdapter(
|
||||||
list[FunctionDefinition]).validate_json(output.text)
|
list[FunctionDefinition]).validate_json(content)
|
||||||
message = ChatMessage(
|
message = ChatMessage(
|
||||||
role=role,
|
role=role,
|
||||||
content="",
|
content="",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user