mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-09 22:31:41 +00:00
fix(azure): price azure_ai transcriptions at the azure_ai cost-map entry
This commit is contained in:
parent
3cadf2f8f7
commit
831a2a13fb
3 changed files with 67 additions and 2 deletions
|
|
@ -37,6 +37,7 @@ class AzureAudioTranscription(AzureChatCompletion):
|
|||
azure_ad_token: str | None = None,
|
||||
atranscription: bool = False,
|
||||
litellm_params: dict | None = None,
|
||||
custom_llm_provider: str = "azure",
|
||||
) -> TranscriptionResponse | Coroutine[Any, Any, TranscriptionResponse]:
|
||||
data: Final = {"model": model, "file": audio_file, **optional_params}
|
||||
|
||||
|
|
@ -53,6 +54,7 @@ class AzureAudioTranscription(AzureChatCompletion):
|
|||
logging_obj=logging_obj,
|
||||
model=model,
|
||||
litellm_params=litellm_params,
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
)
|
||||
|
||||
azure_client: Final = self.get_azure_openai_client(
|
||||
|
|
@ -99,7 +101,7 @@ class AzureAudioTranscription(AzureChatCompletion):
|
|||
additional_args={"complete_input_dict": data},
|
||||
original_response=stringified_response,
|
||||
)
|
||||
hidden_params: Final = {"model": model, "custom_llm_provider": "azure"}
|
||||
hidden_params: Final = {"model": model, "custom_llm_provider": custom_llm_provider}
|
||||
final_response: Final[TranscriptionResponse] = convert_to_model_response_object(
|
||||
response_object=stringified_response,
|
||||
model_response_object=model_response,
|
||||
|
|
@ -122,6 +124,7 @@ class AzureAudioTranscription(AzureChatCompletion):
|
|||
client=None,
|
||||
max_retries=None,
|
||||
litellm_params: dict | None = None,
|
||||
custom_llm_provider: str = "azure",
|
||||
) -> TranscriptionResponse:
|
||||
response = None
|
||||
try:
|
||||
|
|
@ -178,7 +181,7 @@ class AzureAudioTranscription(AzureChatCompletion):
|
|||
},
|
||||
original_response=stringified_response,
|
||||
)
|
||||
hidden_params: Final = {"model": model, "custom_llm_provider": "azure"}
|
||||
hidden_params: Final = {"model": model, "custom_llm_provider": custom_llm_provider}
|
||||
response = convert_to_model_response_object(
|
||||
_response_headers=headers,
|
||||
response_object=stringified_response,
|
||||
|
|
|
|||
|
|
@ -7805,6 +7805,7 @@ def transcription(
|
|||
azure_ad_token=azure_ad_token,
|
||||
max_retries=max_retries,
|
||||
litellm_params=litellm_params_dict,
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
)
|
||||
elif custom_llm_provider == "openai" or (custom_llm_provider in litellm.openai_compatible_providers):
|
||||
api_base = (
|
||||
|
|
|
|||
61
tests/test_litellm/llms/azure/test_audio_transcriptions.py
Normal file
61
tests/test_litellm/llms/azure/test_audio_transcriptions.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import json
|
||||
from pathlib import Path
|
||||
from typing import Final
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
from openai import AzureOpenAI
|
||||
|
||||
import litellm
|
||||
from litellm.cost_calculator import completion_cost
|
||||
from litellm.litellm_core_utils.audio_utils.utils import calculate_request_duration
|
||||
|
||||
AUDIO_FILE: Final = Path(__file__).parents[3] / "gettysburg.wav"
|
||||
WHISPER_COST_PER_SECOND: Final = 0.0001
|
||||
|
||||
|
||||
def _transcription_client() -> AzureOpenAI:
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
return httpx.Response(200, json={"text": "Four score and seven years ago"})
|
||||
|
||||
return AzureOpenAI(
|
||||
api_key="test-key",
|
||||
api_version="2024-06-01",
|
||||
azure_endpoint="https://example.cognitiveservices.azure.com",
|
||||
http_client=httpx.Client(transport=httpx.MockTransport(handler)),
|
||||
)
|
||||
|
||||
|
||||
def test_azure_ai_transcription_is_priced_at_the_azure_ai_entry():
|
||||
with AUDIO_FILE.open("rb") as audio:
|
||||
response = litellm.transcription(
|
||||
model="azure_ai/whisper",
|
||||
file=audio,
|
||||
api_base="https://example.cognitiveservices.azure.com",
|
||||
api_key="test-key",
|
||||
api_version="2024-06-01",
|
||||
client=_transcription_client(),
|
||||
)
|
||||
with AUDIO_FILE.open("rb") as audio:
|
||||
duration = calculate_request_duration(audio)
|
||||
|
||||
assert duration is not None and duration > 0
|
||||
assert response._hidden_params["custom_llm_provider"] == "azure_ai"
|
||||
assert completion_cost(completion_response=response, call_type="transcription") == pytest.approx(
|
||||
WHISPER_COST_PER_SECOND * duration
|
||||
)
|
||||
|
||||
|
||||
def test_azure_transcription_keeps_the_azure_provider():
|
||||
with AUDIO_FILE.open("rb") as audio:
|
||||
response = litellm.transcription(
|
||||
model="azure/whisper-1",
|
||||
file=audio,
|
||||
api_base="https://example.openai.azure.com",
|
||||
api_key="test-key",
|
||||
api_version="2024-06-01",
|
||||
client=_transcription_client(),
|
||||
)
|
||||
|
||||
assert response._hidden_params["custom_llm_provider"] == "azure"
|
||||
assert json.loads(response.model_dump_json())["text"] == "Four score and seven years ago"
|
||||
Loading…
Add table
Reference in a new issue