fix(startup): move all blocking calls to lifespan event
This commit is contained in:
parent
4610521e73
commit
4dfcffd0b3
|
|
@ -13,7 +13,7 @@ import google.auth
|
|||
import google.auth.transport.requests
|
||||
from typing import Literal
|
||||
|
||||
import vertexai
|
||||
|
||||
from google.adk.agents import Agent
|
||||
from google.adk.tools import FunctionTool
|
||||
from google.adk.runners import Runner
|
||||
|
|
@ -25,9 +25,6 @@ logger = logging.getLogger(__name__)
|
|||
PROJECT_ID = os.environ.get("GOOGLE_CLOUD_PROJECT", "propane-will-491900-m5")
|
||||
LOCATION = os.environ.get("GOOGLE_CLOUD_LOCATION", "us-central1")
|
||||
|
||||
# Initialiser Vertex AI eksplisitt — ADK krev dette for Cloud Run
|
||||
vertexai.init(project=PROJECT_ID, location=LOCATION)
|
||||
|
||||
ORCHESTRATOR_MODEL = os.environ.get("ORCHESTRATOR_MODEL", "gemini-2.5-flash")
|
||||
SUBAGENT_MODEL = os.environ.get("SUBAGENT_MODEL", "gemini-2.5-flash")
|
||||
REASONING_MODEL = os.environ.get("REASONING_MODEL", "gemini-2.5-flash")
|
||||
|
|
@ -63,8 +60,6 @@ except ImportError as _e:
|
|||
return flash_model if mode != "heavy" else pro_model
|
||||
class TokenBudgetExceeded(Exception): pass
|
||||
|
||||
create_bq_table_if_not_exists()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# OPAX MCP Client (inlina)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ from pathlib import Path
|
|||
from fastapi import FastAPI, HTTPException, Request
|
||||
from fastapi.responses import JSONResponse, FileResponse
|
||||
from pydantic import BaseModel
|
||||
import vertexai
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -42,6 +43,7 @@ _budget_store: dict = {}
|
|||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
logger.info(f"OSVauco agent '{APP_NAME}' starting up")
|
||||
vertexai.init(project=PROJECT_ID, location=os.environ.get("GOOGLE_CLOUD_LOCATION", "us-central1"))
|
||||
create_bq_table_if_not_exists()
|
||||
logger.info(f"Static dir: {STATIC_DIR} (exists={STATIC_DIR.exists()})")
|
||||
yield
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user