mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-13 03:59:12 +00:00
fix(gemini): strip audio format from speech configuration
This commit is contained in:
parent
3e65e9ef0e
commit
2fdb818327
2 changed files with 23 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue