Repository navigation
fix(openai): unwrap accidentally nested extra_body in custom_extra_body - #11615
Open
JosephTian876 wants to merge 1 commit into
Open
JosephTian876 wants to merge 1 commit into
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 |
JosephTian876
force-pushed
the
fix/gemini-openai-extra-body-guard
branch
from
December 4, 2026 04:12
b6c2b15 to
aa4ebfa
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
Guards
ProviderOpenAIOfficialagainst accidentalextra_bodydouble-wrapping when users configurecustom_extra_bodyfrom OpenAI SDK examples (particularly Google's Gemini OpenAI-compatibility docs).Problem
Google's Gemini OpenAI-compatible documentation illustrates passing vendor options via the OpenAI Python SDK's
extra_bodykeyword argument:Because AstrBot already forwards
custom_extra_bodyas the SDK'sextra_body=argument, users who paste{"extra_body": {"google": ...}}intocustom_extra_bodyend up sending a double-wrapped wire payload:{"model": "gemini-3-pro-preview", "messages": [...], "extra_body": {"google": {"thinking_config": {"thinking_level": "low"}}}}Upstream endpoints ignore or reject the unexpected top-level
"extra_body"key.Changes
ProviderOpenAIOfficial._unwrap_nested_extra_body()invoked at the start of_apply_provider_specific_request_overrides()(covering both_query()and_query_stream()):"extra_body"into top-levelextra_bodykeys (bounded depth to guard against pathological nesting).self.provider_config["custom_extra_body"]unmutated."extra_body"values untouched.custom_extra_body.custom_extra_bodyschema hints inastrbot/core/config/default.pyand all four dashboard locale files (zh-CN,en-US,ja-JP,ru-RU), explicitly noting not to wrap keys in anotherextra_bodyobject and clarifying that OpenAI-compatible endpoints (includingGemini_OpenAI_API) do not support native Geminisafety_settings.httpx.MockTransport) directly intests/test_openai_source.py.Files Changed
astrbot/core/provider/sources/openai_source.pyastrbot/core/config/default.pydashboard/src/i18n/locales/{en-US,zh-CN,ja-JP,ru-RU}/features/config-metadata.jsontests/test_openai_source.pyVerification
ruff format --check .&ruff check .: passed (606 files formatted, 0 lint warnings).pytest tests/test_openai_source.py tests/test_provider_user_agent.py: 122 passed, 1 skipped.pytest tests/test_fastapi_v1_dashboard.py -k "provider": 11 passed.建议合并顺序 (Recommended Merge Order)
AstrBotcore PRs are mutually conflict-free (git merge-tree --write-treeverified across all 15 pairs; hunks indefault.pyand locale JSONs are ~200–300 lines apart fromfix/gemini-thinking-camelcase-and-safety):fix/plugin-service-closed-connectorfix/t2i-local-skip-external-probefix/aiocqhttp-at-member-fallbackfix/system-one-decision-float32-softmax-tolfix/gemini-thinking-camelcase-and-safetyfix/gemini-openai-extra-body-guard(this PR)