Skip to content

fix(antigravity): forward thinking config for Gemini via OpenAI-compatible endpoints - #8619

Open
WidkWidk wants to merge 1 commit into
Wei-Shaw:mainfrom
WidkWidk:widkwidk-antigravity-gemini-compat-thinking
Open

WidkWidk wants to merge 1 commit into
Wei-Shaw:mainfrom
WidkWidk:widkwidk-antigravity-gemini-compat-thinking

Conversation

@WidkWidk

@WidkWidk WidkWidk commented Nov 9, 2026

Copy link
Copy Markdown

背景 / Background

在 Antigravity 账号上通过 OpenAI 兼容端点(/v1/chat/completions、/v1/responses)调用 gemini-* 模型时,即使请求了思考(reasoning_effort / reasoning.effort),模型也不会思考,也不返回 reasoning_content。

Gemini models on Antigravity accounts never think through the OpenAI-compatible endpoints, even when the client asks for reasoning.

根因 / Root cause:buildAntigravityCompatGeminiBody 对 gemini- 模型调用 convertClaudeMessagesToGeminiGenerateContent,其中 convertClaudeGenerationConfig 只复制 max_tokens / temperature / top_p / stop_sequences。中间 Anthropic 请求里的 thinking / output_config.effort 被丢弃,generationConfig.thinkingConfig 从未发给 v1internal。v0.2.19 中代码相同,不是近期回归。

上游实测 / Observed upstream behaviour(Antigravity,gemini-4-argon-high,经原生 /antigravity/v1beta/models/...:generateContent 透传 generationConfig):

generationConfig 结果
无 thinkingConfig 不思考(无 thoughtsTokenCount),尽管模型名带 -high
thinkingLevel: "high" 思考(200–600 thought tokens)
thinkingLevel: "low"(简单提示) 不思考
thinkingBudget: -1 思考
thinkingBudget: 8192 + includeThoughts 不思考
includeThoughts: true 返回 thought=true parts

修复前:Chat Completions reasoning_effort: "high" + gemini-4-argon-high → completion_tokens 8,无 reasoning_content。

所以 Antigravity 不会仅凭模型名后缀启用思考,必须显式下发 thinkingConfig。

改动 / Changes

  • 新增 applyAntigravityCompatGeminiThinkingConfig,在 Antigravity 兼容路径的 Gemini 分支中调用:
    • 没有思考意图(thinking 非 enabled/adaptive 且无 output_config.effort)时不改请求体,保持原有行为。
    • Gemini 3+(level 模型):写 thinkingLevel,复用 geminiThinkingLevelFor;无法从意图得出时取模型名后缀档位,最后回退 high。带 -high/-medium/-low 后缀的模型同样显式下发。
    • Gemini 2.5(budget 模型):写 thinkingBudget(geminiThinkingBudgetFor,否则 -1 动态)。
    • 开启思考时写 includeThoughts: true,使 thought parts 经现有的流/非流转换器变成 reasoning_content / reasoning 输出;minimal 或 budget 0 时不写。
    • 非 gemini、图像/TTS 等不支持思考参数的模型不受影响。
  • Gemini 平台(非 Antigravity)的 applyGeminiCompatThinkingConfig 未改动:它对带档位后缀的模型跳过 thinkingLevel,上面的实测只针对 Antigravity,没有证据表明 Gemini 平台也需要改。

未改动 / Intentionally unchanged

  • 思考变体解析(getMappedModelForThinkingLevel)与计费 reasoning_effort 保持原样;测试中断言了 UpstreamModel 与 ReasoningEffort。
  • /v1/messages 走 antigravity.TransformClaudeToGeminiWithOptions,下发的是 thinkingBudget(-1 或 budget_tokens)。按上表,固定预算(如 8192)在 gemini-4-argon-high 上可能不思考,这可能是另一个问题,本 PR 不涉及。

测试 / Tests

新增 antigravity_gateway_compat_thinking_test.go:

  • applyAntigravityCompatGeminiThinkingConfig 单元表(17 例):3.x 裸模型 / 带后缀模型 / flash / 2.5 budget / 无意图 / disabled / minimal / 非 gemini 等。
  • 端到端:经 ForwardAsChatCompletions、ForwardAsResponses 检查包装后的 v1internal 请求体 request.generationConfig.thinkingConfig,覆盖 gemini-4-argon-high、gemini-3.5-flash、gemini-2.5-flash、未请求思考的情况。去掉修复后这些用例失败。
  • 流式与非流式 Chat 响应中 thought parts 映射为 reasoning_content。

验证(Go 1.27.3,macOS arm64):

  • go test ./internal/service/... ./internal/pkg/... -count=1 通过
  • go vet ./internal/service/ 通过
  • golangci-lint run ./internal/service/...(v2.14.0)0 issues
  • 修复补丁 cherry-pick 到 v0.2.20 无冲突,同样测试通过。

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

riofutab added a commit to riofutab/sub2api that referenced this pull request Nov 10, 2026
riofutab added a commit to riofutab/sub2api that referenced this pull request Nov 10, 2026
- 并入上游已合 PR:Wei-Shaw#8381 Wei-Shaw#8566 Wei-Shaw#8631 Wei-Shaw#8637 Wei-Shaw#8161 Wei-Shaw#8346 Wei-Shaw#8642 Wei-Shaw#8367 Wei-Shaw#8357 Wei-Shaw#8622,Wei-Shaw#8621 仅并测试
- 并入上游开放 PR:Wei-Shaw#8627 单请求最多冷却一个账号、Wei-Shaw#8619 Gemini 兼容下发思考、Wei-Shaw#8596 Wei-Shaw#8597 Wei-Shaw#8598 测试同步
- 新增迁移 249_add_usage_logs_api_key_cost_index_notx,与现有 249 迁移并存
- 后端 unit 测试、golangci-lint、前端 lint/typecheck/全部 vitest 通过;repository 集成测试未跑
@WidkWidk

Copy link
Copy Markdown
Author

Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement (CLA).

To sign, please reply with the following comment:

I have read the CLA Document and I hereby sign the CLA

You only need to sign once — it will be valid for all your future contributions to this project.

I have read the CLA Document and I hereby sign the CLA

轻翮 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

I have read the CLA Document and I hereby sign the CLA

…tible endpoints

The Antigravity compat path (/v1/chat/completions, /v1/responses) converted
the Anthropic-shaped intermediate request to Gemini with
convertClaudeMessagesToGeminiGenerateContent, which drops thinking /
output_config.effort. No generationConfig.thinkingConfig reached
v1internal, and Antigravity does not enable thinking from the -high/-low
model-name suffix alone, so reasoning_effort / reasoning.effort had no
effect and no reasoning content was returned.

Write thinkingLevel (Gemini 3+) or thinkingBudget (2.5) plus
includeThoughts from the client intent, including tier-suffixed models.
Requests without a thinking intent are unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@WidkWidk
WidkWidk force-pushed the widkwidk-antigravity-gemini-compat-thinking branch from 5d8db69 to 2b2f64a Compare November 11, 2026 11:45
@WidkWidk

Copy link
Copy Markdown
Author

recheck

@WidkWidk

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Nov 11, 2026
riofutab added a commit to riofutab/sub2api that referenced this pull request Nov 17, 2026
- 带入上游 11-16 已合的 55 个 PR,同步基准更新为 9cd1a1e;用量汇总改为非阻塞建表(Wei-Shaw#8693),被动用量换窗清理与 Fable 限额恢复采用上游实现(Wei-Shaw#8723 Wei-Shaw#8779)。
- Codex 独立上下文改用上游 Wei-Shaw#8769 的 user 文本归一化,撤回 fork 的 Wei-Shaw#8680 并补回 proposed_plan、guardian、cloud_threads 等类型;Gemini 思考等级改用 Wei-Shaw#8673,撤回 fork 的 Wei-Shaw#8619。
- 合入 24 个开放 PR,Wei-Shaw#8781 与 Wei-Shaw#8705 部分合入;Wei-Shaw#8856、Wei-Shaw#8858 与已有实现重复,未合入。
- 修复转义的 1h TTL 被快速路径漏判,并按 fork 的构造参数与模型目录调整上游测试。
- 后端全量 unit、golangci-lint、前端 vitest、迁移空库回放与 CI 集成测试通过;go.sum 未整理。
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.

1 participant