[31388f42] Add SerpAPI debugging to UI and relax dotenv loading

This commit is contained in:
2026-03-02 09:40:04 +00:00
parent d0c7df3c4b
commit 7edafd5822
2 changed files with 92 additions and 17 deletions

View File

@@ -3,23 +3,15 @@ import requests
import re
from dotenv import load_dotenv
# Load env from root
# Try loading .env only if file exists (Local Dev), otherwise rely on Docker Env
env_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '.env'))
load_dotenv(dotenv_path=env_path, override=True)
if os.path.exists(env_path):
load_dotenv(dotenv_path=env_path, override=True)
SERP_API_KEY = os.getenv("SERP_API")
if not SERP_API_KEY:
print(f"DEBUG: Failed to load SERP_API from {env_path}")
# Fallback: try reading directly if file exists
try:
with open(env_path, 'r') as f:
for line in f:
if line.startswith('SERP_API='):
SERP_API_KEY = line.split('=')[1].strip().strip('"')
print("DEBUG: Loaded key via manual parsing.")
except:
pass
print(f"DEBUG: SERP_API not found in environment.")
import json
@@ -75,8 +67,10 @@ def extract_role_with_llm(name, company, search_results):
# Cleanup: remove punctuation at the end
role = role.rstrip('.')
return None if "Unbekannt" in role else role
except:
pass
else:
print(f"DEBUG: Gemini API Error {response.status_code}: {response.text}")
except Exception as e:
print(f"DEBUG: Gemini API Exception: {e}")
return None
def lookup_person_role(name, company):