Spaces:
Sleeping
Sleeping
File size: 1,445 Bytes
beb52ea |
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import os
import json
from pathlib import Path
class Config:
_instance = None
def __new__(cls):
if cls._instance is None:
cls._instance = super().__new__(cls)
cls._instance._load_config()
return cls._instance
def _load_config(self):
self.config = {
"API_KEYS": {
"OPENAI": os.getenv("OPENAI_API_KEY", ""),
"ANTHROPIC": os.getenv("ANTHROPIC_API_KEY", ""),
"BING": os.getenv("BING_API_KEY", ""),
"GOOGLE_SEARCH": os.getenv("GOOGLE_API_KEY", ""),
"GOOGLE_SEARCH_ENGINE_ID": os.getenv("GOOGLE_SEARCH_ENGINE_ID", ""),
},
"API_ENDPOINTS": {
"BING": "https://api.bing.microsoft.com/v7.0/search",
"GOOGLE": "https://www.googleapis.com/customsearch/v1",
}
}
# Create necessary directories
base_dir = Path("/code")
for dir_name in ["db", "logs", "projects", "screenshots", "pdfs"]:
(base_dir / dir_name).mkdir(exist_ok=True)
def get_config(self):
return self.config
def get_bing_api_key(self):
return self.config["API_KEYS"]["BING"]
def get_google_search_api_key(self):
return self.config["API_KEYS"]["GOOGLE_SEARCH"]
def get_google_search_engine_id(self):
return self.config["API_KEYS"]["GOOGLE_SEARCH_ENGINE_ID"] |