import os from dotenv import load_dotenv from pathlib import Path def load_secrets(): if not os.getenv("OPENAI_API_KEY"): env_path = Path('.') / '.env' load_dotenv(dotenv_path=env_path) open_ai_key = os.getenv("OPENAI_API_KEY") google_maps_key = os.getenv("GOOGLE_MAPS_API_KEY") google_palm_key = os.getenv("GOOGLE_PALM_API_KEY") # Collect all keys in a dictionary secrets = { "OPENAI_API_KEY": open_ai_key, "GOOGLE_MAPS_API_KEY": google_maps_key, "GOOGLE_PALM_API_KEY": google_palm_key, } # Check if any of the keys are missing missing_keys = [key for key, value in secrets.items() if not value] if missing_keys: missing_keys_str = ", ".join(missing_keys) raise Exception(f"Missing API keys: {missing_keys_str}. Ensure .env file is set up correctly.") return secrets