fix: map response_format to output_format for TTS

response_format was declared as supported but never mapped to
the ModelsLab API parameter. Now maps mp3/wav/ogg to output_format.

Add tests for response_format mapping.

Note: time.sleep() polling still blocks async event loop - this is
a known limitation of sync polling in LiteLLM's TTS path.
This commit is contained in:
adhikjoshi 2026-03-04 09:23:04 +05:30
parent 239abc14ae
commit 59e664d7e2
2 changed files with 27 additions and 0 deletions

View file

@ -100,6 +100,12 @@ class ModelsLabTextToSpeechConfig(BaseTextToSpeechConfig):
except (ValueError, TypeError):
pass
# Map response_format (mp3, wav, etc.)
if "response_format" in optional_params:
fmt = optional_params["response_format"]
if fmt in ("mp3", "wav", "ogg"):
mapped["output_format"] = fmt
# Language from extra params
if "language" in kwargs:
lang = kwargs["language"]

View file

@ -58,6 +58,27 @@ class TestModelsLabTTSTransformation:
)
assert params["speed"] == 1.5
def test_map_openai_params_response_format_mp3(self):
"""response_format mp3 maps to output_format mp3."""
_, params = self.config.map_openai_params(
model="default", optional_params={"response_format": "mp3"}, voice="alloy"
)
assert params["output_format"] == "mp3"
def test_map_openai_params_response_format_wav(self):
"""response_format wav maps to output_format wav."""
_, params = self.config.map_openai_params(
model="default", optional_params={"response_format": "wav"}, voice="alloy"
)
assert params["output_format"] == "wav"
def test_map_openai_params_response_format_ignored_for_invalid(self):
"""Invalid response_format values are ignored."""
_, params = self.config.map_openai_params(
model="default", optional_params={"response_format": "flac"}, voice="alloy"
)
assert "output_format" not in params
def test_get_supported_openai_params(self):
params = self.config.get_supported_openai_params("default")
assert "voice" in params