Skip to content

fix(provider): support Gemini relay aliases and dated 2.5 thinking models - #10961

Open
JosephTian876 wants to merge 1 commit into
AstrBotDevs:masterfrom
JosephTian876:fix/gemini-generation-thinking-config
Open

JosephTian876 wants to merge 1 commit into
AstrBotDevs:masterfrom
JosephTian876:fix/gemini-generation-thinking-config

Conversation

@JosephTian876

@JosephTian876 JosephTian876 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

After #11219 and #11251 landed Gemini 4 reasoning_effort support, per-model Gemini 4 allowed levels, Gemini 3.8 MINIMAL filtering, and path/case normalization on master, two model-ID matching gaps remain in ProviderGoogleGenAI._prepare_query_config() (astrbot/core/provider/sources/gemini_source.py):

  1. Relay-decorated model aliases — Relay catalogues frequently decorate model IDs with prefixes such as [抗截断]gemini-4-argon, relay/[AN]Gemini-4-Neon, [抗截断]gemini-3.8-flash, or [抗截断]gemini-2.5-flash. model.rsplit("/", 1)[-1].lower() strips path segments, but the remaining prefix still prevents startswith("gemini-4"), startswith(("gemini-3-", "gemini-3.")), and Gemini 2.5 matching. For decorated Gemini 4 IDs, configuring custom_extra_body.reasoning_effort even raises ValueError: Unsupported Gemini custom_extra_body parameters: reasoning_effort.
  2. Dated / preview / exp / revision Gemini 2.5 thinking models — The Gemini 2.5 thinkingBudget check is still an exact 8-entry list, so dated thinking IDs such as gemini-2.5-flash-preview-09-2025, gemini-2.5-pro-preview-05-06, gemini-2.5-flash-lite-preview-06-17, gemini-2.5-pro-exp-03-25, and gemini-2.5-flash-001 silently omit thinkingConfig.

Modifications / 改动点

  • astrbot/core/provider/sources/gemini_source.py

    • Add _normalize_gemini_model_name() to extract the canonical lowercase gemini-<digit>... identifier from resource paths and relay-decorated aliases (keeping the outgoing API model value untouched).
    • Keep all feat: gemini 4 model series reasoning effort support without bumping google-genai #11219 / feat: register Gemini 4 Neon thinking levels #11251 Gemini 4 and Gemini 3.x semantics intact (custom_extra_body.reasoning_effort for Gemini 4, GEMINI_4_THINKING_LEVELS, sampling parameter stripping, forced TEXT modality, AUTO/None defaults).
    • Add _GEMINI_25_THINKING_MODEL_RE as a default-deny allow-list of thinking-capable Gemini 2.5 families (pro, flash, flash-lite with optional -preview/-exp and dated/revision suffixes), keeping non-thinking 2.5 variants (-image, -tts, -native-audio, -computer-use, decorated or not) excluded so they never receive thinkingConfig.
  • tests/test_gemini_source.py

    • Add coverage for relay-decorated Gemini 4 / 3 / 2.5 aliases, dated/preview/exp/revision 2.5 thinking IDs, Gemini 4 alias sampling-parameter stripping and modality enforcement, pure image generation requests, and 19 excluded model/alias cases.
  • This is NOT a breaking change. / 这不是一个破坏性变更。

Verification

  • ruff format --check . → 599 files already formatted
  • ruff check . → All checks passed
  • pytest tests/test_gemini_source.py → 50 passed

Suggested merge order

Logically independent of #10894, #11185, and #11298 (all touch distinct sections of astrbot/core/provider/sources/gemini_source.py). Suggested order: #10961 → #10894 → #11185 → #11298 (any order works).

Summary by Sourcery

Fix Gemini model matching so relay aliases and dated Gemini 2.5 models receive the appropriate thinking configuration without affecting unsupported variants.

Bug Fixes:

  • Support relay-decorated Gemini model aliases when applying Gemini 4 and Gemini 3.x thinking configuration.
  • Recognize dated, preview, experimental, and revision-based Gemini 2.5 thinking models while excluding non-thinking variants from thinking configuration.

Enhancements:

  • Preserve Gemini model behavior for modality enforcement, sampling parameter handling, and model-specific thinking-level rules across normalized aliases.

Tests:

  • Add coverage for decorated aliases, dated Gemini 2.5 models, excluded model variants, Gemini 4 parameter handling, and image-generation requests.

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@JosephTian876 JosephTian876 reopened this Nov 2, 2026
@Soulter Soulter moved this to In Progress in AstrBot Roadmap Nov 2, 2026

@agammann agammann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Exclude Gemini 2.5 image models from the broad generation fallback. gemini-2.5-flash-image now matches generation == (2, 5), so the default budget=0 still creates a ThinkingConfig and sends it with image requests. Google's model card lists Thinking as unsupported for this model (https://ai.google.dev/gemini-api/docs/models/gemini-2.5-flash-image); the previous explicit list did not include it. Keep the fallback limited to thinking-capable 2.5 model IDs, and test the image model path so an image request does not acquire a thinking config.

@JosephTian876
JosephTian876 force-pushed the fix/gemini-generation-thinking-config branch from 21d253f to c12aca8 Compare November 3, 2026 09:41
@JosephTian876

Copy link
Copy Markdown
Contributor Author

Thanks @agammann — good catch, and it's fixed in c12aca8 (amended into the same single commit, branch force-updated).

What changed

The or generation == (2, 5) disjunct is gone. The 2.5 budget branch is now the existing explicit list or a default-deny allow-list of the thinking-capable 2.5 families:

if model_name in [
    "gemini-2.5-pro", "gemini-2.5-pro-preview", "gemini-2.5-flash",
    "gemini-2.5-flash-preview", "gemini-2.5-flash-lite",
    "gemini-2.5-flash-lite-preview", "gemini-robotics-er-1.5-preview",
    "gemini-live-2.5-flash-preview-native-audio-09-2025",
] or re.search(
    r"gemini-2\.5-(?:pro|flash|flash-lite)"
    r"(?:-preview|-exp)?(?:-\d{2}(?:-\d{2,4})?)?$",
    model_name,
    re.IGNORECASE,
):
  • Default-deny, not an "image" substring test. The image ids can no longer enter the branch at all, so even the default budget=0 produces no ThinkingConfig for them, restoring master's behavior for those ids. I deliberately did not use "image" in model_name: that is fragile and would still leave the other non-thinking 2.5 modalities (TTS, native-audio, computer-use) broken, each of which rejects any thinkingConfig with the same 400 INVALID_ARGUMENT.
  • Excluded now: gemini-2.5-flash-image, -image-preview, -image-preview-09-2025, -image-generation, gemini-2.5-pro-image, their relay-decorated forms ([抗截断]gemini-2.5-flash-image, image-relay:gemini-2.5-flash-image), plus gemini-2.5-flash-preview-tts, gemini-2.5-pro-preview-tts, gemini-2.5-flash-native-audio-preview-09-2025 and gemini-2.5-computer-use-preview-10-2025. Any future 2.5 *-image / *-tts / *-audio id is excluded by construction.
  • Still covered: gemini-2.5-pro / -flash / -flash-lite with optional -preview / -exp and dated suffixes (gemini-2.5-flash-preview-09-2025, gemini-2.5-pro-preview-05-06), their relay aliases, and the two explicit ids that carry no gemini-<digits> marker (gemini-robotics-er-1.5-preview, gemini-live-2.5-flash-preview-native-audio-09-2025), which is why the explicit list stays.
  • Gemini 3 / Gemini 4 untouched: generation >= (3, 0) still selects thinkingLevel, including the >= 3.7 MINIMAL→MEDIUM fallback and relay aliases. The fix remains in _prepare_query_config, so _query and _query_stream share the same predicate.

Tests (tests/test_gemini_source.py)

  1. test_gemini_25_non_thinking_models_get_no_thinking_config — 13 cases: image ids with the shipped default {"budget": 0, "level": "HIGH"} and with budget=2048, relay-decorated aliases, the TTS / native-audio / computer-use ids, and gemini-2.0-flash-exp-image-generation; all assert config.thinking_config is None.
  2. test_gemini_25_image_generation_request_gets_no_thinking_config — gemini-2.5-flash-image with modalities=["IMAGE"] (pure image output) asserts the response modalities are kept and no thinking config is attached.
  3. The existing matrix gained dated thinking variants (gemini-2.5-flash-preview-09-2025, gemini-2.5-flash-lite-preview, gemini-2.5-pro-preview-05-06) so the allow-list cannot silently drop them later.
  4. The existing gemini-4 / relay-alias / gemini-3.1 / 3.7 / 3.8 cases are unchanged and still pass.

Verification

  • python -m pytest tests/test_gemini_source.py -q → 43 passed.
  • Adjacent provider tests (test_provider_user_agent.py, test_decision_provider.py, test_anthropic_kimi_code_provider.py) → 155 passed, 1 skipped.
  • Against the previous head, the 13 new non-thinking cases fail (13 failed / 30 passed), so they do catch the regression you reported.
  • ruff check and ruff format --check clean, git diff --check clean, single amended commit, working tree clean.

Could you take another look when you have a moment?

Copy link
Copy Markdown

Rechecked c12aca8: the 2.5 allow-list excludes the image examples and the new tests cover image requests, including a decorated alias. That addresses the issue I raised. I checked the regex separately with AI assistance, but have not run the AstrBot tests or a live Gemini request.

…dels

After AstrBotDevs#11219 and AstrBotDevs#11251 landed Gemini 4 reasoning_effort and Gemini 3.8
thinking level support on master, narrow this change to the two remaining
matching gaps in ProviderGoogleGenAI._prepare_query_config():

- Normalize relay-decorated model aliases (such as [AN]gemini-4-hydrogen
  or full-width prefixed ids) down to their canonical lowercase Gemini id
  so Gemini 4 reasoning_effort / sampling-param stripping, Gemini 3
  thinkingLevel rules, and Gemini 2.5 thinkingBudget all apply cleanly.
- Match dated/preview/exp Gemini 2.5 thinking families (pro, flash,
  flash-lite) via a default-deny allow-list so dated preview ids receive
  thinkingBudget while non-thinking 2.5 variants (image, tts, native-audio,
  computer-use) remain excluded.
@JosephTian876
JosephTian876 force-pushed the fix/gemini-generation-thinking-config branch from c12aca8 to 220cdf9 Compare November 21, 2026 21:39
@JosephTian876 JosephTian876 changed the title fix(provider): apply Gemini thinking config to gemini-4 and aliases fix(provider): support Gemini relay aliases and dated 2.5 thinking models Nov 21, 2026
@JosephTian876

Copy link
Copy Markdown
Contributor Author

Rebased onto latest master (feb3e82) and narrowed to the two matching gaps remaining after #11219 and #11251:

  1. Relay-decorated model aliases (e.g. [抗截断]gemini-4-argon, relay/[AN]Gemini-4-Neon, [抗截断]gemini-3.8-flash, [抗截断]gemini-2.5-flash) now normalize to their canonical lowercase Gemini ID for capability and thinking-config detection while preserving feat: gemini 4 model series reasoning effort support without bumping google-genai #11219/feat: register Gemini 4 Neon thinking levels #11251's Gemini 4 reasoning_effort contract and AUTO/None defaults.
  2. Dated/preview/exp/revision Gemini 2.5 thinking models (e.g. gemini-2.5-flash-preview-09-2025, gemini-2.5-pro-preview-05-06) are matched by the default-deny allow-list while non-thinking 2.5 variants (-image, -tts, -native-audio, -computer-use) remain excluded.

All 50 tests in tests/test_gemini_source.py and ruff checks pass.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants