fix: handle Vertex AI full resource path in session.created; route guardrail block sends through _send_to_backend

This commit is contained in:
Ishaan Jaffer 2026-02-25 22:04:33 -08:00
parent 5c55c91293
commit cc3c8e433b
2 changed files with 14 additions and 10 deletions

View file

@ -295,9 +295,9 @@ class RealTimeStreaming:
safe_msg = str(e) or "I'm sorry, that request was blocked by the content filter."
# Cancel any in-flight response before speaking the warning.
# This handles the race where create_response fired before we could intercept.
await self.backend_ws.send(json.dumps({"type": "response.cancel"}))
# Ask OpenAI to speak the warning — TTS audio plays naturally in the client
await self.backend_ws.send(
await self._send_to_backend(json.dumps({"type": "response.cancel"}))
# Ask the model to speak the warning — TTS audio plays naturally in the client
await self._send_to_backend(
json.dumps(
{
"type": "response.create",

View file

@ -312,13 +312,17 @@ class GeminiRealtimeConfig(BaseRealtimeConfig):
if _system_instruction is not None and isinstance(_system_instruction, str):
session["instructions"] = _system_instruction
if _model is not None and isinstance(_model, str):
# Strip "models/" prefix if present to match OpenAI model name format.
# Use removeprefix (not strip) — strip removes individual chars, not a substring.
session["model"] = (
_model[len("models/"):]
if _model.startswith("models/")
else _model
)
# Normalise to bare model name for OpenAI compatibility.
# Vertex AI uses a full resource path:
# projects/{project}/locations/{location}/publishers/google/models/{model}
# Google AI Studio uses:
# models/{model}
if "/models/" in _model:
session["model"] = _model.split("/models/")[-1]
elif _model.startswith("models/"):
session["model"] = _model[len("models/"):]
else:
session["model"] = _model
return OpenAIRealtimeStreamSessionEvents(
type="session.created",