| 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", ""), |
| "PERPLEXITY": os.getenv("PERPLEXITY_API_KEY", ""), |
| }, |
| "API_ENDPOINTS": { |
| "BING": "https://api.bing.microsoft.com/v7.0/search", |
| "GOOGLE": "https://www.googleapis.com/customsearch/v1", |
| "PERPLEXITY": "https://api.perplexity.ai", |
| } |
| } |
| |
| |
| 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"] |
| |
| def get_perplexity_api_key(self): |
| return self.config["API_KEYS"]["PERPLEXITY"] |