"""Configuration management for Helium server.""" import os from pathlib import Path from dotenv import load_dotenv import logging # Load environment variables from .env file env_path = Path(__file__).parent / '.env' load_dotenv(dotenv_path=env_path) # Database configuration DB_URL = os.getenv('HELIUM_DB_URL', 'hf://datasets/Fred808/helium/storage.json') # HuggingFace token configuration def get_hf_token() -> str: """Get the HuggingFace token from environment variables.""" token = os.getenv('HF_TOKEN') if not token: logging.error("HF_TOKEN environment variable not set") raise ValueError( "HF_TOKEN environment variable not set. " "Please set it in .env file or environment. " "Create a .env file in the project root with: HF_TOKEN=your_token_here" ) return token def get_db_url() -> str: """Get the database URL from environment variables.""" if not DB_URL or not DB_URL.startswith('hf://datasets/'): logging.error(f"Invalid database URL: {DB_URL}") raise ValueError( f"Invalid database URL: {DB_URL}. " "URL must start with 'hf://datasets/' and be properly formatted" ) return DB_URL # Singleton instance for HF token to avoid reading env multiple times _hf_token = None def get_hf_token_cached() -> str: """Get the HuggingFace token with caching.""" global _hf_token if _hf_token is None: _hf_token = get_hf_token() return _hf_token