mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
fix(realtime): keep the proxy's realtime session gate off translation sessions
A key that opts out of a legacy callback guardrail now gets a working translation session, since the transcription-guardrail gate no longer sends a realtime session.update the translation upstream rejects
This commit is contained in:
parent
fb50c3d3ce
commit
5169f815c5
2 changed files with 33 additions and 2 deletions
|
|
@ -1362,8 +1362,12 @@ class RealTimeStreaming:
|
|||
return self._has_realtime_guardrails_for_event_hooks([GuardrailEventHooks.realtime_input_transcription])
|
||||
|
||||
def _should_disable_vad_auto_response(self) -> bool:
|
||||
"""Transcription-only sessions have no assistant turn to gate and reject realtime session updates."""
|
||||
return not self._is_transcription_session and self._has_audio_transcription_guardrails()
|
||||
"""Transcription and translation sessions have no assistant turn to gate and reject realtime session updates."""
|
||||
return (
|
||||
not self._is_transcription_session
|
||||
and not self._is_translation_session
|
||||
and self._has_audio_transcription_guardrails()
|
||||
)
|
||||
|
||||
async def run_realtime_guardrails(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -3402,6 +3402,33 @@ async def test_translation_rejects_applicable_guardrails_before_forwarding_audio
|
|||
backend.send.assert_awaited_once_with(input_event)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_translation_for_a_key_opted_out_of_a_legacy_callback_guardrail_gets_no_realtime_session_gate(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(litellm, "callbacks", [CustomGuardrail(guardrail_name="legacy-callback")])
|
||||
session_update: Final = json.dumps({"type": "session.update", "session": {"audio": {"output": {"language": "es"}}}})
|
||||
session_created: Final = {"type": "session.created", "session": {"type": "translation"}}
|
||||
client: Final = _ga_client_ws()
|
||||
client.receive_text = AsyncMock(side_effect=[session_update, ConnectionClosed(None, None)])
|
||||
client.close = AsyncMock()
|
||||
backend: Final = MagicMock()
|
||||
backend.send = AsyncMock()
|
||||
backend.recv = AsyncMock(side_effect=[json.dumps(session_created), ConnectionClosed(None, None)])
|
||||
streaming: Final = RealTimeStreaming(
|
||||
websocket=client,
|
||||
backend_ws=backend,
|
||||
logging_obj=_mock_logging(),
|
||||
translation_session=True,
|
||||
request_data={"litellm_metadata": {"user_api_key_metadata": {"disable_global_guardrails": True}}},
|
||||
)
|
||||
|
||||
await streaming.bidirectional_forward()
|
||||
|
||||
assert tuple(call.args[0] for call in backend.send.await_args_list) == (session_update,)
|
||||
assert session_created in tuple(json.loads(call.args[0]) for call in client.send_text.await_args_list)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("retain_close", (False, True))
|
||||
@pytest.mark.parametrize("reported_input,expected_input", [(None, 2.0), (0.0, 0.0), (0.25, 0.25)])
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue