Skip to content

Conversation

nv-guomingz
Copy link
Collaborator

@nv-guomingz nv-guomingz commented Jul 24, 2025

It's a clean version of #5957 and #6197

Summary by CodeRabbit

  • New Features

    • Added support for a new "json" response format, allowing responses to be constrained by a user-provided JSON schema.
    • Enhanced chat completion to validate and generate responses matching specified JSON schemas.
  • Tests

    • Introduced new tests to verify JSON response format functionality, including schema validation and multi-turn chat scenarios.
    • Updated test configurations to include the new JSON response format tests.

@nv-guomingz nv-guomingz requested review from syuoni and LinPoly July 24, 2025 05:43
Copy link
Contributor

coderabbitai bot commented Jul 24, 2025

📝 Walkthrough

"""

Walkthrough

The changes introduce support for a new "json" response format in the OpenAI protocol implementation, requiring a schema for guided decoding. This includes extending the protocol model, updating decoding parameter logic, and adding comprehensive integration and unit tests to validate the new feature, including schema-constrained JSON output from the language model.

Changes

File(s) Change Summary
tensorrt_llm/serve/openai_protocol.py Added "json" as allowed ResponseFormat type, new optional schema field, updated decoding logic and doc.
tests/unittest/llmapi/apps/_test_openai_chat_json.py New test module: fixtures and test for schema-constrained JSON chat completions.
tests/integration/defs/test_e2e.py Added integration test runner for the new OpenAI chat JSON example.
tests/integration/test_lists/test-db/l0_a10.yml Registered new test in the l0_a10 integration test suite.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant OpenAIProtocol
    participant Model

    Client->>OpenAIProtocol: CompletionRequest(response_format={"type": "json", "schema": ...})
    OpenAIProtocol->>OpenAIProtocol: Validate schema presence
    OpenAIProtocol->>Model: GuidedDecodingParams(json=schema)
    Model-->>OpenAIProtocol: Generated JSON response
    OpenAIProtocol-->>Client: JSON response (validated against schema)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes
"""

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4dc7dff and cec0cc4.

📒 Files selected for processing (4)
  • tensorrt_llm/serve/openai_protocol.py (3 hunks)
  • tests/integration/defs/test_e2e.py (1 hunks)
  • tests/integration/test_lists/test-db/l0_a10.yml (1 hunks)
  • tests/unittest/llmapi/apps/_test_openai_chat_json.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • tests/integration/test_lists/test-db/l0_a10.yml
  • tensorrt_llm/serve/openai_protocol.py
  • tests/unittest/llmapi/apps/_test_openai_chat_json.py
  • tests/integration/defs/test_e2e.py
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nv-guomingz nv-guomingz requested a review from amukkara July 24, 2025 05:44
@nv-guomingz
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12807 [ run ] triggered by Bot

Copy link
Contributor

@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: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 428e340 and 156c571.

📒 Files selected for processing (4)
  • tensorrt_llm/serve/openai_protocol.py (3 hunks)
  • tests/integration/defs/test_e2e.py (1 hunks)
  • tests/integration/test_lists/test-db/l0_a10.yml (1 hunks)
  • tests/unittest/llmapi/apps/_test_openai_chat_json.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
tests/integration/defs/test_e2e.py (1)
tests/integration/defs/conftest.py (3)
  • llm_venv (707-723)
  • test_root (2185-2186)
  • unittest_path (90-91)
tensorrt_llm/serve/openai_protocol.py (1)
tensorrt_llm/sampling_params.py (1)
  • GuidedDecodingParams (14-36)
🪛 Ruff (0.12.2)
tests/unittest/llmapi/apps/_test_openai_chat_json.py

134-134: Undefined name first_message

(F821)

⏰ 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). (1)
  • GitHub Check: Pre-commit Check
🔇 Additional comments (7)
tests/integration/test_lists/test-db/l0_a10.yml (1)

25-25: LGTM! Test addition follows established conventions.

The new test test_openai_chat_json_example is properly placed among other OpenAI chat-related tests and follows the consistent naming pattern used throughout the test suite.

tests/integration/defs/test_e2e.py (1)

1446-1452: LGTM! Function implementation follows established patterns perfectly.

The new test function correctly:

  • Uses the standard llm_venv fixture parameter
  • Constructs the test path using unittest_path() helper function
  • Runs pytest on the appropriate test file _test_openai_chat_json.py
  • Follows the exact same structure as other similar functions like test_openai_chat_structural_tag_example

The placement is logical and consistent with the surrounding code organization.

tensorrt_llm/serve/openai_protocol.py (3)

55-57: LGTM! Clean addition of new JSON schema support.

The addition of "json" to the response format types and the new schema field are well-structured and follow the existing patterns in the class.


146-151: Well-implemented validation and integration.

The new JSON response format handling correctly validates that a schema is provided when required and properly integrates with the GuidedDecodingParams class. The error message is clear and actionable.


215-216: Documentation correctly updated.

The docstring properly reflects the new 'json' response format option alongside the existing supported types.

tests/unittest/llmapi/apps/_test_openai_chat_json.py (2)

19-81: Well-structured test fixtures with proper resource management.

The fixtures follow pytest best practices with appropriate scoping, proper temporary file cleanup, and a well-defined JSON schema for testing. The guided decoding backend configuration correctly uses "xgrammar" and disables the overlap scheduler as required.


84-148: Comprehensive test design for JSON schema validation.

The test effectively validates the new JSON response format feature through multi-turn conversation, proper schema validation using jsonschema, and verification that the model generates distinct responses. The helper function provides good separation of concerns for response creation and validation.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12807 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9542 completed with status: 'FAILURE'

@nv-guomingz nv-guomingz force-pushed the user/guomingz/cherry-pick-5957 branch 2 times, most recently from 182f8c9 to 4dc7dff Compare July 24, 2025 15:50
@coderabbitai coderabbitai bot requested a review from chzblych July 24, 2025 15:50
@nv-guomingz
Copy link
Collaborator Author

/bot run --disable-fail-fast

@nv-guomingz nv-guomingz enabled auto-merge (squash) July 24, 2025 15:51
@tensorrt-cicd
Copy link
Collaborator

PR_Github #12875 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #12875 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9597 completed with status: 'FAILURE'

@nv-guomingz nv-guomingz force-pushed the user/guomingz/cherry-pick-5957 branch from 4dc7dff to c940301 Compare July 25, 2025 12:45
@nv-guomingz nv-guomingz force-pushed the user/guomingz/cherry-pick-5957 branch from c940301 to cec0cc4 Compare July 25, 2025 12:46
@nv-guomingz
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13009 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #13009 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #9713 completed with status: 'SUCCESS'

@nv-guomingz nv-guomingz merged commit b8d4cb8 into NVIDIA:main Jul 25, 2025
3 checks passed
NVShreyas pushed a commit to NVShreyas/TensorRT-LLM that referenced this pull request Jul 28, 2025
Ransiki pushed a commit to Ransiki/TensorRT-LLM that referenced this pull request Jul 29, 2025
lancelly pushed a commit to lancelly/TensorRT-LLM that referenced this pull request Aug 6, 2025
@nv-guomingz nv-guomingz deleted the user/guomingz/cherry-pick-5957 branch September 30, 2025 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants