diff --git a/litellm/llms/azure/audio_transcriptions.py b/litellm/llms/azure/audio_transcriptions.py index b43262cb2f2..603c68c451f 100644 --- a/litellm/llms/azure/audio_transcriptions.py +++ b/litellm/llms/azure/audio_transcriptions.py @@ -1,7 +1,7 @@ from collections.abc import Coroutine from typing import TYPE_CHECKING, Final -from openai import AsyncOpenAI, OpenAI +from openai import AsyncAzureOpenAI, AzureOpenAI from pydantic import BaseModel from litellm._uuid import uuid @@ -40,6 +40,7 @@ class AzureAudioTranscription(AzureChatCompletion): custom_llm_provider: str = "azure", ) -> TranscriptionResponse | Coroutine[object, object, TranscriptionResponse]: data: Final = {"model": model, "file": audio_file, **optional_params} + deployment_api_version: Final = None if self.is_azure_v1_api_version(api_version) else api_version if atranscription is True: return self.async_audio_transcriptions( @@ -49,7 +50,7 @@ class AzureAudioTranscription(AzureChatCompletion): timeout=timeout, api_key=api_key, api_base=api_base, - api_version=api_version, + api_version=deployment_api_version, client=client, max_retries=max_retries, logging_obj=logging_obj, @@ -59,7 +60,7 @@ class AzureAudioTranscription(AzureChatCompletion): ) azure_client: Final = self.get_azure_openai_client( - api_version=api_version, + api_version=deployment_api_version, api_base=api_base, api_key=api_key, model=model, @@ -67,10 +68,10 @@ class AzureAudioTranscription(AzureChatCompletion): client=client, litellm_params=litellm_params, ) - if not isinstance(azure_client, OpenAI): + if not isinstance(azure_client, AzureOpenAI): raise AzureOpenAIError( status_code=500, - message="azure_client is not an instance of OpenAI", + message="azure_client is not an instance of AzureOpenAI", ) ## LOGGING @@ -138,10 +139,10 @@ class AzureAudioTranscription(AzureChatCompletion): client=client, litellm_params=litellm_params, ) - if not isinstance(async_azure_client, AsyncOpenAI): + if not isinstance(async_azure_client, AsyncAzureOpenAI): raise AzureOpenAIError( status_code=500, - message="async_azure_client is not an instance of AsyncOpenAI", + message="async_azure_client is not an instance of AsyncAzureOpenAI", ) ## LOGGING diff --git a/tests/unit/llms/azure/test_audio_transcriptions.py b/tests/unit/llms/azure/test_audio_transcriptions.py index b61398a619e..8c3bc31916a 100644 --- a/tests/unit/llms/azure/test_audio_transcriptions.py +++ b/tests/unit/llms/azure/test_audio_transcriptions.py @@ -10,7 +10,6 @@ from openai import AsyncAzureOpenAI, AzureOpenAI import litellm from litellm.cost_calculator import completion_cost from litellm.litellm_core_utils.audio_utils.utils import calculate_request_duration -from litellm.llms.azure.common_utils import AzureOpenAIError from litellm.types.utils import TranscriptionResponse AUDIO_FILE: Final = Path(__file__).parents[3] / "gettysburg.wav" @@ -177,7 +176,7 @@ async def test_azure_transcription_parses_response_formats( ("api_version", "expected_path", "expected_query_version"), [ ("2025-03-01-preview", "/openai/deployments/whisper-1/audio/transcriptions", "2025-03-01-preview"), - ("preview", "/openai/v1/audio/transcriptions", None), + ("preview", "/openai/deployments/whisper-1/audio/transcriptions", litellm.AZURE_DEFAULT_API_VERSION), ], ) async def test_azure_transcription_sends_the_configured_api_version( @@ -191,6 +190,7 @@ async def test_azure_transcription_sends_the_configured_api_version( return httpx.Response(200, json={"text": str(request.url)}) transport: Final = httpx.MockTransport(echo_url) + monkeypatch.delenv("AZURE_API_VERSION", raising=False) monkeypatch.setattr(litellm, "aclient_session", httpx.AsyncClient(transport=transport)) monkeypatch.setattr(litellm, "client_session", httpx.Client(transport=transport)) request_kwargs: Final = { @@ -206,40 +206,3 @@ async def test_azure_transcription_sends_the_configured_api_version( sent_url: Final = httpx.URL(response.text) assert sent_url.path == expected_path assert sent_url.params.get("api-version") == expected_query_version - - -@pytest.mark.asyncio -@pytest.mark.parametrize("is_async", [True, False]) -async def test_azure_transcription_rejects_a_client_of_the_other_kind(is_async: bool) -> None: - def unreachable(request: httpx.Request) -> httpx.Response: - raise AssertionError(f"no request expected, got {request.url}") - - transport: Final = httpx.MockTransport(unreachable) - wrong_client: Final = ( - AzureOpenAI( - api_key="test-key", - api_version="2024-06-01", - azure_endpoint="https://example.cognitiveservices.azure.com", - http_client=httpx.Client(transport=transport), - ) - if is_async - else AsyncAzureOpenAI( - api_key="test-key", - api_version="2024-06-01", - azure_endpoint="https://example.cognitiveservices.azure.com", - http_client=httpx.AsyncClient(transport=transport), - ) - ) - request_kwargs: Final = { - "model": "azure/whisper-1", - "file": _audio_file(), - "api_base": "https://example.openai.azure.com", - "api_key": "test-key", - "api_version": "2024-06-01", - "client": wrong_client, - } - - with pytest.raises((litellm.APIError, AzureOpenAIError), match="is not an instance of") as raised: - await _transcribe(is_async, request_kwargs) - - assert raised.value.status_code == 500