Skip to content

fix: keep mldev candidate parts separate#2565

Open
he-yufeng wants to merge 1 commit into
googleapis:mainfrom
he-yufeng:fix/candidate-count-text-isolation
Open

fix: keep mldev candidate parts separate#2565
he-yufeng wants to merge 1 commit into
googleapis:mainfrom
he-yufeng:fix/candidate-count-text-isolation

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

Summary

Fixes #2507.

The Gemini Developer API can return multiple candidates with the later candidates' parts duplicated onto candidates[0].content.parts. The SDK then exposes response.text as the concatenation of every candidate, even though the helper says it returns the first candidate.

This normalizes only that exact mldev shape: when the tail of candidate 0's parts matches the parts from the sibling candidates, the duplicated tail is removed before the response model is built. Ordinary multi-part first-candidate responses are left alone.

Tests

python -m py_compile google\genai\models.py google\genai\tests\types\test_part_type.py
python -m pytest google\genai\tests\types\test_part_type.py::test_mldev_candidate_count_keeps_candidate_parts_separate google\genai\tests\types\test_part_type.py::test_two_candidates_text -q
python -m pytest google\genai\tests\types\test_part_type.py -q
python -m mypy google\genai\models.py --config-file pyproject.toml
git diff --check

@Venkaiahbabuneelam Venkaiahbabuneelam self-assigned this Jun 8, 2026
@Venkaiahbabuneelam Venkaiahbabuneelam added the size:L Code changes between 40-100 lines label Jun 8, 2026
@he-yufeng he-yufeng force-pushed the fix/candidate-count-text-isolation branch from 14f6cdb to ed07486 Compare June 12, 2026 11:47
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Rebased this branch onto current main and pushed the updated head ed07486.

Validation:

  • python -m pytest google\genai\tests\types\test_part_type.py -q -k "mldev_candidate_count_keeps_candidate_parts_separate" -> passed, 1 passed
  • python -m py_compile google\genai\models.py google\genai\tests\types\test_part_type.py -> passed
  • git diff --check upstream/main..HEAD -> passed

@he-yufeng he-yufeng force-pushed the fix/candidate-count-text-isolation branch from ed07486 to 1a05aa9 Compare June 12, 2026 14:11
@he-yufeng he-yufeng force-pushed the fix/candidate-count-text-isolation branch from 1a05aa9 to 95937b9 Compare June 12, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L Code changes between 40-100 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

candidate_count > 1: candidates[0].content.parts contains every candidate's text; response.text concatenates them all

2 participants