mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-22 00:31:44 +00:00
fix(azure): surface speech recognition failures
Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>
This commit is contained in:
parent
2e5d70570e
commit
126dc2ca16
2 changed files with 29 additions and 0 deletions
|
|
@ -133,6 +133,17 @@ class AzureSpeechAudioTranscriptionConfig(BaseAudioTranscriptionConfig):
|
|||
raw_response: httpx.Response,
|
||||
) -> TranscriptionResponse:
|
||||
response_json = raw_response.json()
|
||||
recognition_status = response_json.get("RecognitionStatus")
|
||||
if recognition_status is not None and recognition_status != "Success":
|
||||
raise AzureSpeechAudioTranscriptionException(
|
||||
message=(
|
||||
"Azure AI Speech transcription failed with "
|
||||
f"RecognitionStatus={recognition_status}."
|
||||
),
|
||||
status_code=raw_response.status_code,
|
||||
headers=raw_response.headers,
|
||||
)
|
||||
|
||||
text = self._extract_text(response_json)
|
||||
response = TranscriptionResponse(text=text)
|
||||
response._hidden_params = response_json
|
||||
|
|
|
|||
|
|
@ -183,6 +183,24 @@ def test_azure_speech_audio_transcription_response_transform(payload, expected_t
|
|||
assert result._hidden_params == payload
|
||||
|
||||
|
||||
def test_azure_speech_audio_transcription_response_raises_on_failed_status():
|
||||
config = AzureSpeechAudioTranscriptionConfig()
|
||||
response = httpx.Response(
|
||||
200,
|
||||
json={
|
||||
"RecognitionStatus": "NoMatch",
|
||||
"Offset": 0,
|
||||
"Duration": 0,
|
||||
},
|
||||
)
|
||||
|
||||
with pytest.raises(
|
||||
AzureSpeechAudioTranscriptionException,
|
||||
match="RecognitionStatus=NoMatch",
|
||||
):
|
||||
config.transform_audio_transcription_response(response)
|
||||
|
||||
|
||||
def test_azure_speech_transcription_routes_through_provider_config(monkeypatch):
|
||||
expected = TranscriptionResponse(text="hello")
|
||||
audio_handler = MagicMock(return_value=expected)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue