|
1 | 1 | # SPDX-License-Identifier: Apache-2.0
|
2 | 2 |
|
3 | 3 | import pytest
|
4 |
| -from mistral_common.protocol.instruct.messages import UserMessage |
| 4 | +from mistral_common.protocol.instruct.messages import (AssistantMessage, |
| 5 | + ToolMessage, |
| 6 | + UserMessage) |
5 | 7 | from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
6 |
| -from mistral_common.protocol.instruct.tool_calls import Function, Tool |
| 8 | +from mistral_common.protocol.instruct.tool_calls import (Function, |
| 9 | + FunctionCall, Tool, |
| 10 | + ToolCall) |
7 | 11 |
|
8 | 12 | from vllm.transformers_utils.tokenizers.mistral import (
|
9 | 13 | make_mistral_chat_completion_request)
|
10 | 14 |
|
11 | 15 |
|
12 |
| -# yapf: enable |
13 | 16 | @pytest.mark.parametrize(
|
14 | 17 | "openai_request,expected_mistral_request",
|
15 | 18 | [(
|
|
78 | 81 | )
|
79 | 82 | def test_make_mistral_chat_completion_request(openai_request,
|
80 | 83 | expected_mistral_request):
|
81 |
| - assert (make_mistral_chat_completion_request( |
82 |
| - openai_request["messages"], |
83 |
| - openai_request["tools"]) == expected_mistral_request) |
| 84 | + actual_request = make_mistral_chat_completion_request( |
| 85 | + openai_request["messages"], openai_request["tools"]) |
| 86 | + assert actual_request == expected_mistral_request |
| 87 | + |
| 88 | + |
| 89 | +# Tool use with list content and reasoning_content |
| 90 | +@pytest.mark.parametrize("openai_request,expected_mistral_request", [( |
| 91 | + { |
| 92 | + "messages": [ |
| 93 | + { |
| 94 | + "role": "user", |
| 95 | + "content": "What's the weather in Paris?", |
| 96 | + }, |
| 97 | + { |
| 98 | + "role": |
| 99 | + "assistant", |
| 100 | + "reasoning_content": |
| 101 | + None, |
| 102 | + "content": |
| 103 | + None, |
| 104 | + "tool_calls": [{ |
| 105 | + "id": "call123", |
| 106 | + "type": "function", |
| 107 | + "function": { |
| 108 | + "name": "get_weather", |
| 109 | + "arguments": '{"city": "Paris"}', |
| 110 | + }, |
| 111 | + }], |
| 112 | + }, |
| 113 | + { |
| 114 | + "role": "tool", |
| 115 | + "content": [{ |
| 116 | + "type": "text", |
| 117 | + "text": "Rainy" |
| 118 | + }], |
| 119 | + "name": "get_weather", |
| 120 | + "tool_call_id": "call123", |
| 121 | + }, |
| 122 | + ], |
| 123 | + "tools": [{ |
| 124 | + "type": "function", |
| 125 | + "function": { |
| 126 | + "name": "get_weather", |
| 127 | + "description": "Gets the current weather in a city.", |
| 128 | + "parameters": { |
| 129 | + "type": "object", |
| 130 | + "properties": { |
| 131 | + "city": { |
| 132 | + "type": "string", |
| 133 | + "description": "The city name" |
| 134 | + } |
| 135 | + }, |
| 136 | + "required": ["city"], |
| 137 | + }, |
| 138 | + }, |
| 139 | + }], |
| 140 | + }, |
| 141 | + ChatCompletionRequest( |
| 142 | + messages=[ |
| 143 | + UserMessage(content="What's the weather in Paris?"), |
| 144 | + AssistantMessage( |
| 145 | + content=None, |
| 146 | + tool_calls=[ |
| 147 | + ToolCall( |
| 148 | + id="call123", |
| 149 | + function=FunctionCall( |
| 150 | + name="get_weather", |
| 151 | + arguments='{"city": "Paris"}', |
| 152 | + ), |
| 153 | + ) |
| 154 | + ], |
| 155 | + ), |
| 156 | + ToolMessage( |
| 157 | + content="Rainy", |
| 158 | + tool_call_id="call123", |
| 159 | + name="get_weather", |
| 160 | + ), |
| 161 | + ], |
| 162 | + tools=[ |
| 163 | + Tool( |
| 164 | + type="function", |
| 165 | + function=Function( |
| 166 | + name="get_weather", |
| 167 | + description="Gets the current weather in a city.", |
| 168 | + parameters={ |
| 169 | + "type": "object", |
| 170 | + "properties": { |
| 171 | + "city": { |
| 172 | + "type": "string", |
| 173 | + "description": "The city name" |
| 174 | + } |
| 175 | + }, |
| 176 | + "required": ["city"], |
| 177 | + }, |
| 178 | + ), |
| 179 | + ) |
| 180 | + ], |
| 181 | + ), |
| 182 | +)]) |
| 183 | +def test_make_mistral_chat_completion_request_list_content( |
| 184 | + openai_request, expected_mistral_request): |
| 185 | + actual_request = make_mistral_chat_completion_request( |
| 186 | + openai_request["messages"], openai_request["tools"]) |
| 187 | + assert actual_request == expected_mistral_request |
0 commit comments