Skip to content

feat(provider): add openai chat format for new provider#18

Merged
bzp2010 merged 2 commits intomainfrom
bzp/feat-new-gateway-oai-cf
Apr 6, 2026
Merged

feat(provider): add openai chat format for new provider#18
bzp2010 merged 2 commits intomainfrom
bzp/feat-new-gateway-oai-cf

Conversation

@bzp2010
Copy link
Copy Markdown
Collaborator

@bzp2010 bzp2010 commented Apr 6, 2026

As the 4th part of a major refactoring of the provider, add ChatFormat for OpenAI chat completions.

Summary by CodeRabbit

  • New Features

    • Added OpenAI Chat format support in the gateway: full request/response handling and hub-style streaming (native provider streaming is intentionally not supported).
  • Documentation

    • Clarified that the OpenAI Chat format acts as an identity mapping for hub requests/responses/streamed chunks and does not provide a separate native-bypass.
  • Tests

    • Added tests validating request/response and streaming round-trips and native-stream rejection.

Copilot AI review requested due to automatic review settings April 6, 2026 16:30
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 6, 2026

📝 Walkthrough

Walkthrough

Adds a new OpenAI chat gateway format (OpenAIChatFormat) that maps OpenAI chat request/response and streaming chunks to the hub representation (identity mapping), registers it under gateway::formats, and documents that it provides no separate native-bypass escape hatch.

Changes

Cohort / File(s) Summary
Documentation
docs/internals/llm-types.md
Clarified that OpenAIChatFormat implements ChatFormat as an identity mapping for the hub protocol and does not provide a separate native-bypass/escape hatch.
Gateway Formats Module
src/gateway/formats/mod.rs, src/gateway/formats/openai/mod.rs
Added formats module and OpenAIChatFormat implementation: identity bridging of ChatCompletionRequest/ChatCompletionResponse, streaming detection via req.stream, model extraction from req.model, hub request/response cloning, chunk passthrough with JSON serialization, explicit absence of native streaming support (returns GatewayError::NativeNotSupported), plus tests for round-trips and streaming behavior.
Gateway Module Declaration
src/gateway/mod.rs
Exported new public formats submodule to expose gateway formats at the gateway module level.

Sequence Diagram

sequenceDiagram
    actor Client
    participant OCF as OpenAIChatFormat
    participant Hub

    Client->>OCF: ChatCompletionRequest
    activate OCF
    OCF->>OCF: extract model (req.model)
    OCF->>OCF: determine stream (req.stream)
    OCF->>Hub: forward cloned hub request
    Hub-->>OCF: ChatCompletionResponse
    OCF->>OCF: clone response for client
    OCF-->>Client: ChatCompletionResponse
    deactivate OCF

    alt Streaming (req.stream = true)
        Client->>OCF: streaming request
        activate OCF
        OCF->>Hub: forward hub stream subscription
        Hub-->>OCF: ChatCompletionChunk
        OCF->>OCF: serialize chunk (serde_json)
        OCF-->>Client: serialized chunk
        deactivate OCF
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.78% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
E2e Test Quality Review ⚠️ Warning PR contains only unit tests with mocked data, lacking E2E tests for complete business flow and uses .expect() in serialize_chunk_payload() instead of proper error handling. Add E2E tests exercising full request lifecycle and replace .expect() with proper Result-based error handling in serialize_chunk_payload().
✅ 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 clearly describes the main change: adding OpenAI chat format implementation as part of the provider refactoring. It accurately reflects the core work shown in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bzp/feat-new-gateway-oai-cf

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

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (3)
src/gateway/formats/openai/mod.rs (1)

10-10: Add rustdoc for public OpenAIChatFormat.

Line 10 declares a public struct without /// documentation. Please add a short API-facing description.

Suggested patch
+/// ChatFormat identity adapter for OpenAI Chat Completions (hub format).
 pub struct OpenAIChatFormat;

As per coding guidelines, "Use /// documentation comments on public items".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/gateway/formats/openai/mod.rs` at line 10, Add a Rust doc comment for the
public struct OpenAIChatFormat by inserting a brief /// comment immediately
above pub struct OpenAIChatFormat that describes its purpose and intended use in
the OpenAI message/formatting layer (e.g., that it represents the chat
output/input format adapter for OpenAI-compatible models), following the
project's documentation style for public items.
src/gateway/formats/mod.rs (1)

1-3: Document public formats exports.

Lines 1 and 3 expose public API surface; add /// comments so generated docs describe the module and re-exported type.

Suggested patch
+/// OpenAI chat format adapter.
 pub mod openai;
 
+/// OpenAI ChatFormat implementation used by gateway format dispatch.
 pub use openai::OpenAIChatFormat;

As per coding guidelines, "Use /// documentation comments on public items".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/gateway/formats/mod.rs` around lines 1 - 3, Add documentation comments
for the public module and re-export: add a module-level /// doc comment above
pub mod openai describing the purpose of the formats module, and add a /// doc
comment above the pub use openai::OpenAIChatFormat re-export that explains what
OpenAIChatFormat represents and when to use it; target the pub mod openai
declaration and the pub use openai::OpenAIChatFormat line so generated docs
include descriptive text for these public API items.
src/gateway/mod.rs (1)

2-2: Add rustdoc for the new public module export.

Line 2 introduces a public module without a /// doc comment. Please add a short module-level description.

Suggested patch
+/// Chat format adapters and protocol bridges exposed by the gateway.
 pub mod formats;

As per coding guidelines, "Use /// documentation comments on public items".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/gateway/mod.rs` at line 2, Add a short module-level rustdoc comment above
the public export `pub mod formats` describing the purpose of the `formats`
module (e.g., what formats it provides or handles); place a `///` line or two
immediately above `pub mod formats` summarizing its responsibility so the public
module has proper documentation per the coding guidelines.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/gateway/formats/mod.rs`:
- Around line 1-3: Add documentation comments for the public module and
re-export: add a module-level /// doc comment above pub mod openai describing
the purpose of the formats module, and add a /// doc comment above the pub use
openai::OpenAIChatFormat re-export that explains what OpenAIChatFormat
represents and when to use it; target the pub mod openai declaration and the pub
use openai::OpenAIChatFormat line so generated docs include descriptive text for
these public API items.

In `@src/gateway/formats/openai/mod.rs`:
- Line 10: Add a Rust doc comment for the public struct OpenAIChatFormat by
inserting a brief /// comment immediately above pub struct OpenAIChatFormat that
describes its purpose and intended use in the OpenAI message/formatting layer
(e.g., that it represents the chat output/input format adapter for
OpenAI-compatible models), following the project's documentation style for
public items.

In `@src/gateway/mod.rs`:
- Line 2: Add a short module-level rustdoc comment above the public export `pub
mod formats` describing the purpose of the `formats` module (e.g., what formats
it provides or handles); place a `///` line or two immediately above `pub mod
formats` summarizing its responsibility so the public module has proper
documentation per the coding guidelines.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 773bbff2-8db6-40fb-8c02-57aaa10d1eec

📥 Commits

Reviewing files that changed from the base of the PR and between 4e56693 and 534a7d7.

📒 Files selected for processing (4)
  • docs/internals/llm-types.md
  • src/gateway/formats/mod.rs
  • src/gateway/formats/openai/mod.rs
  • src/gateway/mod.rs

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an OpenAIChatFormat implementation of the ChatFormat trait to represent the hub OpenAI Chat Completions format as an identity bridge.

Changes:

  • Exposes a new gateway::formats module from src/gateway/mod.rs.
  • Introduces OpenAIChatFormat (identity request/response/chunk pass-through) with unit tests.
  • Updates internal documentation to describe the OpenAI hub format’s identity bridge behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/gateway/mod.rs Exposes the new formats module from the gateway root.
src/gateway/formats/mod.rs Adds the openai formats module and re-exports OpenAIChatFormat.
src/gateway/formats/openai/mod.rs Implements OpenAIChatFormat + unit tests for identity behavior.
docs/internals/llm-types.md Documents OpenAIChatFormat as the identity hub format implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
src/gateway/formats/openai/mod.rs (1)

10-10: Add documentation for the public struct.

Per coding guidelines, public items should have /// documentation comments explaining their purpose.

📝 Suggested documentation
+/// Chat format implementation for OpenAI's chat completions API.
+///
+/// Acts as an identity mapping since the hub format is based on OpenAI's schema.
 pub struct OpenAIChatFormat;

As per coding guidelines: "Use /// documentation comments on public items".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/gateway/formats/openai/mod.rs` at line 10, Add a /// documentation
comment above the public struct OpenAIChatFormat describing its purpose and
intended usage (e.g., that it represents the OpenAI chat message format or
formatter used by the gateway), any important behavior or invariants, and a
brief example or pointer to related types if applicable; place this doc comment
directly above the OpenAIChatFormat declaration to satisfy the public-item
documentation guideline.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/gateway/formats/openai/mod.rs`:
- Around line 108-127: The test request_round_trips_through_hub_identity uses a
JSON with an extraneous "custom_provider_field" that is silently dropped when
deserializing into ChatCompletionRequest; remove the "custom_provider_field"
from the test JSON (or alternatively add an explicit test path that verifies
preservation if you intend to test passthrough) so that OpenAIChatFormat::to_hub
is tested accurately against the actual ChatCompletionRequest shape.

---

Nitpick comments:
In `@src/gateway/formats/openai/mod.rs`:
- Line 10: Add a /// documentation comment above the public struct
OpenAIChatFormat describing its purpose and intended usage (e.g., that it
represents the OpenAI chat message format or formatter used by the gateway), any
important behavior or invariants, and a brief example or pointer to related
types if applicable; place this doc comment directly above the OpenAIChatFormat
declaration to satisfy the public-item documentation guideline.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 17167f36-da13-4398-b6d8-489314ae4c0f

📥 Commits

Reviewing files that changed from the base of the PR and between 534a7d7 and f2df725.

📒 Files selected for processing (1)
  • src/gateway/formats/openai/mod.rs

@bzp2010 bzp2010 merged commit 7200e16 into main Apr 6, 2026
10 checks passed
@bzp2010 bzp2010 deleted the bzp/feat-new-gateway-oai-cf branch April 6, 2026 16:58
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.

2 participants