mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
fix(azure/realtime): use byte-aware close reason for transcription socket errors
Greptile flagged that reason[:120] truncates by characters, so a multibyte Azure error can push the close frame past the 123-byte WebSocket limit and turn the readable 1008 close into a generic 1011. Route both close reasons through websocket_close_reason.
This commit is contained in:
parent
590c9d134e
commit
9afa462966
1 changed files with 11 additions and 2 deletions
|
|
@ -19,6 +19,7 @@ from litellm.constants import (
|
|||
from litellm.types.realtime import RealtimeQueryParams
|
||||
|
||||
from ....litellm_core_utils.litellm_logging import Logging as LiteLLMLogging
|
||||
from ....litellm_core_utils.realtime_errors import websocket_close_reason
|
||||
from ....litellm_core_utils.realtime_streaming import (
|
||||
RealTimeStreaming,
|
||||
ScopedWebSocket,
|
||||
|
|
@ -242,7 +243,12 @@ class AzureOpenAIRealtime(AzureChatCompletion):
|
|||
else None
|
||||
)
|
||||
if isinstance(minted, _EphemeralMintError):
|
||||
await websocket.close(code=1008, reason=_redact_string(minted.reason)[:120])
|
||||
await websocket.close(
|
||||
code=1008,
|
||||
reason=websocket_close_reason(
|
||||
_redact_string(minted.reason), fallback="Realtime transcription session error"
|
||||
),
|
||||
)
|
||||
return
|
||||
|
||||
url: Final = self._construct_url(
|
||||
|
|
@ -280,6 +286,9 @@ class AzureOpenAIRealtime(AzureChatCompletion):
|
|||
await realtime_streaming.bidirectional_forward()
|
||||
|
||||
except websockets.exceptions.InvalidStatusCode as e:
|
||||
await websocket.close(code=e.status_code, reason=_redact_string(str(e)))
|
||||
await websocket.close(
|
||||
code=e.status_code,
|
||||
reason=websocket_close_reason(_redact_string(str(e)), fallback="Invalid status code"),
|
||||
)
|
||||
except Exception:
|
||||
verbose_proxy_logger.exception("Error in AzureOpenAIRealtime.async_realtime")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue