fix(gemini): reject nonnumeric candidate counts for long decode

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
mateo 2026-10-31 11:14:39 +00:00
parent a713ed6bab
commit 6d83312d2f
2 changed files with 11 additions and 2 deletions

View file

@ -87,7 +87,9 @@ def _int_or_none(value: object) -> int | None:
def _asks_for_one_candidate(generation_config: Mapping[str, object]) -> bool:
return all(
_int_or_none(generation_config[key] or 1) == 1 for key in _CANDIDATE_COUNT_KEYS if key in generation_config
generation_config[key] is None or _int_or_none(generation_config[key]) in (0, 1)
for key in _CANDIDATE_COUNT_KEYS
if key in generation_config
)

View file

@ -518,7 +518,14 @@ async def test_unary_answer_cut_at_the_callers_cap_is_returned_with_its_token_in
@pytest.mark.parametrize(
"choice_count_request",
[{"max_tokens": 100_000, "n": 2}, {"extra_body": {"generationConfig": {"candidateCount": 2}}}],
[
{"max_tokens": 100_000, "n": 2},
{"extra_body": {"generationConfig": {"candidateCount": 2}}},
{"max_tokens": 100_000, "n": ""},
{"max_tokens": 100_000, "n": []},
{"max_tokens": 100_000, "n": {}},
{"max_tokens": 100_000, "n": "1"},
],
)
@pytest.mark.parametrize("is_async", [True, False])
@pytest.mark.asyncio