Spaces:
Runtime error
Runtime error
File size: 874 Bytes
77a0c82 47c93d7 77a0c82 47c93d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
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
|