Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/tool_parsers/test_ernie45_moe_tool_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ def test_extract_tool_calls_no_tools(ernie45_tool_parser):
assert extracted_tool_calls.content == model_output


def test_extract_tool_calls_truncated_keeps_content(ernie45_tool_parser):
# Output cut off (e.g. by max_tokens) before </tool_call> has no complete call,
# so it must be returned as content instead of being dropped.
model_output = (
'Sure.\n<tool_call>\n{"name": "get_weather", "arguments": {"city": "Par'
)
extracted_tool_calls = ernie45_tool_parser.extract_tool_calls(
model_output, request=None
)
assert not extracted_tool_calls.tools_called
assert extracted_tool_calls.tool_calls == []
assert extracted_tool_calls.content == model_output


@pytest.mark.parametrize(
ids=[
"single_tool_call",
Expand Down
5 changes: 5 additions & 0 deletions vllm/tool_parsers/ernie45_tool_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ def extract_tool_calls(
)
)

if not tool_calls:
return ExtractedToolCallInformation(
tools_called=False, tool_calls=[], content=model_output
)

content = model_output[
: model_output.find(self.tool_calls_start_token)
].rstrip("\n")
Expand Down
Loading