Spaces:
Sleeping
Sleeping
| """Configuration loader for Francis Botcon project.""" | |
| import yaml | |
| from pathlib import Path | |
| from typing import Dict, Any | |
| class ConfigLoader: | |
| """Load and manage project configuration.""" | |
| def __init__(self, config_path: str = None): | |
| """Initialize configuration loader. | |
| Args: | |
| config_path: Path to config.yaml file | |
| """ | |
| if config_path is None: | |
| config_path = str(Path(__file__).parent.parent / "config" / "config.yaml") | |
| self.config_path = Path(config_path) | |
| self.config = self._load_config() | |
| def _load_config(self) -> Dict[str, Any]: | |
| """Load YAML configuration file.""" | |
| if not self.config_path.exists(): | |
| raise FileNotFoundError(f"Configuration file not found: {self.config_path}") | |
| with open(self.config_path, 'r') as f: | |
| return yaml.safe_load(f) | |
| def get(self, key: str, default: Any = None) -> Any: | |
| """Get configuration value by key (supports dot notation). | |
| Args: | |
| key: Configuration key (e.g., "model.base_model") | |
| default: Default value if key not found | |
| Returns: | |
| Configuration value or default | |
| """ | |
| keys = key.split('.') | |
| value = self.config | |
| for k in keys: | |
| if isinstance(value, dict): | |
| value = value.get(k) | |
| if value is None: | |
| return default | |
| else: | |
| return default | |
| return value | |
| def get_model_config(self) -> Dict[str, Any]: | |
| """Get model configuration.""" | |
| return self.config.get('model', {}) | |
| def get_training_config(self) -> Dict[str, Any]: | |
| """Get training configuration.""" | |
| return self.config.get('training', {}) | |
| def get_vector_db_config(self) -> Dict[str, Any]: | |
| """Get vector database configuration.""" | |
| return self.config.get('vector_db', {}) | |
| def get_generation_config(self) -> Dict[str, Any]: | |
| """Get generation configuration.""" | |
| return self.config.get('generation', {}) | |
| # Global config instance | |
| config = ConfigLoader() | |