Skip to content

Commit b7cedba

Browse files
authored
feat: add multiframe image input support for OpenAI Chat endpoint (#418)
* add multiframe image input support * test more meaningful batch sizes
1 parent b45b078 commit b7cedba

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

genai-perf/genai_perf/inputs/converters/openai_chat_completions_converter.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ def check_config(self) -> None:
4444
raise GenAIPerfException(
4545
f"The --batch-size-text flag is not supported for {self.config.endpoint.output_format.to_lowercase()}."
4646
)
47-
if self.config.input.image.batch_size != InputDefaults.BATCH_SIZE:
48-
raise GenAIPerfException(
49-
f"The --batch-size-image flag is not supported for {self.config.endpoint.output_format.to_lowercase()}."
50-
)
5147

5248
def convert(
5349
self,

genai-perf/tests/test_converters/test_openai_chat_converter.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,58 @@ def test_convert_multi_modal(self, rows, first_content, second_content) -> None:
346346

347347
assert result == expected_result
348348

349+
@pytest.mark.parametrize(
350+
"batch_size_image",
351+
[
352+
0, # no images
353+
1,
354+
123,
355+
],
356+
)
357+
def test_convert_multi_modal_with_batched_image(self, batch_size_image):
358+
"""
359+
Test multi-modal format of OpenAI Chat API with batched image input payloads
360+
"""
361+
rows = [
362+
{
363+
"text": "hello world",
364+
"image": [f"test_image_{i}" for i in range(batch_size_image)],
365+
},
366+
]
367+
generic_dataset = self.create_generic_dataset(rows)
368+
369+
config = ConfigCommand({"model_name": "test_model"})
370+
config.endpoint.model_selection_strategy = ModelSelectionStrategy.ROUND_ROBIN
371+
config.endpoint.output_format = OutputFormat.OPENAI_MULTIMODAL
372+
config.endpoint.streaming = True
373+
config.input.image.batch_size = batch_size_image
374+
375+
chat_converter = OpenAIChatCompletionsConverter(config)
376+
payload = chat_converter.convert(generic_dataset)
377+
378+
expected_image_contents = [
379+
{
380+
"type": "image_url",
381+
"image_url": {
382+
"url": f"test_image_{i}",
383+
},
384+
}
385+
for i in range(batch_size_image)
386+
]
387+
388+
assert payload["data"][0]["payload"][0]["messages"] == [
389+
{
390+
"role": "user",
391+
"content": [
392+
{
393+
"type": "text",
394+
"text": "hello world",
395+
},
396+
*expected_image_contents,
397+
],
398+
}
399+
]
400+
349401
def test_convert_with_payload_parameters(self):
350402
optional_data = {"session_id": "abcd"}
351403
generic_dataset = self.create_generic_dataset(

0 commit comments

Comments
 (0)