Repository navigation
fix: 收窄 OpenAI o 系列模型适配范围 - #5293
Conversation
|
Caution Review failedPull request was closed or merged during review WalkthroughNormalize provider-prefixed model names, add helpers to classify reasoning O-models and gpt-5 models, use them to determine system vs developer role, and update ConvertOpenAIRequest and test builders to apply model-specific token and parameter adaptations. ChangesModel-Specific Request Transformations
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
relay/channel/openai/adaptor.go (1)
320-335:⚠️ Potential issue | 🟠 Major | ⚡ Quick win
gpt-5detection is not gated byopenAIProvider, reintroducing the same misclassification this PR fixes.
isOModelis correctly gated onopenAIProvider, but everygpt-5check (lines 320, 331, 348) runs on the prefix-strippedupstreamModelNamewithout the provider guard. This is actually a regression: before this change,strings.HasPrefix(info.UpstreamModelName, "gpt-5")would befalsefor a name likeopenrouter/gpt-5-foo(the raw string starts withopenrouter/). Now the prefix is stripped first, sogpt-5-foomatches and a non-OpenAI provider model gets gpt-5 param resets and the system→developer rewrite — the exact class of bug this PR set out to eliminate for theoseries.Gate gpt-5 on
openAIProvideras well:🐛 Proposed fix
- isOModel := openAIProvider && len(upstreamModelName) > 1 && upstreamModelName[0] == 'o' && upstreamModelName[1] >= '0' && upstreamModelName[1] <= '9' - if isOModel || strings.HasPrefix(upstreamModelName, "gpt-5") { + isOModel := openAIProvider && len(upstreamModelName) > 1 && upstreamModelName[0] == 'o' && upstreamModelName[1] >= '0' && upstreamModelName[1] <= '9' + isGPT5Model := openAIProvider && strings.HasPrefix(upstreamModelName, "gpt-5") + if isOModel || isGPT5Model { @@ - if strings.HasPrefix(upstreamModelName, "gpt-5") { + if isGPT5Model { request.Temperature = nil request.TopP = nil request.LogProbs = nil } @@ - if strings.HasPrefix(upstreamModelName, "gpt-5") || !strings.HasPrefix(upstreamModelName, "o1-mini") && !strings.HasPrefix(upstreamModelName, "o1-preview") { + if isGPT5Model || (!strings.HasPrefix(upstreamModelName, "o1-mini") && !strings.HasPrefix(upstreamModelName, "o1-preview")) {Also applies to: 348-348
🤖 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/channel/openai/adaptor.go` around lines 320 - 335, The gpt-5 prefix checks are currently performed against the prefix-stripped upstreamModelName regardless of provider, causing non-OpenAI models to receive gpt-5-specific resets; update each gpt-5 detection so it only runs when openAIProvider is true (i.e., combine the existing isOModel/openAIProvider guard with the strings.HasPrefix(upstreamModelName, "gpt-5") checks), so when openAIProvider is false you do not clear request.Temperature/TopP/LogProbs or apply any gpt-5-specific transformations (apply the same change to the other gpt-5 checks mentioned alongside isOModel and the system→developer rewrite).
🧹 Nitpick comments (1)
relay/channel/openai/adaptor.go (1)
348-348: 💤 Low valueParenthesize the mixed
||/&&condition for clarity.The expression relies on
&&binding tighter than||. It is functionally correct (gpt-5 || (!o1-mini && !o1-preview)) and matchesGetSystemRoleNameindto/openai_request.go, but explicit parentheses prevent future misreads. Covered by the diff above.🤖 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/channel/openai/adaptor.go` at line 348, The mixed ||/&& condition using upstreamModelName in adaptor.go is hard to read; update the if that checks strings.HasPrefix(upstreamModelName, "gpt-5") || !strings.HasPrefix(... "o1-mini") && !strings.HasPrefix(... "o1-preview") to explicitly parenthesize the right-hand conjunct (so the logic remains gpt-5 OR (not o1-mini AND not o1-preview)), mirroring the intent in GetSystemRoleName in dto/openai_request.go; locate the condition around upstreamModelName and add parentheses around the !o1-mini && !o1-preview part for clarity.
🤖 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.
Outside diff comments:
In `@relay/channel/openai/adaptor.go`:
- Around line 320-335: The gpt-5 prefix checks are currently performed against
the prefix-stripped upstreamModelName regardless of provider, causing non-OpenAI
models to receive gpt-5-specific resets; update each gpt-5 detection so it only
runs when openAIProvider is true (i.e., combine the existing
isOModel/openAIProvider guard with the strings.HasPrefix(upstreamModelName,
"gpt-5") checks), so when openAIProvider is false you do not clear
request.Temperature/TopP/LogProbs or apply any gpt-5-specific transformations
(apply the same change to the other gpt-5 checks mentioned alongside isOModel
and the system→developer rewrite).
---
Nitpick comments:
In `@relay/channel/openai/adaptor.go`:
- Line 348: The mixed ||/&& condition using upstreamModelName in adaptor.go is
hard to read; update the if that checks strings.HasPrefix(upstreamModelName,
"gpt-5") || !strings.HasPrefix(... "o1-mini") && !strings.HasPrefix(...
"o1-preview") to explicitly parenthesize the right-hand conjunct (so the logic
remains gpt-5 OR (not o1-mini AND not o1-preview)), mirroring the intent in
GetSystemRoleName in dto/openai_request.go; locate the condition around
upstreamModelName and add parentheses around the !o1-mini && !o1-preview part
for clarity.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ed893dc3-ac97-4eaa-be3e-5e07e25b01fe
📒 Files selected for processing (1)
relay/channel/openai/adaptor.go
… id 等) 主要变更(QuantumNous/new-api → adc390c): - feat: 渠道被禁用后可配置是否清空渠道粘性 (QuantumNous#5306) - feat(web): profile 页显示 user id (QuantumNous#5317) - fix: 复用 channel handler 的 stream scanner buffer (QuantumNous#5225) - fix: 收窄 OpenAI o 系列模型适配范围 (QuantumNous#5293) - fix(relay): GLM Anthropic 兼容避免 chunked encoding (QuantumNous#5307) - fix: 新增 relay idle 连接超时配置 (QuantumNous#5309) - fix: 限制匿名请求体大小 (QuantumNous#5244) - fix(distributor): 修复 video generations task_id 模型解析 (QuantumNous#5133) - fix(dify): 远程图片字段赋值前初始化 file pointer (QuantumNous#5134) - fix(i18n): 优化 thinking adapter 文案 (QuantumNous#5242) 去合规一致性:上游未触及任何合规文件,合并完整保留本地去合规状态 (payment_setting.go / payment-settings-section.tsx / recharge-form-card.tsx / risk-acknowledgement-dialog.tsx 均未被改动)。 i18n:web/default 6 语言(en/zh/fr/ja/ru/vi)key 并集三路合并 + i18n:sync 规范化,4584 keys/语言,missing/extras/untranslated 全为 0。 验证:go build ./... ✅ + bun run typecheck ✅
* fix: 收窄 OpenAI o 系列模型适配范围 * fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型 * fix(openai): narrow o-series reasoning model detection --------- Co-authored-by: Seefs <i@seefs.me>
* fix: 收窄 OpenAI o 系列模型适配范围 * fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型 * fix(openai): narrow o-series reasoning model detection --------- Co-authored-by: Seefs <i@seefs.me>
…codes * origin/main: (45 commits) fix(openai): support streaming image relay and image edit for images API (QuantumNous#4608) perf(web): improve dialog sizing and footer layout feat(web): add shared dialog wrapper perf(web): simplify public page hero copy perf(model-pricing): move pricing tabs into page title feat(json-editor): add reusable JSON code editor perf(model-pricing): improve JSON pricing editor layout perf(model-pricing): reduce duplicate model name display fix: support six-decimal steps in model pricing editor fix: respect theme for multiselect combobox popover fix: reuse stream scanner buffer in channel handlers (QuantumNous#5225) fix: 收窄 OpenAI o 系列模型适配范围 (QuantumNous#5293) fix(i18n): clarify thinking adapter copy (QuantumNous#5242) fix: limit anonymous request body (QuantumNous#5244) fix(relay): fix Anthropic-compatible compatibility for GLM (avoid chunked encoding) (QuantumNous#5307) feat: 支持配置渠道被禁用后是否清空渠道粘性 (QuantumNous#5306) fix: add relay idle connection timeout config (QuantumNous#5309) feat(web): show user id on profile page perf(model-pricing): refine visual editor actions refactor(model-pricing): split visual pricing editor modules ... # Conflicts: # router/api-router.go # web/default/src/features/usage-logs/components/usage-logs-mobile-card.tsx
* fix: 收窄 OpenAI o 系列模型适配范围 * fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型 * fix(openai): narrow o-series reasoning model detection --------- Co-authored-by: Seefs <i@seefs.me> (cherry picked from commit 01c2128)
* fix: 收窄 OpenAI o 系列模型适配范围 * fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型 * fix(openai): narrow o-series reasoning model detection --------- Co-authored-by: Seefs <i@seefs.me>
* fix: 收窄 OpenAI o 系列模型适配范围 * fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型 * fix(openai): narrow o-series reasoning model detection --------- Co-authored-by: Seefs <i@seefs.me>
* fix: 收窄 OpenAI o 系列模型适配范围 * fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型 * fix(openai): narrow o-series reasoning model detection --------- Co-authored-by: Seefs <i@seefs.me>
* fix: 收窄 OpenAI o 系列模型适配范围 * fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型 * fix(openai): narrow o-series reasoning model detection --------- Co-authored-by: Seefs <i@seefs.me>
* fix: 收窄 OpenAI o 系列模型适配范围 * fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型 * fix(openai): narrow o-series reasoning model detection --------- Co-authored-by: Seefs <i@seefs.me>
* fix: 收窄 OpenAI o 系列模型适配范围 * fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型 * fix(openai): narrow o-series reasoning model detection --------- Co-authored-by: Seefs <i@seefs.me>
* fix: 收窄 OpenAI o 系列模型适配范围 * fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型 * fix(openai): narrow o-series reasoning model detection --------- Co-authored-by: Seefs <i@seefs.me> (cherry picked from commit 01c2128)
Important
📝 变更描述 / Description
#5292
修复 OpenAI adaptor 中 o 系列模型判断过于宽泛的问题
原来
strings.HasPrefix(info.UpstreamModelName, "o")判断是否应用 OpenAI o 系列适配,会误伤openrouter/owl-alpha这类模型,导致首条system消息被改写为developer本修改进行以下修改:
无 provider 前缀,且模型名满足
o+数字或 provider 前缀以openai开头,且模型名满足o+数字🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

修复后脚本验证:
Summary by CodeRabbit
Bug Fixes
Tests