16
16
MAXIMUM_IMAGES = 2
17
17
18
18
# Test different image extensions (JPG/PNG) and formats (gray/RGB/RGBA)
19
- TEST_IMAGE_URLS = [
20
- "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg" ,
21
- "https://upload.wikimedia.org/wikipedia/commons/f/fa/Grayscale_8bits_palette_sample_image.png" ,
22
- "https://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Venn_diagram_rgb.svg/1280px-Venn_diagram_rgb.svg.png" ,
23
- "https://upload.wikimedia.org/wikipedia/commons/0/0b/RGBA_comp.png" ,
19
+ TEST_IMAGE_ASSETS = [
20
+ "2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg" , # " https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
21
+ "Grayscale_8bits_palette_sample_image.png" , # " https://upload.wikimedia.org/wikipedia/commons/f/fa/Grayscale_8bits_palette_sample_image.png",
22
+ "1280px-Venn_diagram_rgb.svg.png" , # " https://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Venn_diagram_rgb.svg/1280px-Venn_diagram_rgb.svg.png",
23
+ "RGBA_comp.png" , # " https://upload.wikimedia.org/wikipedia/commons/0/0b/RGBA_comp.png",
24
24
]
25
25
26
26
EXPECTED_MM_BEAM_SEARCH_RES = [
@@ -69,10 +69,11 @@ async def client(server):
69
69
70
70
71
71
@pytest .fixture (scope = "session" )
72
- def base64_encoded_image () -> dict [str , str ]:
72
+ def base64_encoded_image (local_asset_server ) -> dict [str , str ]:
73
73
return {
74
- image_url : encode_image_base64 (fetch_image (image_url ))
75
- for image_url in TEST_IMAGE_URLS
74
+ image_asset :
75
+ encode_image_base64 (local_asset_server .get_image_asset (image_asset ))
76
+ for image_asset in TEST_IMAGE_ASSETS
76
77
}
77
78
78
79
@@ -97,7 +98,7 @@ def get_hf_prompt_tokens(model_name, content, image_url):
97
98
98
99
@pytest .mark .asyncio
99
100
@pytest .mark .parametrize ("model_name" , [MODEL_NAME ])
100
- @pytest .mark .parametrize ("image_url" , TEST_IMAGE_URLS )
101
+ @pytest .mark .parametrize ("image_url" , TEST_IMAGE_ASSETS , indirect = True )
101
102
async def test_single_chat_session_image (client : openai .AsyncOpenAI ,
102
103
model_name : str , image_url : str ):
103
104
content_text = "What's in this image?"
@@ -157,7 +158,7 @@ async def test_single_chat_session_image(client: openai.AsyncOpenAI,
157
158
158
159
@pytest .mark .asyncio
159
160
@pytest .mark .parametrize ("model_name" , [MODEL_NAME ])
160
- @pytest .mark .parametrize ("image_url" , TEST_IMAGE_URLS )
161
+ @pytest .mark .parametrize ("image_url" , TEST_IMAGE_ASSETS , indirect = True )
161
162
async def test_error_on_invalid_image_url_type (client : openai .AsyncOpenAI ,
162
163
model_name : str ,
163
164
image_url : str ):
@@ -187,7 +188,7 @@ async def test_error_on_invalid_image_url_type(client: openai.AsyncOpenAI,
187
188
188
189
@pytest .mark .asyncio
189
190
@pytest .mark .parametrize ("model_name" , [MODEL_NAME ])
190
- @pytest .mark .parametrize ("image_url" , TEST_IMAGE_URLS )
191
+ @pytest .mark .parametrize ("image_url" , TEST_IMAGE_ASSETS , indirect = True )
191
192
async def test_single_chat_session_image_beamsearch (client : openai .AsyncOpenAI ,
192
193
model_name : str ,
193
194
image_url : str ):
@@ -223,10 +224,11 @@ async def test_single_chat_session_image_beamsearch(client: openai.AsyncOpenAI,
223
224
224
225
@pytest .mark .asyncio
225
226
@pytest .mark .parametrize ("model_name" , [MODEL_NAME ])
226
- @pytest .mark .parametrize ("image_url" , TEST_IMAGE_URLS )
227
+ @pytest .mark .parametrize ("raw_image_url" , TEST_IMAGE_ASSETS )
228
+ @pytest .mark .parametrize ("image_url" , TEST_IMAGE_ASSETS , indirect = True )
227
229
async def test_single_chat_session_image_base64encoded (
228
- client : openai .AsyncOpenAI , model_name : str , image_url : str ,
229
- base64_encoded_image : dict [str , str ]):
230
+ client : openai .AsyncOpenAI , model_name : str , raw_image_url : str ,
231
+ image_url : str , base64_encoded_image : dict [str , str ]):
230
232
231
233
content_text = "What's in this image?"
232
234
messages = [{
@@ -237,7 +239,7 @@ async def test_single_chat_session_image_base64encoded(
237
239
"type" : "image_url" ,
238
240
"image_url" : {
239
241
"url" :
240
- f"data:image/jpeg;base64,{ base64_encoded_image [image_url ]} "
242
+ f"data:image/jpeg;base64,{ base64_encoded_image [raw_image_url ]} "
241
243
}
242
244
},
243
245
{
@@ -287,12 +289,12 @@ async def test_single_chat_session_image_base64encoded(
287
289
288
290
@pytest .mark .asyncio
289
291
@pytest .mark .parametrize ("model_name" , [MODEL_NAME ])
290
- @pytest .mark .parametrize ("image_idx" , list (range (len (TEST_IMAGE_URLS ))))
292
+ @pytest .mark .parametrize ("image_idx" , list (range (len (TEST_IMAGE_ASSETS ))))
291
293
async def test_single_chat_session_image_base64encoded_beamsearch (
292
294
client : openai .AsyncOpenAI , model_name : str , image_idx : int ,
293
295
base64_encoded_image : dict [str , str ]):
294
296
# NOTE: This test also validates that we pass MM data through beam search
295
- image_url = TEST_IMAGE_URLS [image_idx ]
297
+ raw_image_url = TEST_IMAGE_ASSETS [image_idx ]
296
298
expected_res = EXPECTED_MM_BEAM_SEARCH_RES [image_idx ]
297
299
298
300
messages = [{
@@ -303,7 +305,7 @@ async def test_single_chat_session_image_base64encoded_beamsearch(
303
305
"type" : "image_url" ,
304
306
"image_url" : {
305
307
"url" :
306
- f"data:image/jpeg;base64,{ base64_encoded_image [image_url ]} "
308
+ f"data:image/jpeg;base64,{ base64_encoded_image [raw_image_url ]} "
307
309
}
308
310
},
309
311
{
@@ -326,7 +328,7 @@ async def test_single_chat_session_image_base64encoded_beamsearch(
326
328
327
329
@pytest .mark .asyncio
328
330
@pytest .mark .parametrize ("model_name" , [MODEL_NAME ])
329
- @pytest .mark .parametrize ("image_url" , TEST_IMAGE_URLS )
331
+ @pytest .mark .parametrize ("image_url" , TEST_IMAGE_ASSETS , indirect = True )
330
332
async def test_chat_streaming_image (client : openai .AsyncOpenAI ,
331
333
model_name : str , image_url : str ):
332
334
messages = [{
@@ -385,7 +387,8 @@ async def test_chat_streaming_image(client: openai.AsyncOpenAI,
385
387
@pytest .mark .parametrize ("model_name" , [MODEL_NAME ])
386
388
@pytest .mark .parametrize (
387
389
"image_urls" ,
388
- [TEST_IMAGE_URLS [:i ] for i in range (2 , len (TEST_IMAGE_URLS ))])
390
+ [TEST_IMAGE_ASSETS [:i ] for i in range (2 , len (TEST_IMAGE_ASSETS ))],
391
+ indirect = True )
389
392
async def test_multi_image_input (client : openai .AsyncOpenAI , model_name : str ,
390
393
image_urls : list [str ]):
391
394
0 commit comments