Skip to content

Conversation

@ajcasagrande
Copy link
Contributor

@ajcasagrande ajcasagrande commented Nov 6, 2025

Summary by CodeRabbit

  • Tests
    • Added test coverage for multiple image batch handling in chat completion payloads.
    • Added integration test for image batch sizing validation.

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

Try out this PR

Quick install:

pip install --upgrade --force-reinstall git+https://github.com/ai-dynamo/aiperf.git@ajc/image-batch

Recommended with virtual environment (using uv):

uv venv --python 3.12 && source .venv/bin/activate
uv pip install --upgrade --force-reinstall git+https://github.com/ai-dynamo/aiperf.git@ajc/image-batch

@github-actions github-actions bot added the test label Nov 6, 2025
@ajcasagrande ajcasagrande requested a review from ilana-n November 6, 2025 20:28
@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@coderabbitai
Copy link

coderabbitai bot commented Nov 6, 2025

Walkthrough

Two new test functions were added: one unit test validating that multiple image URLs are correctly formatted in a ChatEndpoint payload, and one integration test verifying image batch sizing behavior and payload structure validation. No existing logic was modified.

Changes

Cohort / File(s) Summary
Unit Tests
tests/endpoints/test_openai_chat_completions.py
New test test_format_payload_with_multiple_images_batch added to validate that ChatEndpoint correctly formats payloads with multiple image URLs within a single message.
Integration Tests
tests/integration/test_multimodal.py
New test test_image_batch_size added to TestMultimodal class to verify image batch sizing with configurable --batch-size-image parameter and validate payload structure contains expected image_url entries per turn.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify assertions in test_format_payload_with_multiple_images_batch correctly validate image URL presence and ordering
  • Confirm test_image_batch_size properly validates batch sizing logic against inputs.json structure

Poem

🐰 Two tests hop through the code today,
One checks images in display,
The other counts the batches right,
More coverage shines so bright,
Testing ensures the path is clear, hooray! ✨

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'test: add tests for image batch size' accurately and concisely describes the main changes—new tests for image batch sizing in both unit and integration test files.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e5194fa and 5268c2e.

📒 Files selected for processing (2)
  • tests/endpoints/test_openai_chat_completions.py (1 hunks)
  • tests/integration/test_multimodal.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-23T03:16:02.685Z
Learnt from: ajcasagrande
Repo: ai-dynamo/aiperf PR: 389
File: src/aiperf/endpoints/openai_chat.py:41-46
Timestamp: 2025-10-23T03:16:02.685Z
Learning: In the aiperf project, the ChatEndpoint at src/aiperf/endpoints/openai_chat.py supports video inputs (supports_videos=True) through custom extensions, even though the standard OpenAI /v1/chat/completions API does not natively support raw video inputs.

Applied to files:

  • tests/endpoints/test_openai_chat_completions.py
🧬 Code graph analysis (2)
tests/endpoints/test_openai_chat_completions.py (3)
tests/conftest.py (1)
  • sample_conversations (317-347)
src/aiperf/endpoints/openai_chat.py (2)
  • ChatEndpoint (27-217)
  • format_payload (48-77)
src/aiperf/common/models/record_models.py (1)
  • RequestInfo (755-808)
tests/integration/test_multimodal.py (3)
tests/integration/conftest.py (3)
  • AIPerfCLI (47-118)
  • aiperf_mock_server (159-236)
  • run (56-90)
tests/integration/models.py (3)
  • AIPerfMockServer (30-41)
  • request_count (159-163)
  • has_input_images (237-239)
tests/aiperf_mock_server/models.py (1)
  • inputs (81-87)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: build (macos-latest, 3.12)
  • GitHub Check: build (macos-latest, 3.11)
  • GitHub Check: integration-tests (macos-latest, 3.12)
  • GitHub Check: build (macos-latest, 3.10)
  • GitHub Check: build (ubuntu-latest, 3.10)
  • GitHub Check: integration-tests (macos-latest, 3.11)
  • GitHub Check: integration-tests (ubuntu-latest, 3.11)
  • GitHub Check: integration-tests (ubuntu-latest, 3.10)
  • GitHub Check: integration-tests (macos-latest, 3.10)
  • GitHub Check: integration-tests (ubuntu-latest, 3.12)
🔇 Additional comments (1)
tests/endpoints/test_openai_chat_completions.py (1)

195-243: LGTM! Well-structured unit test for image batching.

The test correctly validates that multiple image URLs within a single Image object's contents list are properly formatted as separate image_url entries in the payload. The test structure is clear, and the assertions accurately verify the expected OpenAI Chat Completions format.

Comment on lines +111 to +124
for message in messages:
content = message.get("content", [])
if isinstance(content, list):
# Count image_url entries in the content array
image_count = sum(
1
for item in content
if isinstance(item, dict)
and item.get("type") == "image_url"
)
# Each turn should have exactly batch_size images
assert image_count == batch_size, (
f"Expected {batch_size} images per turn, got {image_count}"
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Only assert image count for messages that contain images.

The current logic asserts image_count == batch_size for every message where content is a list. However, not all messages necessarily contain images (e.g., assistant responses or messages with only audio/video). This could cause false failures.

Apply this diff to check only messages with images:

                for message in messages:
                    content = message.get("content", [])
                    if isinstance(content, list):
                        # Count image_url entries in the content array
                        image_count = sum(
                            1
                            for item in content
                            if isinstance(item, dict)
                            and item.get("type") == "image_url"
                        )
-                       # Each turn should have exactly batch_size images
-                       assert image_count == batch_size, (
-                           f"Expected {batch_size} images per turn, got {image_count}"
-                       )
+                       # Each turn with images should have exactly batch_size images
+                       if image_count > 0:
+                           assert image_count == batch_size, (
+                               f"Expected {batch_size} images per turn, got {image_count}"
+                           )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for message in messages:
content = message.get("content", [])
if isinstance(content, list):
# Count image_url entries in the content array
image_count = sum(
1
for item in content
if isinstance(item, dict)
and item.get("type") == "image_url"
)
# Each turn should have exactly batch_size images
assert image_count == batch_size, (
f"Expected {batch_size} images per turn, got {image_count}"
)
for message in messages:
content = message.get("content", [])
if isinstance(content, list):
# Count image_url entries in the content array
image_count = sum(
1
for item in content
if isinstance(item, dict)
and item.get("type") == "image_url"
)
# Each turn with images should have exactly batch_size images
if image_count > 0:
assert image_count == batch_size, (
f"Expected {batch_size} images per turn, got {image_count}"
)
🤖 Prompt for AI Agents
In tests/integration/test_multimodal.py around lines 111 to 124, the test
currently asserts image_count == batch_size for every message whose content is a
list, which fails for turns that don't contain images; change the logic to only
perform the equality assertion when the message actually contains image entries
(e.g., check if any item in content has type "image_url" or simply if
image_count > 0) and skip the assertion for messages with zero image entries so
only image-containing messages are validated against batch_size.

@ajcasagrande ajcasagrande marked this pull request as draft November 10, 2025 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants