Repository navigation
Python: Honor the requested model in non-streamed Gemini responses - #9736
Open
Ayoub (Ayoubhm07) wants to merge 1 commit into
Open
Ayoub (Ayoubhm07) wants to merge 1 commit into
Ayoub (Ayoubhm07) wants to merge 1 commit into
Conversation
_get_response resolved the request model but did not pass it to _process_generate_response, which fell back to the client default when the response carried no model_version. The streaming path already falls back to the resolved model, so the same call was labelled differently depending on stream. _process_generate_response now takes the request model as a keyword-only argument and falls back to it before the client default.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The narrow fix preserves existing callers and server-reported model precedence, with focused regression coverage for the corrected behavior.
No open issues 🎉
What changed in this PR
Fixes #9548 by making Gemini non-streaming responses report the requested model when the API omits model_version, matching streaming behavior.
Changes:
- Passes the resolved request model into non-streaming response processing.
- Preserves server-reported model precedence and the existing client-default fallback.
- Adds regression tests for per-call model overrides on both paths and the client-default fallback.
| File | Description |
|---|---|
python/packages/gemini/tests/test_gemini_client.py |
Adds model-fallback and streaming/non-streaming parity tests. |
python/packages/gemini/agent_framework_gemini/_chat_client.py |
Uses the requested model before the client default when processing responses. |
Review effort: Balanced
This branch was successfully 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.
Motivation & Context
Follow-up I offered in #9139.
_get_responseresolves the request model (:515) but never passes it to_process_generate_response(:527), which falls back toself.model, the client default (:1088). The streaming path has fallen back to the resolved model since #9139, so agemini-2.5-flashclient called withoptions={"model": "gemini-2.5-pro"}reportsgemini-2.5-prowhen streamed andgemini-2.5-flashwhen not, whenever the response carries nomodel_version.Description & Review Guide
_process_generate_responsetakes the request model as a keyword-onlymodeland falls back to it beforeself.model._get_responsepasses it.model_versionback changes: it now reports the requested model. A call without the new keyword behaves as before. One test, parametrized overstream, pins that both paths report the requested model (stream=Falsefails onmain); another pins the client-default fallback. Gemini tests: 264 passed, 10 skipped. Ruff, pyright, mypy, pyrefly, ty and zuban report nothing new at the pinned versions.Nonedefault, the same shape as the Bedrock fix in Python: fix(bedrock): report the requested model on non-streaming responses #9399, so existing calls are unaffected. This PR only touches Gemini; Bedrock stays with Python: fix(bedrock): report the requested model on non-streaming responses #9399.Related Issue
Fixes #9548
AI Assistance
AI assistance details: used to draft the tests and this description. I checked that the new test fails on
main, reviewed the change and ran the Gemini tests myself.Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.