Skip to content

fix: 收窄 OpenAI o 系列模型适配范围 - #5293

Merged
seefs001 merged 3 commits into
QuantumNous:mainfrom
USER-HFC:fix/openrouter-o-model-detection
Jun 5, 2026
Merged

seefs001 merged 3 commits into
QuantumNous:mainfrom
USER-HFC:fix/openrouter-o-model-detection

Conversation

@USER-HFC

@USER-HFC USER-HFC commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

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

📝 变更描述 / 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

  • 🐛 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

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)
修复后脚本验证:
image

image

Summary by CodeRabbit

  • Bug Fixes

    • Improved compatibility with newer OpenAI o-series and gpt-5 models: parameter normalization prevents misapplied token/temperature/top-p/logprob settings.
    • Expanded message-role handling so system→developer rewrites apply correctly to relevant o-series and gpt-5 models, improving prompt behavior.
  • Tests

    • Added unit tests validating role determination for o-series and gpt-5 model names.

@coderabbitai

coderabbitai Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

Normalize 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.

Changes

Model-Specific Request Transformations

Layer / File(s) Summary
Model helpers and system-role resolution
dto/openai_request.go
Add IsOpenAIReasoningOModel and IsOpenAIGPT5Model; update GeneralOpenAIRequest.GetSystemRoleName() to use them and preserve o1-mini/o1-preview exceptions.
ConvertOpenAIRequest model gating and parameter normalization
relay/channel/openai/adaptor.go
Replace prefix checks with dto helpers; gate MaxTokens→MaxCompletionTokens normalization on classified models; split parameter resets between isOModel and isGPT5Model.
Test builder and unit tests
controller/channel-test.go, dto/openai_request_zero_value_test.go
buildTestRequest switches to dto.IsOpenAIReasoningOModel(model) for model detection; add table-driven tests asserting GetSystemRoleName() for various model inputs.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • QuantumNous/new-api#1525: Modifies relay/channel/openai/adaptor.go and related model detection logic for o-series/gpt-5 handling.
  • QuantumNous/new-api#2433: Updates controller/channel-test.go buildTestRequest logic and may overlap with model-detection changes.

Suggested reviewers

  • seefs001

Poem

🐰 I trimmed the prefixes tangled in names,
Now o and gpt‑5 play fair in the frames.
Tokens and temps adapt with care,
Tests hop along to make sure it's fair. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly describes the main change: narrowing the detection scope for OpenAI o-series models, which directly addresses the core issue of overly broad model identification logic.
Linked Issues check ✅ Passed The code changes successfully implement stricter detection for OpenAI o-series models using helper functions, ensuring provider-prefixed models like openrouter/owl-alpha are not misidentified and system role is preserved.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the OpenAI o-series model detection issue: helper functions clarify model classification, adaptor logic is narrowed, and tests validate the corrected behavior.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@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.

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-5 detection is not gated by openAIProvider, reintroducing the same misclassification this PR fixes.

isOModel is correctly gated on openAIProvider, but every gpt-5 check (lines 320, 331, 348) runs on the prefix-stripped upstreamModelName without the provider guard. This is actually a regression: before this change, strings.HasPrefix(info.UpstreamModelName, "gpt-5") would be false for a name like openrouter/gpt-5-foo (the raw string starts with openrouter/). Now the prefix is stripped first, so gpt-5-foo matches 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 the o series.

Gate gpt-5 on openAIProvider as 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 value

Parenthesize the mixed ||/&& condition for clarity.

The expression relies on && binding tighter than ||. It is functionally correct (gpt-5 || (!o1-mini && !o1-preview)) and matches GetSystemRoleName in dto/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

📥 Commits

Reviewing files that changed from the base of the PR and between b0ac042 and e45c79e.

📒 Files selected for processing (1)
  • relay/channel/openai/adaptor.go

@seefs001
seefs001 merged commit 01c2128 into QuantumNous:main Jun 5, 2026
1 check was pending
Soein added a commit to Soein/new-api that referenced this pull request Jun 6, 2026
… 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 ✅
Ember-Moth pushed a commit to Herta-Network/new-api that referenced this pull request Jun 7, 2026
* fix: 收窄 OpenAI o 系列模型适配范围

* fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型

* fix(openai): narrow o-series reasoning model detection

---------

Co-authored-by: Seefs <i@seefs.me>
szxufan pushed a commit to szxufan/new-api that referenced this pull request Jun 9, 2026
* fix: 收窄 OpenAI o 系列模型适配范围

* fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型

* fix(openai): narrow o-series reasoning model detection

---------

Co-authored-by: Seefs <i@seefs.me>
52assert added a commit to 52assert/new-api that referenced this pull request Jun 10, 2026
…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
endercat-alu pushed a commit to endercat-alu/new-api that referenced this pull request Jun 10, 2026
* 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)
OuYang-HX pushed a commit to OuYang-HX/new-api that referenced this pull request Jun 13, 2026
* fix: 收窄 OpenAI o 系列模型适配范围

* fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型

* fix(openai): narrow o-series reasoning model detection

---------

Co-authored-by: Seefs <i@seefs.me>
ruanhangjian pushed a commit to ruanhangjian/new-api that referenced this pull request Jul 11, 2026
* fix: 收窄 OpenAI o 系列模型适配范围

* fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型

* fix(openai): narrow o-series reasoning model detection

---------

Co-authored-by: Seefs <i@seefs.me>
zhaodechao2008 pushed a commit to zhaodechao2008/new-api that referenced this pull request Jul 27, 2026
* fix: 收窄 OpenAI o 系列模型适配范围

* fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型

* fix(openai): narrow o-series reasoning model detection

---------

Co-authored-by: Seefs <i@seefs.me>
330079598 pushed a commit to 330079598/new-api that referenced this pull request Aug 19, 2026
* fix: 收窄 OpenAI o 系列模型适配范围

* fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型

* fix(openai): narrow o-series reasoning model detection

---------

Co-authored-by: Seefs <i@seefs.me>
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
* fix: 收窄 OpenAI o 系列模型适配范围

* fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型

* fix(openai): narrow o-series reasoning model detection

---------

Co-authored-by: Seefs <i@seefs.me>
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
* fix: 收窄 OpenAI o 系列模型适配范围

* fix(openai): 限制 gpt-5 适配仅作用于 OpenAI 模型

* fix(openai): narrow o-series reasoning model detection

---------

Co-authored-by: Seefs <i@seefs.me>
NaturalSelect pushed a commit to NaturalSelect/new-api that referenced this pull request Nov 5, 2026
* 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)
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.

OpenRouter 模型 openrouter/owl-alpha 被误判为 OpenAI o 系列,导致 system role 被改写为 developer

2 participants