mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-13 23:11:40 +00:00
fix(realtime): speak exact content filter error message via TTS
Extract the human-readable error string from HTTPException.detail so the spoken warning says e.g. "Content blocked: keyword 'system update' detected" instead of the raw str(e) repr.
This commit is contained in:
parent
b3b931c9a9
commit
2d73090090
1 changed files with 11 additions and 5 deletions
|
|
@ -147,11 +147,17 @@ class RealTimeStreaming:
|
|||
session_id=item_id,
|
||||
)
|
||||
except Exception as e:
|
||||
safe_msg = (
|
||||
str(e)
|
||||
if str(e)
|
||||
else "I'm sorry, that request was blocked by the content filter."
|
||||
)
|
||||
# Extract the human-readable error from HTTPException detail dict,
|
||||
# falling back to str(e) for other exception types.
|
||||
try:
|
||||
detail = e.detail # type: ignore[attr-defined]
|
||||
safe_msg = (
|
||||
detail.get("error")
|
||||
if isinstance(detail, dict)
|
||||
else str(detail)
|
||||
) or "I'm sorry, that request was blocked by the content filter."
|
||||
except AttributeError:
|
||||
safe_msg = str(e) or "I'm sorry, that request was blocked by the content filter."
|
||||
# Ask OpenAI to speak the warning — TTS audio plays naturally in the client
|
||||
await self.backend_ws.send(
|
||||
json.dumps(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue