Skip to content

fix: support playground advanced custom routing - #5968

Closed
seefs001 wants to merge 1 commit into
QuantumNous:mainfrom
seefs001:fix/advanced-custom-channel-playground
Closed

seefs001 wants to merge 1 commit into
QuantumNous:mainfrom
seefs001:fix/advanced-custom-channel-playground

Conversation

@seefs001

@seefs001 seefs001 commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)

格式化playground的path

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 Issues 与 PRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit

  • New Features

    • Playground request paths are now recognized consistently and mapped to the standard API route format.
  • Bug Fixes

    • Improved routing and retry handling for playground and custom chat requests.
    • Advanced custom channels now match playground chat requests correctly, reducing misrouting and failed channel selection.

@seefs001
seefs001 marked this pull request as draft July 7, 2026 06:30
@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR adds path canonicalization helpers (IsPlaygroundRelayPath, CanonicalRelayRequestPath) to normalize /pg/* playground paths to their /v1/* equivalents, and applies them across relay mode detection, distributor channel matching, the advanced custom adaptor, and retry parameter population, fixing playground routing for AdvancedCustom channels.

Changes

Playground Path Canonicalization

Layer / File(s) Summary
Canonicalization helpers and relay mode routing
relay/constant/relay_mode.go
Adds IsPlaygroundRelayPath and CanonicalRelayRequestPath; Path2RelayMode now canonicalizes /pg paths before route matching, replacing the prior inline special-case.
Relay info playground detection
relay/common/relay_info.go
genBaseRelayInfo detects playground paths via IsPlaygroundRelayPath and canonicalizes info.RequestURLPath instead of manual prefix rewriting.
Distributor channel matching and retry path
middleware/distributor.go, middleware/distributor_test.go
Computes a canonical requestPath for preferred-channel matching and retry params; channelSupportsRequestPath canonicalizes the path before checking config.SupportsPath; adds a test verifying playground path support for AdvancedCustom channels.
Advanced custom adaptor path matching
relay/channel/advancedcustom/adaptor.go, relay/channel/advancedcustom/adaptor_test.go
incomingRequestPath canonicalizes the request URL path; adds a test verifying a playground path matches the corresponding /v1 route in GetRequestURL.
Retry parameter path in controller
controller/relay.go
Relay and RelayTask set service.RetryParam.RequestPath using the canonical path instead of the raw request path.

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
Loading

Possibly related PRs

  • QuantumNous/new-api#1656: Both PRs modify the RelayTask flow in controller/relay.go, one refactoring retry/task handling and this one changing retry RequestPath derivation.

Suggested reviewers: creamlike1024, xyfacai

Poem

A rabbit hopped down the /pg trail,
found signs pointing to /v1 without fail.
No more "no channel" frown,
canonical paths lead safely down—
hop, route, match, and never bail! 🐇🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the bug fix for playground routing with advanced custom channels.
Linked Issues check ✅ Passed The changes canonicalize playground paths and add tests so advanced custom channels route correctly, matching #5966.
Out of Scope Changes check ✅ Passed All code changes support canonicalizing playground request paths and route matching; no unrelated scope is introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
relay/constant/relay_mode.go (1)

57-71: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Solid canonicalization logic.

IsPlaygroundRelayPath/CanonicalRelayRequestPath correctly handle exact /pg, prefixed /pg/..., and non-playground paths (e.g. /pgx), and preserve any trailing query string since only the leading /pg segment is rewritten. Path2RelayMode now 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

📥 Commits

Reviewing files that changed from the base of the PR and between becc18e and e77a015.

📒 Files selected for processing (7)
  • controller/relay.go
  • middleware/distributor.go
  • middleware/distributor_test.go
  • relay/channel/advancedcustom/adaptor.go
  • relay/channel/advancedcustom/adaptor_test.go
  • relay/common/relay_info.go
  • relay/constant/relay_mode.go

@YCQ1101

YCQ1101 commented Jul 22, 2026

Copy link
Copy Markdown

Any updates?

@ysmintor

Copy link
Copy Markdown

Any updates to merge?

@Calcium-Ion
Calcium-Ion force-pushed the main branch 2 times, most recently from 51fdfc5 to 2b6f1df Compare August 30, 2026 15:03
@seefs001 seefs001 closed this Sep 18, 2026
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.

使用高级自定义渠道之后游乐场聊天提示 无可用渠道(distributor)

3 participants