@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 720d3cd0f0
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 14, 05:30 UTC

[CI] fix ruff format (#26579)

Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>

Chauncey committed Oct 10, 2025 at 18:02 UTC 720d3cd0f05b6f4b7df6a0a70a64b551401b9526
2 files changed +84 -88
tests/entrypoints/openai/test_serving_chat.py
+80 -86
@@ -208,51 +208,49 @@ async def test_gpt_oss_multi_turn_chat(gptoss_client: OpenAI, with_tool_parser:
208
209
210 @pytest.mark.asyncio
211 -async def test_gpt_oss_tool_message_array_content(gptoss_client: OpenAI,
212 - with_tool_parser: bool):
211 +async def test_gpt_oss_tool_message_array_content(
212 + gptoss_client: OpenAI, with_tool_parser: bool
213 +):
214 """Test that tool messages support both string and array content formats."""
215 if not with_tool_parser:
216 pytest.skip("skip non-tool for array content tests")
217
217 - tools = [{
218 - "type": "function",
219 - "function": {
220 - "name": "get_weather",
221 - "description": "Get the current weather in a given location",
222 - "parameters": {
223 - "type": "object",
224 - "properties": {
225 - "city": {
226 - "type": "string"
227 - },
228 - "state": {
229 - "type": "string"
218 + tools = [
219 + {
220 + "type": "function",
221 + "function": {
222 + "name": "get_weather",
223 + "description": "Get the current weather in a given location",
224 + "parameters": {
225 + "type": "object",
226 + "properties": {
227 + "city": {"type": "string"},
228 + "state": {"type": "string"},
229 },
230 + "required": ["city", "state"],
231 },
232 - "required": ["city", "state"],
232 },
234 - },
235 - }]
233 + }
234 + ]
235
236 # Test 1: Tool message with string content
238 - messages_string = [{
239 - "role": "user",
240 - "content": "What's the weather in Paris?"
241 - }, {
242 - "role":
243 - "assistant",
244 - "tool_calls": [{
245 - "id": "call_123",
246 - "type": "function",
247 - "function": {
248 - "name": "get_weather",
249 - "arguments": '{"city": "Paris", "state": "TX"}'
250 - }
251 - }]
252 - }, {
253 - "role": "tool",
254 - "content": "The weather in Paris, TX is sunny, 22°C"
255 - }]
237 + messages_string = [
238 + {"role": "user", "content": "What's the weather in Paris?"},
239 + {
240 + "role": "assistant",
241 + "tool_calls": [
242 + {
243 + "id": "call_123",
244 + "type": "function",
245 + "function": {
246 + "name": "get_weather",
247 + "arguments": '{"city": "Paris", "state": "TX"}',
248 + },
249 + }
250 + ],
251 + },
252 + {"role": "tool", "content": "The weather in Paris, TX is sunny, 22°C"},
253 + ]
254
255 response_string = await gptoss_client.chat.completions.create(
256 model=GPT_OSS_MODEL_NAME,
@@ -265,28 +263,28 @@ async def test_gpt_oss_tool_message_array_content(gptoss_client: OpenAI,
263 assert response_string.choices[0].message is not None
264
265 # Test 2: Tool message with array content
268 - messages_array = [{
269 - "role": "user",
270 - "content": "What's the weather in Dallas?"
271 - }, {
272 - "role":
273 - "assistant",
274 - "tool_calls": [{
275 - "id": "call_456",
276 - "type": "function",
277 - "function": {
278 - "name": "get_weather",
279 - "arguments": '{"city": "Dallas", "state": "TX"}'
280 - }
281 - }]
282 - }, {
283 - "role":
284 - "tool",
285 - "content": [{
286 - "type": "text",
287 - "text": "f2e897a7-2705-4337-8193-2a8f57b81618"
288 - }]
289 - }]
266 + messages_array = [
267 + {"role": "user", "content": "What's the weather in Dallas?"},
268 + {
269 + "role": "assistant",
270 + "tool_calls": [
271 + {
272 + "id": "call_456",
273 + "type": "function",
274 + "function": {
275 + "name": "get_weather",
276 + "arguments": '{"city": "Dallas", "state": "TX"}',
277 + },
278 + }
279 + ],
280 + },
281 + {
282 + "role": "tool",
283 + "content": [
284 + {"type": "text", "text": "f2e897a7-2705-4337-8193-2a8f57b81618"}
285 + ],
286 + },
287 + ]
288
289 response_array = await gptoss_client.chat.completions.create(
290 model=GPT_OSS_MODEL_NAME,
@@ -299,34 +297,30 @@ async def test_gpt_oss_tool_message_array_content(gptoss_client: OpenAI,
297 assert response_array.choices[0].message is not None
298
299 # Test 3: Tool message with multiple array content items
302 - messages_multi_array = [{
303 - "role": "user",
304 - "content": "Search for information"
305 - }, {
306 - "role":
307 - "assistant",
308 - "tool_calls": [{
309 - "id": "call_789",
310 - "type": "function",
311 - "function": {
312 - "name": "get_weather",
313 - "arguments": '{"city": "Austin", "state": "TX"}'
314 - }
315 - }]
316 - }, {
317 - "role":
318 - "tool",
319 - "content": [{
320 - "type": "text",
321 - "text": "Weather data: "
322 - }, {
323 - "type": "text",
324 - "text": "Austin, TX - Partly cloudy, 25°C"
325 - }, {
326 - "type": "text",
327 - "text": " with 60% humidity"
328 - }]
329 - }]
300 + messages_multi_array = [
301 + {"role": "user", "content": "Search for information"},
302 + {
303 + "role": "assistant",
304 + "tool_calls": [
305 + {
306 + "id": "call_789",
307 + "type": "function",
308 + "function": {
309 + "name": "get_weather",
310 + "arguments": '{"city": "Austin", "state": "TX"}',
311 + },
312 + }
313 + ],
314 + },
315 + {
316 + "role": "tool",
317 + "content": [
318 + {"type": "text", "text": "Weather data: "},
319 + {"type": "text", "text": "Austin, TX - Partly cloudy, 25°C"},
320 + {"type": "text", "text": " with 60% humidity"},
321 + ],
322 + },
323 + ]
324
325 response_multi_array = await gptoss_client.chat.completions.create(
326 model=GPT_OSS_MODEL_NAME,
vllm/entrypoints/harmony_utils.py
+4 -2
@@ -260,8 +260,10 @@ def parse_chat_input(chat_msg) -> list[Message]:
260 # Handle array format for tool message content
261 # by concatenating all text parts.
262 content = "".join(
263 - item.get("text", "") for item in content
264 - if isinstance(item, dict) and item.get("type") == "text")
263 + item.get("text", "")
264 + for item in content
265 + if isinstance(item, dict) and item.get("type") == "text"
266 + )
267
268 msg = Message.from_author_and_content(
269 Author.new(Role.TOOL, f"functions.{name}"), content