Commit ·
4b7c591
1
Parent(s): 80f29b9
Add Gemini API key file and update config to read from file
Browse files- 2_backend_llm/app/config.py +19 -2
- gemini_api_key.txt +2 -0
2_backend_llm/app/config.py
CHANGED
|
@@ -7,6 +7,7 @@ or a .env file (which is git-ignored for security).
|
|
| 7 |
"""
|
| 8 |
|
| 9 |
import os
|
|
|
|
| 10 |
from dataclasses import dataclass
|
| 11 |
from dotenv import load_dotenv # type: ignore
|
| 12 |
|
|
@@ -16,6 +17,21 @@ from dotenv import load_dotenv # type: ignore
|
|
| 16 |
load_dotenv(override=False)
|
| 17 |
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
@dataclass
|
| 20 |
class Settings:
|
| 21 |
"""
|
|
@@ -25,8 +41,9 @@ class Settings:
|
|
| 25 |
This provides flexibility for different deployment environments.
|
| 26 |
"""
|
| 27 |
# LLM API keys - at least one must be set for the system to work
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
# CSV data file path - relative to project root
|
| 32 |
# Default to feedback_transformed_2.csv which has pre-calculated date/time fields
|
|
|
|
| 7 |
"""
|
| 8 |
|
| 9 |
import os
|
| 10 |
+
from pathlib import Path
|
| 11 |
from dataclasses import dataclass
|
| 12 |
from dotenv import load_dotenv # type: ignore
|
| 13 |
|
|
|
|
| 17 |
load_dotenv(override=False)
|
| 18 |
|
| 19 |
|
| 20 |
+
def _load_api_key_from_file(key_name: str) -> str | None:
|
| 21 |
+
"""Load API key from file if environment variable is not set."""
|
| 22 |
+
# Try to find the key file in project root
|
| 23 |
+
project_root = Path(__file__).resolve().parent.parent.parent
|
| 24 |
+
key_file = project_root / f"{key_name.lower()}.txt"
|
| 25 |
+
|
| 26 |
+
if key_file.exists():
|
| 27 |
+
try:
|
| 28 |
+
return key_file.read_text().strip()
|
| 29 |
+
except Exception:
|
| 30 |
+
pass
|
| 31 |
+
|
| 32 |
+
return None
|
| 33 |
+
|
| 34 |
+
|
| 35 |
@dataclass
|
| 36 |
class Settings:
|
| 37 |
"""
|
|
|
|
| 41 |
This provides flexibility for different deployment environments.
|
| 42 |
"""
|
| 43 |
# LLM API keys - at least one must be set for the system to work
|
| 44 |
+
# Try environment variable first, then fallback to file
|
| 45 |
+
openai_api_key: str | None = os.getenv("OPENAI_API_KEY") or _load_api_key_from_file("OPENAI_API_KEY")
|
| 46 |
+
gemini_api_key: str | None = os.getenv("GEMINI_API_KEY") or _load_api_key_from_file("GEMINI_API_KEY")
|
| 47 |
|
| 48 |
# CSV data file path - relative to project root
|
| 49 |
# Default to feedback_transformed_2.csv which has pre-calculated date/time fields
|
gemini_api_key.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
AIzaSyCO3OfHPsocMDDI2KfotavH5qFZMmrzy8w
|
| 2 |
+
|