Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions litellm/llms/openai/transcriptions/whisper_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def get_complete_url(

return api_base or ""

def get_supported_openai_params(
self, model: str
) -> List[OpenAIAudioTranscriptionOptionalParams]:
def get_supported_openai_params(self, model: str) -> List[OpenAIAudioTranscriptionOptionalParams]:
"""
Get the supported OpenAI params for the `whisper-1` models
"""
Expand All @@ -70,10 +68,9 @@ def map_openai_params(
"""
Map the OpenAI params to the Whisper params
"""
supported_params = self.get_supported_openai_params(model)
for k, v in non_default_params.items():
if k in supported_params:
optional_params[k] = v
supported_params = set(self.get_supported_openai_params(model))
for k in supported_params.intersection(non_default_params):
optional_params[k] = non_default_params[k]
return optional_params

def validate_environment(
Expand Down Expand Up @@ -107,20 +104,14 @@ def transform_audio_transcription_request(
"""
data = {"model": model, "file": audio_file, **optional_params}

if "response_format" not in data or (
data["response_format"] == "text" or data["response_format"] == "json"
):
data["response_format"] = (
"verbose_json" # ensures 'duration' is received - used for cost calculation
)
if "response_format" not in data or (data["response_format"] == "text" or data["response_format"] == "json"):
data["response_format"] = "verbose_json" # ensures 'duration' is received - used for cost calculation

return AudioTranscriptionRequestData(
data=data,
)

def get_error_class(
self, error_message: str, status_code: int, headers: Union[dict, Headers]
) -> BaseLLMException:
def get_error_class(self, error_message: str, status_code: int, headers: Union[dict, Headers]) -> BaseLLMException:
return OpenAIError(
status_code=status_code,
message=error_message,
Expand All @@ -134,14 +125,9 @@ def transform_audio_transcription_response(
try:
raw_response_json = raw_response.json()
except Exception as e:
raise ValueError(
f"Error transforming response to json: {str(e)}\nResponse: {raw_response.text}"
)
raise ValueError(f"Error transforming response to json: {str(e)}\nResponse: {raw_response.text}")

if any(
key in raw_response_json
for key in TranscriptionResponse.model_fields.keys()
):
if any(key in raw_response_json for key in TranscriptionResponse.model_fields.keys()):
return TranscriptionResponse(**raw_response_json)
else:
raise ValueError(
Expand Down