Repository navigation
fix(gemini): normalize thinkingConfig wire casing, safety OFF/civic_integrity, and per-model overrides - #11614
Open
JosephTian876 wants to merge 1 commit into
Conversation
Contributor
|
Sorry @JosephTian876, you've used your own review budget of 250,000 diff characters for the last 7 days. You can request another review in 1 day and 7 hours by commenting |
…ntegrity, and per-model overrides
JosephTian876
force-pushed
the
fix/gemini-thinking-camelcase-and-safety
branch
from
December 4, 2026 04:15
397ee6b to
556e82a
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes five interoperability and configuration issues in the native Google Gemini provider (
ProviderGoogleGenAI):Serialize
generationConfig.thinkingConfigkeys in strict camelCase on the wiregoogle-genai(verified on both2.34.0and3.6.1) lacks_ThinkingConfig_to_mldev/_ThinkingConfig_to_vertexingoogle.genai.models._GenerateContentConfig_to_mldev, soconvert_to_dict(..., convert_keys=False)emits snake_case keys (thinking_level,thinking_budget,include_thoughts) instead of the documented REST camelCase keys (thinkingLevel,thinkingBudget,includeThoughts).encoding/jsonproxies such as New-API / One-API) silently drop snake_case fields, causing thinking configuration to be ignored._GeminiAsyncClient(httpx.AsyncClient)overriding the publicbuild_request()hook to normalize snake_case keys insidegenerationConfig.thinkingConfigto camelCase for:generateContentand:streamGenerateContentPOST bodies (fast-path byte guard when no snake_case markers exist; recomputesContent-Lengthcleanly; works transparently across direct connections, proxies, and custom transports).Add
HarmBlockThreshold.OFFandHARM_CATEGORY_CIVIC_INTEGRITYsafety settings"OFF": types.HarmBlockThreshold.OFFtoTHRESHOLD_MAPPINGand"civic_integrity": types.HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITYtoCATEGORY_MAPPING.OFFandcivic_integrityinastrbot/core/config/default.pyand all four dashboard i18n locale metadata files (zh-CN,en-US,ja-JP,ru-RU), without forcingcivic_integrityonto existing configs unless explicitly configured.Guard
thinking_budget=0ongemini-2.5-pro*thinking_budget=0triggers HTTP 400; legacy configs often retainbudget: 0).thinking_budget == 0ongemini-2.5-pro*, logs a warning suggesting-1(dynamic) or>=128, and omitsthinking_budgetinstead of sending an invalid value.gemini-2.5-flash/gemini-2.5-flash-litecontinue to accept0.Widen Gemini 2.5 thinking allow-list for
-thinkingand-latestrelay aliases_GEMINI_25_THINKING_MODEL_REto match-thinkingand-latestvariants (e.g.,gemini-2.5-pro-thinking,gemini-2.5-flash-thinking-05-20,gemini-2.5-pro-preview-05-06-thinking,gemini-2.5-flash-latest) while preserving strict default-deny exclusion of non-thinking 2.5 variants (image,tts,native-audio,computer-use).Allow safe per-model thinking & safety overrides in
custom_extra_body+ tighten Gemini 3 level validationcustom_extra_body(thinking_config/thinkingConfig,thinking_level/thinkingLevel/reasoning_effort,thinking_budget/thinkingBudget,include_thoughts/includeThoughts, andsafety_settings/safetySettingsas either a category-merge dict or a Gemini REST list), while still raisingValueErroron unknown parameters.gemini-3-pro*acceptsLOW/HIGH;gemini-3.1-pro*/3.7/3.8acceptLOW/MEDIUM/HIGH;gemini-3-flash*acceptsMINIMAL/LOW/MEDIUM/HIGH. Preserves Gemini 4 behavior (ignoring legacygm_thinking_config.levelin favor of explicit per-modelreasoning_effort/thinking_level).Files Changed
astrbot/core/provider/sources/gemini_source.pyastrbot/core/config/default.pydashboard/src/i18n/locales/{en-US,zh-CN,ja-JP,ru-RU}/features/config-metadata.jsontests/test_gemini_source.pyVerification
ruff format --check .&ruff check .: passed (606 files formatted, 0 lint warnings).pytest tests/test_gemini_source.py tests/test_provider_user_agent.py tests/test_dashboard.py: 169 passed, 2 skipped.pytest tests/test_fastapi_v1_dashboard.py -k "provider": 11 passed.:generateContentand streaming:streamGenerateContent) viahttpx.MockTransporton bothgoogle-genai==3.6.1andgoogle-genai==2.34.0: confirmed strict camelCase (thinkingLevel,thinkingBudget,includeThoughts), zero snake_case leaks, matchingContent-Length, andOFF/HARM_CATEGORY_CIVIC_INTEGRITYserialization.建议合并顺序 (Recommended Merge Order)
AstrBotcore PRs are mutually conflict-free (git merge-tree --write-treeverified across all 15 pairs):fix/plugin-service-closed-connectorfix/t2i-local-skip-external-probefix/aiocqhttp-at-member-fallbackfix/system-one-decision-float32-softmax-tolfix/gemini-thinking-camelcase-and-safety(this PR) — recommended beforefix/gemini-openai-extra-body-guardso native Gemini thinking & safety controls are already landed.fix/gemini-openai-extra-body-guard