fix(audio): don't override explicit response_format with verbose_json

This commit is contained in:
cohml 2026-06-09 22:34:23 -04:00 • committed by Chris Hamill
parent 9608dd51ac
commit 01556557f4
2 changed files with 44 additions and 3 deletions

View file

@ -107,9 +107,7 @@ class OpenAIWhisperAudioTranscriptionConfig(BaseAudioTranscriptionConfig):
"""
data = {"model": model, "file": audio_file, **optional_params}
if "response_format" not in data or (
data["response_format"] == "text" or data["response_format"] == "json"
):
if "response_format" not in data:
data["response_format"] = (
"verbose_json" # ensures 'duration' is received - used for cost calculation
)

View file

@ -0,0 +1,43 @@
"""
Tests for OpenAIWhisperAudioTranscriptionConfig.transform_audio_transcription_request.
"""
import io
from litellm.llms.openai.transcriptions.whisper_transformation import (
OpenAIWhisperAudioTranscriptionConfig,
)
class TestWhisperTransformRequestResponseFormat:
def _transform(self, optional_params: dict) -> dict:
config = OpenAIWhisperAudioTranscriptionConfig()
audio_file = io.BytesIO(b"fake audio")
audio_file.name = "test.wav"
result = config.transform_audio_transcription_request(
model="whisper-1",
audio_file=audio_file,
optional_params=optional_params,
litellm_params={},
)
return result.data
def test_defaults_to_verbose_json_when_unset(self):
"""When response_format is not specified, default to verbose_json for cost calculation."""
data = self._transform({})
assert data["response_format"] == "verbose_json"
def test_respects_explicit_json(self):
"""When response_format='json' is set, do not override to verbose_json."""
data = self._transform({"response_format": "json"})
assert data["response_format"] == "json"
def test_respects_explicit_text(self):
"""When response_format='text' is set, do not override to verbose_json."""
data = self._transform({"response_format": "text"})
assert data["response_format"] == "text"
def test_preserves_verbose_json_when_set(self):
"""verbose_json explicitly set by the caller stays as-is."""
data = self._transform({"response_format": "verbose_json"})
assert data["response_format"] == "verbose_json"