feat(provider): add openai chat format for new provider#18
Conversation
📝 WalkthroughWalkthroughAdds a new OpenAI chat gateway format ( Changes
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
src/gateway/formats/openai/mod.rs (1)
10-10: Add rustdoc for publicOpenAIChatFormat.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 publicformatsexports.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
📒 Files selected for processing (4)
docs/internals/llm-types.mdsrc/gateway/formats/mod.rssrc/gateway/formats/openai/mod.rssrc/gateway/mod.rs
There was a problem hiding this comment.
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::formatsmodule fromsrc/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.
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
src/gateway/formats/openai/mod.rs
As the 4th part of a major refactoring of the provider, add ChatFormat for OpenAI chat completions.
Summary by CodeRabbit
New Features
Documentation
Tests