galbendavids commited on
Commit
979b4a2
·
1 Parent(s): 4b7c591

Fix API key file loading logic

Browse files
Files changed (1) hide show
  1. 2_backend_llm/app/config.py +22 -6
2_backend_llm/app/config.py CHANGED
@@ -21,13 +21,29 @@ 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
 
 
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
 
25
+ # Try different file name formats
26
+ possible_names = [
27
+ f"{key_name.lower()}.txt", # gemini_api_key.txt
28
+ f"{key_name.replace('_', '').lower()}.txt", # gemini apikey.txt
29
+ ]
30
+
31
+ for filename in possible_names:
32
+ key_file = project_root / filename
33
+ if key_file.exists():
34
+ try:
35
+ return key_file.read_text().strip()
36
+ except Exception:
37
+ pass
38
+
39
+ # Also try gemini_api_key.txt specifically (the file we created)
40
+ if key_name == "GEMINI_API_KEY":
41
+ gemini_file = project_root / "gemini_api_key.txt"
42
+ if gemini_file.exists():
43
+ try:
44
+ return gemini_file.read_text().strip()
45
+ except Exception:
46
+ pass
47
 
48
  return None
49