Repository navigation
Conversation
WalkthroughThis PR adds path canonicalization helpers ( ChangesPlayground Path Canonicalization
Estimated code review effort: 2 (Simple) | ~15 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant Distributor
participant RelayMode as Path2RelayMode
participant Adaptor as AdvancedCustom Adaptor
participant Channel
Client->>Distributor: Request /pg/chat/completions
Distributor->>Distributor: CanonicalRelayRequestPath(path) -> /v1/chat/completions
Distributor->>RelayMode: Path2RelayMode(canonical path)
RelayMode-->>Distributor: relay mode
Distributor->>Channel: channelSupportsRequestPath(canonical path)
Channel-->>Distributor: supported = true
Distributor->>Adaptor: Forward request with canonical path
Adaptor->>Adaptor: incomingRequestPath() canonicalizes again
Adaptor-->>Client: Response via matched /v1 route
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
relay/constant/relay_mode.go (1)
57-71: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winSolid canonicalization logic.
IsPlaygroundRelayPath/CanonicalRelayRequestPathcorrectly handle exact/pg, prefixed/pg/..., and non-playground paths (e.g./pgx), and preserve any trailing query string since only the leading/pgsegment is rewritten.Path2RelayModenow generalizes canonicalization for all/pg/*routes rather than just chat completions.Consider adding a small table test directly for these two exported helpers (e.g.
/pg,/pg/,/pg/chat/completions?x=1,/pgx,/v1/...) since they're now relied upon by four different call sites (relay_info.go,distributor.go,advancedcustom/adaptor.go,controller/relay.go).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@relay/constant/relay_mode.go` around lines 57 - 71, Add a small table-driven test for IsPlaygroundRelayPath and CanonicalRelayRequestPath to cover the key canonicalization cases the review calls out: exact "/pg", "/pg/", "/pg/chat/completions?x=1", non-playground "/pgx", and an already-canonical "/v1/..." path. Use the existing helper names from relay_mode.go so the test clearly validates the exported behavior now relied on by Path2RelayMode and the downstream call sites.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@relay/constant/relay_mode.go`:
- Around line 57-71: Add a small table-driven test for IsPlaygroundRelayPath and
CanonicalRelayRequestPath to cover the key canonicalization cases the review
calls out: exact "/pg", "/pg/", "/pg/chat/completions?x=1", non-playground
"/pgx", and an already-canonical "/v1/..." path. Use the existing helper names
from relay_mode.go so the test clearly validates the exported behavior now
relied on by Path2RelayMode and the downstream call sites.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 013e4762-e345-4bbf-9dd3-daeac028a6d7
📒 Files selected for processing (7)
controller/relay.gomiddleware/distributor.gomiddleware/distributor_test.gorelay/channel/advancedcustom/adaptor.gorelay/channel/advancedcustom/adaptor_test.gorelay/common/relay_info.gorelay/constant/relay_mode.go
|
Any updates? |
|
Any updates to merge? |
51fdfc5 to
2b6f1df
Compare
Important
📝 变更描述 / Description
(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
格式化playground的path
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)
Summary by CodeRabbit
New Features
Bug Fixes