Skip to content

Instantly share code, notes, and snippets.

@rpappalax
Created January 30, 2026 15:28
Show Gist options
  • Select an option

  • Save rpappalax/93d2ec47f0067fcc7d9877409f70dc70 to your computer and use it in GitHub Desktop.

Select an option

Save rpappalax/93d2ec47f0067fcc7d9877409f70dc70 to your computer and use it in GitHub Desktop.
app/llm/vertex_init.py
import logging
import vertexai
from app.common.config import Settings
_INITIALIZED = False
def init_vertex(settings: Settings) -> None:
"""Initialize Vertex AI once per process."""
global _INITIALIZED
if _INITIALIZED:
return
project = settings.require_project()
vertexai.init(project=project, location=settings.gcp_location)
logging.getLogger(__name__).info(
"Vertex AI initialized (project=%s, location=%s).",
project,
settings.gcp_location,
)
_INITIALIZED = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment