[Bugfix] fix Qwen3.5 tool calling bug (#36774)
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
This commit is contained in:
@@ -249,7 +249,10 @@ class Qwen3CoderToolParser(ToolParser):
|
|||||||
self, function_call_str: str, tools: list[ChatCompletionToolsParam] | None
|
self, function_call_str: str, tools: list[ChatCompletionToolsParam] | None
|
||||||
) -> ToolCall | None:
|
) -> ToolCall | None:
|
||||||
# Extract function name
|
# Extract function name
|
||||||
end_index = function_call_str.index(">")
|
end_index = function_call_str.find(">")
|
||||||
|
# If there's no ">" character, this is not a valid xml function call
|
||||||
|
if end_index == -1:
|
||||||
|
return None
|
||||||
function_name = function_call_str[:end_index]
|
function_name = function_call_str[:end_index]
|
||||||
param_config = self._get_arguments_config(function_name, tools)
|
param_config = self._get_arguments_config(function_name, tools)
|
||||||
parameters = function_call_str[end_index + 1 :]
|
parameters = function_call_str[end_index + 1 :]
|
||||||
@@ -316,7 +319,6 @@ class Qwen3CoderToolParser(ToolParser):
|
|||||||
self._parse_xml_function_call(function_call_str, request.tools)
|
self._parse_xml_function_call(function_call_str, request.tools)
|
||||||
for function_call_str in function_calls
|
for function_call_str in function_calls
|
||||||
]
|
]
|
||||||
|
|
||||||
# Populate prev_tool_call_arr for serving layer to set finish_reason
|
# Populate prev_tool_call_arr for serving layer to set finish_reason
|
||||||
self.prev_tool_call_arr.clear() # Clear previous calls
|
self.prev_tool_call_arr.clear() # Clear previous calls
|
||||||
for tool_call in tool_calls:
|
for tool_call in tool_calls:
|
||||||
@@ -333,10 +335,10 @@ class Qwen3CoderToolParser(ToolParser):
|
|||||||
idx = model_output.find(self.tool_call_prefix)
|
idx = model_output.find(self.tool_call_prefix)
|
||||||
content_index = content_index if content_index >= 0 else idx
|
content_index = content_index if content_index >= 0 else idx
|
||||||
content = model_output[:content_index] # .rstrip()
|
content = model_output[:content_index] # .rstrip()
|
||||||
|
valid_tool_calls = [tc for tc in tool_calls if tc is not None]
|
||||||
return ExtractedToolCallInformation(
|
return ExtractedToolCallInformation(
|
||||||
tools_called=(len(tool_calls) > 0),
|
tools_called=(len(valid_tool_calls) > 0),
|
||||||
tool_calls=tool_calls,
|
tool_calls=valid_tool_calls,
|
||||||
content=content if content else None,
|
content=content if content else None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user