Skip to content

Commit b7e9948

Browse files
committed
feat: Update settings to remove Gemini API configuration and focus on Vertex AI integration
1 parent 362435a commit b7e9948

1 file changed

Lines changed: 2 additions & 68 deletions

File tree

backend/config/settings.py

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
LegalMind Configuration Settings
3-
Google Cloud / Gemini API Configuration
3+
Google Cloud / Vertex AI Configuration
44
"""
55

66
import os
@@ -14,15 +14,9 @@ class Settings(BaseSettings):
1414
"""Application settings loaded from environment variables."""
1515

1616
# -------------------------------------------------------------------------
17-
# Gemini API Configuration
17+
# Vertex AI Configuration
1818
# -------------------------------------------------------------------------
19-
gemini_api_key: str = ""
2019
gemini_model: str = "gemini-2.0-flash"
21-
# Use Vertex AI by default - reads from USE_VERTEX_AI env var (true/false)
22-
use_vertex_ai: bool = Field(
23-
default=True,
24-
description="Use Vertex AI instead of public Gemini API. Set USE_VERTEX_AI=true/false in environment"
25-
)
2620

2721
# -------------------------------------------------------------------------
2822
# Google Cloud Project Configuration
@@ -74,31 +68,6 @@ class Settings(BaseSettings):
7468
enable_thinking_logs: bool = True
7569
enable_citations: bool = True
7670

77-
@field_validator("use_vertex_ai", mode="before")
78-
@classmethod
79-
def read_use_vertex_ai(cls, v):
80-
"""Read USE_VERTEX_AI from environment variable."""
81-
# If called during init, v is the field default
82-
# Check environment variable first
83-
env_val = os.getenv("USE_VERTEX_AI", "true").lower()
84-
if env_val in ("true", "1", "yes"):
85-
return True
86-
elif env_val in ("false", "0", "no"):
87-
return False
88-
# Default to True (use Vertex AI) for production
89-
return True
90-
91-
@field_validator("gemini_api_key", mode="after")
92-
@classmethod
93-
def validate_api_key(cls, v, info):
94-
"""Validate API key is set if not using Vertex AI."""
95-
# Check if using Vertex AI from environment (default to true for production)
96-
use_vertex_ai = os.getenv("USE_VERTEX_AI", "true").lower() == "true"
97-
if not use_vertex_ai and not v:
98-
# Only warn, don't fail - Vertex AI might use ADC
99-
print("⚠️ GEMINI_API_KEY not set - will attempt Vertex AI or ADC authentication")
100-
return v or ""
101-
10271
@field_validator("google_cloud_project", mode="after")
10372
@classmethod
10473
def validate_project(cls, v):
@@ -110,19 +79,6 @@ def validate_project(cls, v):
11079
)
11180
return v
11281

113-
def model_post_init(self, __context):
114-
"""Ensure USE_VERTEX_AI environment variable is respected after initialization."""
115-
env_val = os.getenv("USE_VERTEX_AI", "true").lower()
116-
if env_val in ("true", "1", "yes"):
117-
self.use_vertex_ai = True
118-
print(f"✅ USE_VERTEX_AI=true from environment - using Vertex AI")
119-
elif env_val in ("false", "0", "no"):
120-
self.use_vertex_ai = False
121-
print(f"⚠️ USE_VERTEX_AI=false from environment - using public Gemini API")
122-
else:
123-
self.use_vertex_ai = True
124-
print(f"✅ USE_VERTEX_AI not set, defaulting to True - using Vertex AI")
125-
12682
class Config:
12783
env_file = ".env.local"
12884
env_file_encoding = "utf-8"
@@ -143,21 +99,6 @@ def get_settings() -> Settings:
14399
return Settings()
144100

145101

146-
def get_gemini_api_key() -> str:
147-
"""Get the Gemini API key from settings.
148-
149-
Returns:
150-
str: The Gemini API key
151-
152-
Raises:
153-
ValueError: If the API key is not configured and not using Vertex AI
154-
"""
155-
settings = get_settings()
156-
if settings.use_vertex_ai:
157-
return ""
158-
return settings.gemini_api_key
159-
160-
161102
def get_google_cloud_project() -> str:
162103
"""Get the Google Cloud project ID.
163104
@@ -198,11 +139,4 @@ def validate_settings() -> bool:
198139
"Please check your .env file."
199140
)
200141

201-
# API key is only required if not using Vertex AI
202-
if not settings.use_vertex_ai and not settings.gemini_api_key:
203-
raise ValueError(
204-
"Missing required environment variable: GEMINI_API_KEY. "
205-
"Please set it in your .env file or set USE_VERTEX_AI=true to use Vertex AI."
206-
)
207-
208142
return True

0 commit comments

Comments
 (0)