Spaces:
Sleeping
Sleeping
File size: 1,440 Bytes
5774aff | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | """
Uplan β Lobster Trap Proxy Client (Phase 2 β Scaffolded)
When wired, this rewrites the Gemini API base URL to route through
Lobster Trap's DPI layer for prompt injection detection, PII exfil
scanning, and YAML policy enforcement.
Not active in Phase 1 β all Gemini calls go direct to Vertex AI / AI Studio.
"""
from __future__ import annotations
import os
from typing import Optional
# Lobster Trap proxy URL β set when the proxy is deployed
LOBSTER_TRAP_URL = os.environ.get("LOBSTER_TRAP_URL", None)
def get_proxy_base_url() -> Optional[str]:
"""
Returns the Lobster Trap proxy URL if configured, else None.
When None, the google-genai client uses its default endpoint.
"""
return LOBSTER_TRAP_URL
def is_proxy_active() -> bool:
"""Check if Lobster Trap proxy is configured and reachable."""
return LOBSTER_TRAP_URL is not None
# ββ Future: wrap google-genai client to route through proxy βββββββββ
#
# The google-genai SDK doesn't natively support custom base URLs.
# When Lobster Trap is wired in, the approach is:
#
# 1. Run Lobster Trap as an OpenAI-compatible proxy
# 2. Use the openai SDK (not google-genai) pointed at Lobster Trap
# 3. Lobster Trap forwards to Gemini after DPI inspection
#
# This requires switching from google-genai to openai SDK for all
# Gemini calls β a straightforward swap since Gemini supports the
# OpenAI-compatible API format.
|