adrienbrdne commited on
Commit
9c1f7cf
·
verified ·
1 Parent(s): e38935b

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +3 -7
api.py CHANGED
@@ -21,13 +21,11 @@ NEO4J_PASSWORD = os.getenv("NEO4J_PASSWORD")
21
  if not NEO4J_URI or not NEO4J_USER or not NEO4J_PASSWORD:
22
  logger.critical("CRITICAL ERROR: NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD environment variables must be set.")
23
 
24
- client = None
25
  # --- Application Lifecycle (Startup/Shutdown) ---
26
  @asynccontextmanager
27
  async def lifespan(app: FastAPI):
28
  """Handles startup and shutdown events."""
29
  # Initialize Gemini Client
30
- global client
31
  logger.info("Initializing Gemini client...")
32
  if genai:
33
  try:
@@ -35,8 +33,9 @@ async def lifespan(app: FastAPI):
35
  api_key = os.getenv("GEMINI_API_KEY") or getattr(settings, "GEMINI_API_KEY", None)
36
  if not api_key:
37
  raise ValueError("GEMINI_API_KEY not found in environment or settings.")
38
- client = genai.Client(api_key=api_key)
39
- logger.info("Gemini client configured successfully.")
 
40
  except Exception as e:
41
  logger.error(f"Failed to configure Gemini client: {e}", exc_info=True)
42
  else:
@@ -46,9 +45,6 @@ async def lifespan(app: FastAPI):
46
 
47
  # --- Shutdown ---
48
  logger.info("API shutting down...")
49
- # Close Neo4j connection (handled by atexit in graph_client.py)
50
- # neo4j_client.close() # Usually not needed due to atexit registration
51
- logger.info("Neo4j client closed (likely via atexit).")
52
  logger.info("API shutdown complete.")
53
 
54
  # Initialize FastAPI application
 
21
  if not NEO4J_URI or not NEO4J_USER or not NEO4J_PASSWORD:
22
  logger.critical("CRITICAL ERROR: NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD environment variables must be set.")
23
 
 
24
  # --- Application Lifecycle (Startup/Shutdown) ---
25
  @asynccontextmanager
26
  async def lifespan(app: FastAPI):
27
  """Handles startup and shutdown events."""
28
  # Initialize Gemini Client
 
29
  logger.info("Initializing Gemini client...")
30
  if genai:
31
  try:
 
33
  api_key = os.getenv("GEMINI_API_KEY") or getattr(settings, "GEMINI_API_KEY", None)
34
  if not api_key:
35
  raise ValueError("GEMINI_API_KEY not found in environment or settings.")
36
+ else:
37
+ genai.configure(api_key=api_key)
38
+ logger.info("Gemini client configured successfully.")
39
  except Exception as e:
40
  logger.error(f"Failed to configure Gemini client: {e}", exc_info=True)
41
  else:
 
45
 
46
  # --- Shutdown ---
47
  logger.info("API shutting down...")
 
 
 
48
  logger.info("API shutdown complete.")
49
 
50
  # Initialize FastAPI application