Skip to content

fix: align wire format for GeminiModel and GeminiCodeAssistModel. - #933

Draft
StarsExpress wants to merge 5 commits into
mpfaffenberger:mainfrom
StarsExpress:fix-gemini-wire-format
Draft

fix: align wire format for GeminiModel and GeminiCodeAssistModel.#933
StarsExpress wants to merge 5 commits into
mpfaffenberger:mainfrom
StarsExpress:fix-gemini-wire-format

Conversation

@StarsExpress

Copy link
Copy Markdown
Contributor

Fixes issue #461 to consolidate duplicated Gemini wire-format logic between gemini_model.py::GeminiModel and gemini_code_assist.py::GeminiCodeAssistModel.


Changes

Per issue #461's Proposed Extraction, several functions moved into a new code_puppy/gemini_common.py:

1. _sanitize_schema_for_gemini + _flatten_union_to_object_gemini + generate_tool_call_id

  • Previously only in gemini_model.py. Now they are all in gemini_common.py to get called by methods in either gemini_model.py or gemini_common.py, since gemini_model.py depends on gemini_common.py.

  • Relationship: _build_tools calls _sanitize_schema_for_gemini, which calls _flatten_union_to_object_gemini.

2. _build_tools

  • Shared by GeminiModel and GeminiCodeAssistModel: both emit sanitized schemas under parameters key.

3. _build_generation_config

  • Shared by GeminiModel and GeminiCodeAssistModel: reads ModelSettings correctly via .get(), as ModelSettings is a TypedDict, not an object with attributes.

  • Additionally handles thinking_level & thinkingConfig.

4. _parse_candidate_parts

  • Shared by GeminiModel and GeminiCodeAssistModel: per-part text/functionCall/thought loop + usageMetadata extraction, per issue's exact scope.

Tests

New tests/test_gemini_common_full_coverage.py covers shared functions directly, like:

  • Schema sanitization.
  • Generation config.
  • Candidate parsing — thinking parts, function calls with/without API-supplied ids, empty candidates, usage extraction.

Existing test_gemini_code_assist.py also updated where it asserted the old buggy behavior from GeminiCodeAssistModel's drifted usages.

For test_gemini_model_full_coverage.py, since _sanitize_schema_for_gemini + _flatten_union_to_object_gemini + generate_tool_call_id all joined gemini_common.py, their corresponding tests have moved into test_gemini_common_full_coverage.py.

Added `gemini_common.py` and corresponding tests.
Also adjusted `test_gemini_code_assist.py::test_build_request_with_tools` assertions to reflect current status.
@StarsExpress StarsExpress changed the title fix: aligned gemini wire format for GeminiModel and GeminiCodeAssistModel. fix: align gemini wire format for GeminiModel and GeminiCodeAssistModel. Sep 11, 2026
@StarsExpress StarsExpress changed the title fix: align gemini wire format for GeminiModel and GeminiCodeAssistModel. fix: align wire format for GeminiModel and GeminiCodeAssistModel. Sep 11, 2026
@StarsExpress
StarsExpress marked this pull request as ready for review September 11, 2026 16:27
@StarsExpress
StarsExpress marked this pull request as draft September 11, 2026 16:38
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