vllm/tests/tool_use/test_deepseekv31_tool_parser.py
Harry Mellor d6953beb91
Convert formatting to use ruff instead of yapf + isort (#26247)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
2025-10-05 07:06:22 -07:00

60 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import pytest
from vllm.entrypoints.openai.tool_parsers import DeepSeekV31ToolParser
from vllm.transformers_utils.tokenizer import get_tokenizer
MODEL = "deepseek-ai/DeepSeek-V3.1"
@pytest.fixture(scope="module")
def deepseekv31_tokenizer():
return get_tokenizer(tokenizer_name=MODEL)
@pytest.fixture
def parser(deepseekv31_tokenizer):
return DeepSeekV31ToolParser(deepseekv31_tokenizer)
def test_extract_tool_calls_with_tool(parser):
model_output = (
"normal text"
+ "<tool▁calls▁begin>"
+ '<tool▁call▁begin>foo<tool▁sep>{"x":1}<tool▁call▁end>'
+ "<tool▁calls▁end>"
)
result = parser.extract_tool_calls(model_output, None)
assert result.tools_called
assert len(result.tool_calls) == 1
assert result.tool_calls[0].function.name == "foo"
assert result.tool_calls[0].function.arguments == '{"x":1}'
assert result.content == "normal text"
def test_extract_tool_calls_with_multiple_tools(parser):
model_output = (
"some prefix text"
+ "<tool▁calls▁begin>"
+ '<tool▁call▁begin>foo<tool▁sep>{"x":1}<tool▁call▁end>'
+ '<tool▁call▁begin>bar<tool▁sep>{"y":2}<tool▁call▁end>'
+ "<tool▁calls▁end>"
+ " some suffix text"
)
result = parser.extract_tool_calls(model_output, None)
assert result.tools_called
assert len(result.tool_calls) == 2
assert result.tool_calls[0].function.name == "foo"
assert result.tool_calls[0].function.arguments == '{"x":1}'
assert result.tool_calls[1].function.name == "bar"
assert result.tool_calls[1].function.arguments == '{"y":2}'
# prefix is content
assert result.content == "some prefix text"