refactor: update model handling in Azure and OpenAI audio transcription classes (#11333)

- Changed hardcoded model "whisper-1" to dynamic model extraction in AzureAudioTranscription and OpenAIAudioTranscription classes.
- Added tests to ensure correct model mapping for various transcription models, including GPT-4o and Azure whisper-1.
This commit is contained in:
Cole McIntosh 2025-06-02 17:25:51 -06:00 • committed by GitHub
parent 75dbb86d34
commit ba89d4f00f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 75 additions and 4 deletions

View file

@ -94,7 +94,7 @@ class AzureAudioTranscription(AzureChatCompletion):
additional_args={"complete_input_dict": data},
original_response=stringified_response,
)
hidden_params = {"model": "whisper-1", "custom_llm_provider": "azure"}
hidden_params = {"model": model, "custom_llm_provider": "azure"}
final_response: TranscriptionResponse = convert_to_model_response_object(response_object=stringified_response, model_response_object=model_response, hidden_params=hidden_params, response_type="audio_transcription") # type: ignore
return final_response
@ -174,7 +174,7 @@ class AzureAudioTranscription(AzureChatCompletion):
},
original_response=stringified_response,
)
hidden_params = {"model": "whisper-1", "custom_llm_provider": "azure"}
hidden_params = {"model": model, "custom_llm_provider": "azure"}
response = convert_to_model_response_object(
_response_headers=headers,
response_object=stringified_response,

View file

@ -155,7 +155,7 @@ class OpenAIAudioTranscription(OpenAIChatCompletion):
additional_args={"complete_input_dict": data},
original_response=stringified_response,
)
hidden_params = {"model": "whisper-1", "custom_llm_provider": "openai"}
hidden_params = {"model": model, "custom_llm_provider": "openai"}
final_response: TranscriptionResponse = convert_to_model_response_object(response_object=stringified_response, model_response_object=model_response, hidden_params=hidden_params, response_type="audio_transcription") # type: ignore
return final_response
@ -210,7 +210,9 @@ class OpenAIAudioTranscription(OpenAIChatCompletion):
additional_args={"complete_input_dict": data},
original_response=stringified_response,
)
hidden_params = {"model": "whisper-1", "custom_llm_provider": "openai"}
# Extract the actual model from data instead of hardcoding "whisper-1"
actual_model = data.get("model", "whisper-1")
hidden_params = {"model": actual_model, "custom_llm_provider": "openai"}
return convert_to_model_response_object(response_object=stringified_response, model_response_object=model_response, hidden_params=hidden_params, response_type="audio_transcription") # type: ignore
except Exception as e:
## LOGGING

View file

@ -164,3 +164,72 @@ async def test_gpt_4o_transcribe():
await litellm.atranscription(
model="openai/gpt-4o-transcribe", file=audio_file, response_format="json"
)
@pytest.mark.asyncio
async def test_gpt_4o_transcribe_model_mapping():
"""Test that GPT-4o transcription models are correctly mapped and not hardcoded to whisper-1"""
# Test GPT-4o mini transcribe
response = await litellm.atranscription(
model="openai/gpt-4o-mini-transcribe",
file=audio_file,
response_format="json"
)
# Check that the response contains the correct model in hidden params
assert response._hidden_params is not None
assert response._hidden_params["model"] == "gpt-4o-mini-transcribe"
assert response._hidden_params["custom_llm_provider"] == "openai"
assert response.text is not None
# Test GPT-4o transcribe
response2 = await litellm.atranscription(
model="openai/gpt-4o-transcribe",
file=audio_file,
response_format="json"
)
# Check that the response contains the correct model in hidden params
assert response2._hidden_params is not None
assert response2._hidden_params["model"] == "gpt-4o-transcribe"
assert response2._hidden_params["custom_llm_provider"] == "openai"
assert response2.text is not None
# Test traditional whisper-1 still works
response3 = await litellm.atranscription(
model="openai/whisper-1",
file=audio_file,
response_format="json"
)
# Check that the response contains the correct model in hidden params
assert response3._hidden_params is not None
assert response3._hidden_params["model"] == "whisper-1"
assert response3._hidden_params["custom_llm_provider"] == "openai"
assert response3.text is not None
@pytest.mark.asyncio
async def test_azure_transcribe_model_mapping():
"""Test that Azure transcription models are correctly mapped and not hardcoded to whisper-1"""
# Test Azure whisper-1
try:
response = await litellm.atranscription(
model="azure/whisper-1",
file=audio_file,
response_format="json",
api_key=os.getenv("AZURE_EUROPE_API_KEY"),
api_base="https://my-endpoint-europe-berri-992.openai.azure.com/",
drop_params=True
)
# Check that the response contains the correct model in hidden params
assert response._hidden_params is not None
assert response._hidden_params["model"] == "whisper-1"
assert response._hidden_params["custom_llm_provider"] == "azure"
assert response.text is not None
except Exception as e:
# If Azure credentials are not available, skip this test
pytest.skip(f"Azure credentials not available: {str(e)}")