mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-09 22:31:41 +00:00
fix(audio): log audio filename on async transcription errors
This commit is contained in:
parent
7e43b3fac7
commit
39001f75cd
4 changed files with 64 additions and 2 deletions
|
|
@ -191,7 +191,7 @@ class AzureAudioTranscription(AzureChatCompletion):
|
|||
except Exception as e:
|
||||
## LOGGING
|
||||
logging_obj.post_call(
|
||||
input=input,
|
||||
input=get_audio_file_name(audio_file),
|
||||
api_key=api_key,
|
||||
original_response=str(e),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -226,7 +226,7 @@ class OpenAIAudioTranscription(OpenAIChatCompletion):
|
|||
except Exception as e:
|
||||
## LOGGING
|
||||
logging_obj.post_call(
|
||||
input=input,
|
||||
input=get_audio_file_name(audio_file),
|
||||
api_key=api_key,
|
||||
original_response=str(e),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -427,3 +427,36 @@ class TestAzureExceptionMapping:
|
|||
error = exc_info.value
|
||||
assert "encrypted_content_affinity" in error.message
|
||||
assert "enable_pre_call_checks" in error.message
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_audio_transcription_error_path_logs_audio_filename(
|
||||
self,
|
||||
):
|
||||
from litellm.litellm_core_utils.audio_utils.utils import get_audio_file_name
|
||||
from litellm.llms.azure.audio_transcriptions import AzureAudioTranscription
|
||||
from litellm.utils import TranscriptionResponse
|
||||
|
||||
audio_file = ("test.wav", b"fake audio", "audio/wav")
|
||||
expected_error = RuntimeError("azure upstream failure")
|
||||
handler = AzureAudioTranscription()
|
||||
handler.get_azure_openai_client = MagicMock(side_effect=expected_error)
|
||||
logging_obj = MagicMock()
|
||||
|
||||
with pytest.raises(RuntimeError) as exc_info:
|
||||
await handler.async_audio_transcriptions(
|
||||
audio_file=audio_file,
|
||||
model="whisper-1",
|
||||
data={"model": "whisper-1", "file": audio_file},
|
||||
model_response=TranscriptionResponse(),
|
||||
timeout=1,
|
||||
logging_obj=logging_obj,
|
||||
api_key="test-api-key",
|
||||
api_base="https://example.openai.azure.com",
|
||||
litellm_params={},
|
||||
)
|
||||
|
||||
assert exc_info.value is expected_error
|
||||
logging_obj.post_call.assert_called_once()
|
||||
kwargs = logging_obj.post_call.call_args.kwargs
|
||||
assert kwargs["input"] == get_audio_file_name(audio_file)
|
||||
assert kwargs["original_response"] == str(expected_error)
|
||||
|
|
|
|||
|
|
@ -104,3 +104,32 @@ class TestWhisperTransformResponse:
|
|||
is_json=False,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_transcription_error_path_logs_audio_filename():
|
||||
from litellm.litellm_core_utils.audio_utils.utils import get_audio_file_name
|
||||
from litellm.llms.openai.transcriptions.handler import OpenAIAudioTranscription
|
||||
from litellm.utils import TranscriptionResponse
|
||||
|
||||
audio_file = ("test.wav", b"fake audio", "audio/wav")
|
||||
expected_error = RuntimeError("upstream failure")
|
||||
handler = OpenAIAudioTranscription()
|
||||
handler._get_openai_client = MagicMock(side_effect=expected_error)
|
||||
logging_obj = MagicMock()
|
||||
|
||||
with pytest.raises(RuntimeError) as exc_info:
|
||||
await handler.async_audio_transcriptions(
|
||||
audio_file=audio_file,
|
||||
data={"model": "whisper-1", "file": audio_file},
|
||||
model_response=TranscriptionResponse(),
|
||||
timeout=1,
|
||||
logging_obj=logging_obj,
|
||||
api_key="test-api-key",
|
||||
)
|
||||
|
||||
assert exc_info.value is expected_error
|
||||
logging_obj.post_call.assert_called_once()
|
||||
kwargs = logging_obj.post_call.call_args.kwargs
|
||||
assert kwargs["input"] == get_audio_file_name(audio_file)
|
||||
assert kwargs["original_response"] == str(expected_error)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue