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
[Misc] Use helper function to generate dummy messages in OpenAI MM tests (#26875)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
Cyrus Leung committed
Oct 15, 2025 at 15:17 UTC
b8a45721576e8cc0a0a6b8f82e7aec423068dc64
3 files changed
+91
-176
tests/entrypoints/openai/test_audio.py
+26
-43
@@ -53,22 +53,35 @@ def base64_encoded_audio() -> dict[str, str]:
53
}
54
55
56
-@pytest.mark.asyncio
57
-@pytest.mark.parametrize("model_name", [MODEL_NAME])
58
-@pytest.mark.parametrize("audio_url", [TEST_AUDIO_URLS[0]])
59
-async def test_single_chat_session_audio(
60
- client: openai.AsyncOpenAI, model_name: str, audio_url: str
56
+def dummy_messages_from_audio_url(
57
+ audio_urls: str | list[str],
58
+ content_text: str = "What's happening in this audio?",
59
):
62
- messages = [
60
+ if isinstance(audio_urls, str):
61
+ audio_urls = [audio_urls]
62
+
63
+ return [
64
{
65
"role": "user",
66
"content": [
66
- {"type": "audio_url", "audio_url": {"url": audio_url}},
67
- {"type": "text", "text": "What's happening in this audio?"},
67
+ *(
68
+ {"type": "audio_url", "audio_url": {"url": audio_url}}
69
+ for audio_url in audio_urls
70
+ ),
71
+ {"type": "text", "text": content_text},
72
],
73
}
74
]
75
76
+
77
+@pytest.mark.asyncio
78
+@pytest.mark.parametrize("model_name", [MODEL_NAME])
79
+@pytest.mark.parametrize("audio_url", [TEST_AUDIO_URLS[0]])
80
+async def test_single_chat_session_audio(
81
+ client: openai.AsyncOpenAI, model_name: str, audio_url: str
82
+):
83
+ messages = dummy_messages_from_audio_url(audio_url)
84
+
85
# test single completion
86
chat_completion = await client.chat.completions.create(
87
model=model_name,
@@ -138,20 +151,9 @@ async def test_single_chat_session_audio_base64encoded(
151
audio_url: str,
152
base64_encoded_audio: dict[str, str],
153
):
141
- messages = [
142
- {
143
- "role": "user",
144
- "content": [
145
- {
146
- "type": "audio_url",
147
- "audio_url": {
148
- "url": f"data:audio/wav;base64,{base64_encoded_audio[audio_url]}" # noqa: E501
149
- },
150
- },
151
- {"type": "text", "text": "What's happening in this audio?"},
152
- ],
153
- }
154
- ]
154
+ messages = dummy_messages_from_audio_url(
155
+ f"data:audio/wav;base64,{base64_encoded_audio[audio_url]}"
156
+ )
157
158
# test single completion
159
chat_completion = await client.chat.completions.create(
@@ -252,15 +254,7 @@ async def test_single_chat_session_input_audio(
254
async def test_chat_streaming_audio(
255
client: openai.AsyncOpenAI, model_name: str, audio_url: str
256
):
255
- messages = [
256
- {
257
- "role": "user",
258
- "content": [
259
- {"type": "audio_url", "audio_url": {"url": audio_url}},
260
- {"type": "text", "text": "What's happening in this audio?"},
261
- ],
262
- }
263
- ]
257
+ messages = dummy_messages_from_audio_url(audio_url)
258
259
# test single completion
260
chat_completion = await client.chat.completions.create(
@@ -365,18 +359,7 @@ async def test_chat_streaming_input_audio(
359
async def test_multi_audio_input(
360
client: openai.AsyncOpenAI, model_name: str, audio_urls: list[str]
361
):
368
- messages = [
369
- {
370
- "role": "user",
371
- "content": [
372
- *(
373
- {"type": "audio_url", "audio_url": {"url": audio_url}}
374
- for audio_url in audio_urls
375
- ),
376
- {"type": "text", "text": "What's happening in this audio?"},
377
- ],
378
- }
379
- ]
362
+ messages = dummy_messages_from_audio_url(audio_urls)
363
364
if len(audio_urls) > MAXIMUM_AUDIOS:
365
with pytest.raises(openai.BadRequestError): # test multi-audio input
tests/entrypoints/openai/test_video.py
+31
-66
@@ -55,22 +55,35 @@ def base64_encoded_video() -> dict[str, str]:
55
}
56
57
58
-@pytest.mark.asyncio
59
-@pytest.mark.parametrize("model_name", [MODEL_NAME])
60
-@pytest.mark.parametrize("video_url", TEST_VIDEO_URLS)
61
-async def test_single_chat_session_video(
62
- client: openai.AsyncOpenAI, model_name: str, video_url: str
58
+def dummy_messages_from_video_url(
59
+ video_urls: str | list[str],
60
+ content_text: str = "What's in this video?",
61
):
64
- messages = [
62
+ if isinstance(video_urls, str):
63
+ video_urls = [video_urls]
64
+
65
+ return [
66
{
67
"role": "user",
68
"content": [
68
- {"type": "video_url", "video_url": {"url": video_url}},
69
- {"type": "text", "text": "What's in this video?"},
69
+ *(
70
+ {"type": "video_url", "video_url": {"url": video_url}}
71
+ for video_url in video_urls
72
+ ),
73
+ {"type": "text", "text": content_text},
74
],
75
}
76
]
77
78
+
79
+@pytest.mark.asyncio
80
+@pytest.mark.parametrize("model_name", [MODEL_NAME])
81
+@pytest.mark.parametrize("video_url", TEST_VIDEO_URLS)
82
+async def test_single_chat_session_video(
83
+ client: openai.AsyncOpenAI, model_name: str, video_url: str
84
+):
85
+ messages = dummy_messages_from_video_url(video_url)
86
+
87
# test single completion
88
chat_completion = await client.chat.completions.create(
89
model=model_name,
@@ -137,15 +150,7 @@ async def test_error_on_invalid_video_url_type(
150
async def test_single_chat_session_video_beamsearch(
151
client: openai.AsyncOpenAI, model_name: str, video_url: str
152
):
140
- messages = [
141
- {
142
- "role": "user",
143
- "content": [
144
- {"type": "video_url", "video_url": {"url": video_url}},
145
- {"type": "text", "text": "What's in this video?"},
146
- ],
147
- }
148
- ]
153
+ messages = dummy_messages_from_video_url(video_url)
154
155
chat_completion = await client.chat.completions.create(
156
model=model_name,
@@ -172,20 +177,9 @@ async def test_single_chat_session_video_base64encoded(
177
video_url: str,
178
base64_encoded_video: dict[str, str],
179
):
175
- messages = [
176
- {
177
- "role": "user",
178
- "content": [
179
- {
180
- "type": "video_url",
181
- "video_url": {
182
- "url": f"data:video/jpeg;base64,{base64_encoded_video[video_url]}" # noqa: E501
183
- },
184
- },
185
- {"type": "text", "text": "What's in this video?"},
186
- ],
187
- }
188
- ]
180
+ messages = dummy_messages_from_video_url(
181
+ f"data:video/jpeg;base64,{base64_encoded_video[video_url]}"
182
+ )
183
184
# test single completion
185
chat_completion = await client.chat.completions.create(
@@ -231,20 +225,10 @@ async def test_single_chat_session_video_base64encoded_beamsearch(
225
video_url: str,
226
base64_encoded_video: dict[str, str],
227
):
234
- messages = [
235
- {
236
- "role": "user",
237
- "content": [
238
- {
239
- "type": "video_url",
240
- "video_url": {
241
- "url": f"data:video/jpeg;base64,{base64_encoded_video[video_url]}" # noqa: E501
242
- },
243
- },
244
- {"type": "text", "text": "What's in this video?"},
245
- ],
246
- }
247
- ]
228
+ messages = dummy_messages_from_video_url(
229
+ f"data:video/jpeg;base64,{base64_encoded_video[video_url]}"
230
+ )
231
+
232
chat_completion = await client.chat.completions.create(
233
model=model_name,
234
messages=messages,
@@ -265,15 +249,7 @@ async def test_single_chat_session_video_base64encoded_beamsearch(
249
async def test_chat_streaming_video(
250
client: openai.AsyncOpenAI, model_name: str, video_url: str
251
):
268
- messages = [
269
- {
270
- "role": "user",
271
- "content": [
272
- {"type": "video_url", "video_url": {"url": video_url}},
273
- {"type": "text", "text": "What's in this video?"},
274
- ],
275
- }
276
- ]
252
+ messages = dummy_messages_from_video_url(video_url)
253
254
# test single completion
255
chat_completion = await client.chat.completions.create(
@@ -318,18 +294,7 @@ async def test_chat_streaming_video(
294
async def test_multi_video_input(
295
client: openai.AsyncOpenAI, model_name: str, video_urls: list[str]
296
):
321
- messages = [
322
- {
323
- "role": "user",
324
- "content": [
325
- *(
326
- {"type": "video_url", "video_url": {"url": video_url}}
327
- for video_url in video_urls
328
- ),
329
- {"type": "text", "text": "What's in this video?"},
330
- ],
331
- }
332
- ]
297
+ messages = dummy_messages_from_video_url(video_urls)
298
299
if len(video_urls) > MAXIMUM_VIDEOS:
300
with pytest.raises(openai.BadRequestError): # test multi-video input
tests/entrypoints/openai/test_vision.py
+34
-67
@@ -78,6 +78,27 @@ def base64_encoded_image(local_asset_server) -> dict[str, str]:
78
}
79
80
81
+def dummy_messages_from_image_url(
82
+ image_urls: str | list[str],
83
+ content_text: str = "What's in this image?",
84
+):
85
+ if isinstance(image_urls, str):
86
+ image_urls = [image_urls]
87
+
88
+ return [
89
+ {
90
+ "role": "user",
91
+ "content": [
92
+ *(
93
+ {"type": "image_url", "image_url": {"url": image_url}}
94
+ for image_url in image_urls
95
+ ),
96
+ {"type": "text", "text": content_text},
97
+ ],
98
+ }
99
+ ]
100
+
101
+
102
def get_hf_prompt_tokens(model_name, content, image_url):
103
processor = AutoProcessor.from_pretrained(
104
model_name, trust_remote_code=True, num_crops=4
@@ -107,15 +128,7 @@ async def test_single_chat_session_image(
128
client: openai.AsyncOpenAI, model_name: str, image_url: str
129
):
130
content_text = "What's in this image?"
110
- messages = [
111
- {
112
- "role": "user",
113
- "content": [
114
- {"type": "image_url", "image_url": {"url": image_url}},
115
- {"type": "text", "text": content_text},
116
- ],
117
- }
118
- ]
131
+ messages = dummy_messages_from_image_url(image_url, content_text)
132
133
max_completion_tokens = 10
134
# test single completion
@@ -188,15 +201,8 @@ async def test_error_on_invalid_image_url_type(
201
async def test_single_chat_session_image_beamsearch(
202
client: openai.AsyncOpenAI, model_name: str, image_url: str
203
):
191
- messages = [
192
- {
193
- "role": "user",
194
- "content": [
195
- {"type": "image_url", "image_url": {"url": image_url}},
196
- {"type": "text", "text": "What's in this image?"},
197
- ],
198
- }
199
- ]
204
+ content_text = "What's in this image?"
205
+ messages = dummy_messages_from_image_url(image_url, content_text)
206
207
chat_completion = await client.chat.completions.create(
208
model=model_name,
@@ -226,20 +232,10 @@ async def test_single_chat_session_image_base64encoded(
232
base64_encoded_image: dict[str, str],
233
):
234
content_text = "What's in this image?"
229
- messages = [
230
- {
231
- "role": "user",
232
- "content": [
233
- {
234
- "type": "image_url",
235
- "image_url": {
236
- "url": f"data:image/jpeg;base64,{base64_encoded_image[raw_image_url]}" # noqa: E501
237
- },
238
- },
239
- {"type": "text", "text": content_text},
240
- ],
241
- }
242
- ]
235
+ messages = dummy_messages_from_image_url(
236
+ f"data:image/jpeg;base64,{base64_encoded_image[raw_image_url]}",
237
+ content_text,
238
+ )
239
240
max_completion_tokens = 10
241
# test single completion
@@ -293,20 +289,10 @@ async def test_single_chat_session_image_base64encoded_beamsearch(
289
raw_image_url = TEST_IMAGE_ASSETS[image_idx]
290
expected_res = EXPECTED_MM_BEAM_SEARCH_RES[image_idx]
291
296
- messages = [
297
- {
298
- "role": "user",
299
- "content": [
300
- {
301
- "type": "image_url",
302
- "image_url": {
303
- "url": f"data:image/jpeg;base64,{base64_encoded_image[raw_image_url]}" # noqa: E501
304
- },
305
- },
306
- {"type": "text", "text": "What's in this image?"},
307
- ],
308
- }
309
- ]
292
+ messages = dummy_messages_from_image_url(
293
+ f"data:image/jpeg;base64,{base64_encoded_image[raw_image_url]}"
294
+ )
295
+
296
chat_completion = await client.chat.completions.create(
297
model=model_name,
298
messages=messages,
@@ -326,15 +312,7 @@ async def test_single_chat_session_image_base64encoded_beamsearch(
312
async def test_chat_streaming_image(
313
client: openai.AsyncOpenAI, model_name: str, image_url: str
314
):
329
- messages = [
330
- {
331
- "role": "user",
332
- "content": [
333
- {"type": "image_url", "image_url": {"url": image_url}},
334
- {"type": "text", "text": "What's in this image?"},
335
- ],
336
- }
337
- ]
315
+ messages = dummy_messages_from_image_url(image_url)
316
317
# test single completion
318
chat_completion = await client.chat.completions.create(
@@ -381,18 +359,7 @@ async def test_chat_streaming_image(
359
async def test_multi_image_input(
360
client: openai.AsyncOpenAI, model_name: str, image_urls: list[str]
361
):
384
- messages = [
385
- {
386
- "role": "user",
387
- "content": [
388
- *(
389
- {"type": "image_url", "image_url": {"url": image_url}}
390
- for image_url in image_urls
391
- ),
392
- {"type": "text", "text": "What's in this image?"},
393
- ],
394
- }
395
- ]
362
+ messages = dummy_messages_from_image_url(image_urls)
363
364
if len(image_urls) > MAXIMUM_IMAGES:
365
with pytest.raises(openai.BadRequestError): # test multi-image input