| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | import pytest |
| 5 | |
| 6 | from tests.tool_parsers.common_tests import ( |
| 7 | ToolParserTestConfig, |
| 8 | ToolParserTests, |
| 9 | ) |
| 10 | |
| 11 | |
| 12 | class TestGranite20bFcToolParser(ToolParserTests): |
| 13 | @pytest.fixture |
| 14 | def test_config(self) -> ToolParserTestConfig: |
| 15 | return ToolParserTestConfig( |
| 16 | parser_name="granite-20b-fc", |
| 17 | # Test data |
| 18 | no_tool_calls_output="This is a regular response without any tool calls.", |
| 19 | single_tool_call_output=( |
| 20 | '<function_call> {"name": "get_weather", ' |
| 21 | '"arguments": {"city": "Tokyo"}}' |
| 22 | ), |
| 23 | parallel_tool_calls_output=( |
| 24 | '<function_call> {"name": "get_weather", ' |
| 25 | '"arguments": {"city": "Tokyo"}}\n' |
| 26 | '<function_call> {"name": "get_time", ' |
| 27 | '"arguments": {"timezone": "Asia/Tokyo"}}' |
| 28 | ), |
| 29 | various_data_types_output="""<function_call> { |
| 30 | "name": "test_function", |
| 31 | "arguments": { |
| 32 | "string_field": "hello", |
| 33 | "int_field": 42, |
| 34 | "float_field": 3.14, |
| 35 | "bool_field": true, |
| 36 | "null_field": null, |
| 37 | "array_field": ["a", "b", "c"], |
| 38 | "object_field": {"nested": "value"}, |
| 39 | "empty_array": [], |
| 40 | "empty_object": {} |
| 41 | } |
| 42 | }""", |
| 43 | empty_arguments_output=( |
| 44 | '<function_call> {"name": "refresh", "arguments": {}}' |
| 45 | ), |
| 46 | surrounding_text_output="""Let me check the weather for you. |
| 47 | <function_call> {"name": "get_weather", "arguments": {"city": "Tokyo"}}""", |
| 48 | escaped_strings_output="""<function_call> { |
| 49 | "name": "test_function", |
| 50 | "arguments": { |
| 51 | "quoted": "He said \\"hello\\"", |
| 52 | "path": "C:\\\\Users\\\\file.txt", |
| 53 | "newline": "line1\\nline2", |
| 54 | "unicode": "emoji: 🎉" |
| 55 | } |
| 56 | }""", |
| 57 | malformed_input_outputs=[ |
| 58 | '<function_call> {"name": "func", "arguments": {', |
| 59 | '<function_call> [{"name": "func", "arguments": {}}]', |
| 60 | '{"name": "func", "arguments": {}}', |
| 61 | '<function_call> {"name": 123}', |
| 62 | ], |
| 63 | # Expected results |
| 64 | single_tool_call_expected_name="get_weather", |
| 65 | single_tool_call_expected_args={"city": "Tokyo"}, |
| 66 | single_tool_call_expected_content=None, |
| 67 | parallel_tool_calls_count=2, |
| 68 | parallel_tool_calls_names=["get_weather", "get_time"], |
| 69 | # xfail markers |
| 70 | xfail_streaming={ |
| 71 | "test_surrounding_text": ( |
| 72 | "Granite 20B FC streaming requires <function_call> at start" |
| 73 | ), |
| 74 | }, |
| 75 | xfail_nonstreaming={}, |
| 76 | ) |