Skip to content

hotfix(models): support hosted Gemma 4 thinking mode - #14793

Merged
ousugo merged 5 commits into
CherryHQ:mainfrom
ousugo:hotfix/14776-gemma4-thinking
May 7, 2026
Merged

hotfix(models): support hosted Gemma 4 thinking mode#14793
ousugo merged 5 commits into
CherryHQ:mainfrom
ousugo:hotfix/14776-gemma4-thinking

Conversation

@ousugo

@ousugo ousugo commented May 2, 2026

Copy link
Copy Markdown
Collaborator

What this PR does

Before this PR:

  • Hosted Gemma 4 models under the Gemini provider were treated as reasoning models, but they did not go through the Gemini thinking-token path.
  • Cherry Studio could not configure hosted Gemma 4 thinking mode correctly, and requests did not send the intended Gemini thinking-level parameters for these models.

After this PR:

  • Hosted Gemma 4 models on the Gemini provider are classified separately from generic Gemini thinking models.
  • Cherry Studio now exposes the intended minimal / high options for hosted Gemma 4 and maps them to the matching Gemini thinkingLevel request parameters.
  • Cherry Studio intentionally does not expose a formal none option for Google-hosted Gemma 4, because Google documents minimal as the closest supported near-off setting for most requests but does not guarantee that thinking is fully disabled.
  • Non-Gemini Gemma 4 routes remain unchanged.

Fixes #14776

Why we need it and why it was done in this way

The following tradeoffs were made:

  • Added a dedicated gemma4_hosted thinking model type instead of overloading existing Gemini types, so the change stays provider-scoped and avoids affecting Ollama or OpenRouter Gemma 4 behavior.
  • Kept the existing Thinking button state behavior unchanged to minimize UI churn.
  • Chose minimal / high rather than exposing none as a formal hosted Gemma 4 option on the Gemini provider, because the Google API does not document a distinct hard-off mode for this route.
  • Kept request-side compatibility for unexpected or legacy reasoning_effort: 'none' inputs by normalizing them to thinkingLevel: 'minimal' with includeThoughts: false.

The following alternatives were considered:

  • Exposing none as an official hosted Gemma 4 option despite the Gemini API not guaranteeing hard-off behavior.
  • Reusing the existing gemini2_pro thinking options and budget mapping.
  • Special-casing only the Gemini request builder without introducing a dedicated thinking model type.

Links to places where the discussion took place: #14776

Breaking changes

N/A

If this PR introduces breaking changes, please describe the changes and the impact on users.

Special notes for your reviewer

  • This change is intentionally limited to hosted Gemma 4 models on the Gemini provider.
  • OpenRouter Gemma 4 reasoning control will be handled separately so this hotfix stays provider-scoped and minimal.
  • Added code comments documenting why Google-hosted Gemma 4 does not expose a formal none option.
  • Verified with focused Vitest coverage:
    • src/renderer/src/config/models/__tests__/reasoning.test.ts
    • src/renderer/src/aiCore/utils/__tests__/reasoning.test.ts
    • src/renderer/src/pages/home/Inputbar/tools/components/__tests__/ThinkingButton.test.tsx

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note

Fixed hosted Gemma 4 thinking mode on the Gemini provider so Cherry Studio exposes the correct minimal/high options and sends matching thinking level parameters to Google-hosted endpoints.

Signed-off-by: ousugo <dkzydkzyxh@gmail.com>
@ousugo ousugo changed the title fix: support hosted Gemma 4 thinking mode hotfix(models): support hosted Gemma 4 thinking mode May 2, 2026

@GeorgeDong32 GeorgeDong32 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Code Review Summary

✅ 优点

  1. 精准修复:只针对 Gemini provider 的 hosted Gemma 4,不影响其他 provider
  2. 代码质量:函数命名清晰,实现简洁
  3. 测试覆盖:添加了完整的测试用例
  4. API 参数处理:正确映射 reasoning_effort 到 thinkingLevel

🔶 需关注的问题

  1. 缺少 none 选项:用户无法显式关闭 thinking mode(详见 inline comment)
  2. OpenRouter 场景未解决:原始 issue #14870 用户报告的是 OpenRouter 场景,但此 PR 仅修复 Gemini provider(详见 inline comment)

建议在 PR description 中说明此 PR 仅修复 Gemini provider 场景,OpenRouter 可能需要后续处理。

Comment thread src/renderer/src/config/models/reasoning.ts
Comment thread src/renderer/src/config/models/reasoning.ts

@GeorgeDong32 GeorgeDong32 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

补充说明:关于 OpenRouter 和 "none" 选项

经过文档调研后的补充说明:

OpenRouter 场景

OpenRouter 文档确认 google/gemma-4-31b-it 支持 reasoning 控制,使用 reasoning.effort 参数(支持 none/minimal/low/medium/high/xhigh)。但此 PR 有意只修复 Gemini provider 场景,OpenRouter 需要后续单独处理 —— 这个设计决策是合理的。

关于缺少 "none" 选项

OpenRouter 支持 effort: "none" 来完全禁用推理。但对于 Google hosted Gemma 4,需要确认:

  • Google Gemini API 是否支持完全关闭 hosted Gemma 4 的 thinking?
  • 类似于 Gemini 3 Pro 不支持关闭 thinking 的限制?

如果 Google API 支持关闭 thinking,建议添加 none 选项。如果不支持,建议在代码注释或文档中说明原因。

参考资料

@ousugo

ousugo commented May 7, 2026

Copy link
Copy Markdown
Collaborator Author

Note

This comment was translated by Claude.

Additional clarification on these two review points:

  1. Regarding the none option: I checked the Google Gemini / Gemma documentation, and the semantics of minimal are closer to "equivalent to no thinking for most requests," but the documentation also explicitly states that it does not guarantee thinking is completely disabled. Therefore, in this PR, hosted Gemma 4 under the Gemini provider continues to expose only default / minimal / high, without exposing none as a formal UI capability, to avoid describing capabilities more strongly than what the Google API actually guarantees.

  2. Compatibility-wise: The request layer retains compatibility handling for reasoning_effort === 'none', which will be sent as a downgrade to thinkingLevel: 'minimal' with includeThoughts: false, and corresponding tests have been added. In other words, none is treated here as a compatibility input, not as an official capability tier for Gemini hosted Gemma 4.

  3. Regarding OpenRouter: The scope of this PR is intentionally limited to hosted Gemma 4 under the Gemini provider. I will handle Gemma 4 reasoning control on OpenRouter separately and not mix it with this hotfix. The PR description also maintains this provider-scoped boundary to avoid coupling two provider paths into a single fix. Removed the Fix reference for [Bug]: New models automatically enable thinking mode by default, cannot be manually adjusted #14870.


Original Content

补充说明一下这两个 review 点:

  1. 关于 none 选项:我查了 Google Gemini / Gemma 的文档,minimal 的语义更接近 "对大多数请求等同 no thinking",但文档也明确说明它 不保证 thinking 完全关闭。所以这个 PR 里,Gemini provider 下的 hosted Gemma 4 继续只暴露 default / minimal / high,不把 none 作为正式 UI 能力暴露,避免把能力描述得比 Google API 实际保证更强。

  2. 兼容性方面:请求层仍保留了对 reasoning_effort === 'none' 的兼容处理,会降级发送为 thinkingLevel: 'minimal' 且 includeThoughts: false,并补了对应测试。也就是说,none 在这里被当作兼容输入处理,而不是 Gemini hosted Gemma 4 的正式能力档位。

  3. 关于 OpenRouter:这个 PR 的范围有意只限定在 Gemini provider 下的 hosted Gemma 4。OpenRouter 上的 Gemma 4 reasoning 控制我会另外处理,不和这次 hotfix 混在一起。PR 描述里我也保留了这个 provider-scoped 的边界,避免把两条 provider 路径耦合到一个修复里。已删除了对 [Bug]: New models automatically enable thinking mode by default, cannot be manually adjusted #14870 的 Fix。

@ousugo
ousugo requested a review from GeorgeDong32 May 7, 2026 07:47

@GeorgeDong32 GeorgeDong32 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. 设计决策清晰文档化,向后兼容处理得当。

@ousugo
ousugo merged commit c5e4409 into CherryHQ:main May 7, 2026
9 checks passed
@ousugo
ousugo deleted the hotfix/14776-gemma4-thinking branch May 7, 2026 17:37
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.

[Feature]: Add convenient thinking mode toggle for Gemma 4 model on AI Studio

3 participants