fix(gemini): strip audio format from speech configuration

This commit is contained in:
Emerson Gomes 2026-09-26 08:52:05 -05:00
parent 3e65e9ef0e
commit 2fdb818327
No known key found for this signature in database
GPG key ID: D3DF28AB5D1B5E17
2 changed files with 23 additions and 1 deletions

View file

@ -196,7 +196,9 @@ def normalize_gemini_speech_config(
if isinstance(nested_config, Mapping)
else value
)
normalized: Final = _normalize_gemini_speech_config_item(config)
normalized: Final = _normalize_gemini_speech_config_item(
{key: item for key, item in config.items() if key != "format"}
)
voice_name: Final = next(
(normalized[key] for key in ("name", "voiceName", "voice") if isinstance(normalized.get(key), str)),
None,

View file

@ -90,6 +90,26 @@ def test_gemini_request_keeps_voice_beside_nested_speech_config() -> None:
}
@pytest.mark.parametrize("wrapper", (None, "speech_config", "speechConfig"))
def test_gemini_request_keeps_voice_and_language_without_audio_format(wrapper: str | None) -> None:
voice: Final = {"language_code": "fr-FR", "voice": "Kore", "format": "pcm16"}
request: Final = SpeechToCompletionBridgeTransformationHandler().transform_request(
model=GEMINI_TTS_MODEL,
input="Bonjour",
voice=voice if wrapper is None else {wrapper: voice},
optional_params={},
litellm_params={},
headers={},
litellm_logging_obj=MagicMock(),
custom_llm_provider="gemini",
)
assert request["audio"]["speech_config"] == {
"languageCode": "fr-FR",
"voiceConfig": {"prebuiltVoiceConfig": {"voiceName": "Kore"}},
}
@pytest.mark.parametrize("response_format", ["mp3", "flac", "opus", "aac"])
def test_gemini_tts_request_rejects_formats_gemini_cannot_produce(response_format: str) -> None:
with pytest.raises(litellm.BadRequestError) as excinfo: