# SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project from unittest.mock import MagicMock import pytest from tests.tool_parsers.common_tests import ( ToolParserTestConfig, ToolParserTests, ) from vllm.tokenizers import TokenizerLike class TestLongCatToolParser(ToolParserTests): @pytest.fixture def tokenizer(self, default_tokenizer: TokenizerLike) -> TokenizerLike: """Add some longcat specific tokens to the default vocab.""" tokenizer = default_tokenizer tokenizer_vocab = tokenizer.get_vocab() tokenizer.get_vocab = MagicMock() tokenizer_vocab.update( { "": 32000, "": 32001, } ) tokenizer.get_vocab.return_value = tokenizer_vocab return tokenizer @pytest.fixture def test_config(self) -> ToolParserTestConfig: return ToolParserTestConfig( parser_name="longcat", # Test data no_tool_calls_output="This is a regular response without any tool calls.", single_tool_call_output=( '{"name": "get_weather", ' '"arguments": {"city": "Tokyo"}}' ), parallel_tool_calls_output=( '{"name": "get_weather", ' '"arguments": {"city": "Tokyo"}}\n' '{"name": "get_time", ' '"arguments": {"timezone": "Asia/Tokyo"}}' ), various_data_types_output="""{ "name": "test_function", "arguments": { "string_field": "hello", "int_field": 42, "float_field": 3.14, "bool_field": true, "null_field": null, "array_field": ["a", "b", "c"], "object_field": {"nested": "value"}, "empty_array": [], "empty_object": {} } }""", empty_arguments_output=( '{"name": "refresh", "arguments": {}}' "" ), surrounding_text_output=( "Let me check the weather for you.\n" '{"name": "get_weather", ' '"arguments": {"city": "Tokyo"}}\n' "Here is the result." ), escaped_strings_output="""{ "name": "test_function", "arguments": { "quoted": "He said \\"hello\\"", "path": "C:\\\\Users\\\\file.txt", "newline": "line1\\nline2", "unicode": "emoji: 🎉" } }""", malformed_input_outputs=[ '{"name": "func", "arguments": {', ( '{"name": "func", ' '"arguments": "not a dict"}' ), "Some text with invalid json", ], # Expected results single_tool_call_expected_name="get_weather", single_tool_call_expected_args={"city": "Tokyo"}, single_tool_call_expected_content=None, parallel_tool_calls_count=2, parallel_tool_calls_names=["get_weather", "get_time"], # xfail markers xfail_streaming={ "test_malformed_input": "Streaming has complex buffering behavior", }, xfail_nonstreaming={}, # Configuration allow_empty_or_json_empty_args=True, )