feat: 新增阿里云百炼 Token Plan 渠道类型,修复 responses API 路径问题#5764
Conversation
- 新增 ChannelTypeAliTokenPlan (59) 渠道类型和 APITypeAliTokenPlan - 创建 ali_token_plan 适配器包,通过嵌入 ali.Adaptor 继承并覆写 GetRequestURL - 修复 Token Plan 的 responses API 路径(使用 /compatible-mode/v1/responses 替代 DashScope 特有前缀) - 注册流式支持和前端 UI 选项
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds a new Ali Token Plan channel and API type, routes it to a dedicated relay adaptor for responses and other modes, and updates streaming support plus web channel options. ChangesAli Token Plan channel support
Sequence Diagram(s)sequenceDiagram
participant Client
participant GetAdaptor as relay/relay_adaptor.go GetAdaptor
participant Adaptor as relay/channel/ali_token_plan.Adaptor
participant Upstream as Ali token plan upstream
Client->>GetAdaptor: APITypeAliTokenPlan request
GetAdaptor->>Adaptor: return ali_token_plan.Adaptor
Client->>Adaptor: GetRequestURL(info)
Adaptor->>Adaptor: choose /compatible-mode/v1/responses, /embeddings, /completions, /rerank, or /chat/completions
Adaptor->>Upstream: send request to resolved URL
Upstream-->>Adaptor: response
Adaptor-->>Client: relay response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@relay/channel/ali_token_plan/adaptor.go`:
- Around line 21-35: The fallback in the request URL resolver is too restrictive
and should delegate unknown relay modes to the embedded Ali adaptor. In the
GetRequestURL logic for the Token Plan adaptor, keep the explicit overrides for
the known compatible-mode cases, but replace the default chat-completions path
with a call to a.Adaptor.GetRequestURL(info) so any Ali-specific RelayMode not
listed here inherits the base behavior.
🪄 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: 16d1e522-2178-44bf-87ef-01d5ad3ce7b1
📒 Files selected for processing (7)
common/api_type.goconstant/api_type.goconstant/channel.gorelay/channel/ali_token_plan/adaptor.gorelay/common/relay_info.gorelay/relay_adaptor.goweb/classic/src/constants/channel.constants.js
将 GetRequestURL() 的 default 分支从硬编码 chat/completions 路径改为 调用 a.Adaptor.GetRequestURL(info),确保未来 Ali 适配器新增模式时 能正确继承路由行为而非被错误路由。
问题
使用阿里通义千问渠道类型(ChannelTypeAli)配置 Token Plan API 地址
https://token-plan.cn-beijing.maas.aliyuncs.com时,调用 responses 接口返回bad_response_status_code错误。根因分析
Ali 适配器在
RelayModeResponses下构造的请求路径为:该前缀
/api/v2/apps/protocols/是 DashScope(dashscope.aliyuncs.com)平台专属路径,Token Plan 平台不支持。Token Plan 的正确 responses 端点应为:
修复方案
ChannelTypeAliTokenPlan = 59渠道类型(阿里百炼 Token Plan 与通义千问是不同产品线)APITypeAliTokenPlanAPI 类型relay/channel/ali_token_plan/adaptor.go,通过 Go 结构体嵌入继承ali.Adaptor,仅覆写GetRequestURL()方法修复路径变更文件
constant/channel.go- 新增渠道类型常量和 base URLconstant/api_type.go- 新增 API 类型common/api_type.go- 添加类型映射relay/relay_adaptor.go- 注册适配器工厂relay/channel/ali_token_plan/adaptor.go- 新建适配器(继承 Ali)relay/common/relay_info.go- 注册流式支持web/classic/src/constants/channel.constants.js- 前端 UI 选项Closes newapi缺乏阿里云token plan渠道导致responses不可用, 返回500错误 #5763
Summary by CodeRabbit
.qoder/directory.