File size: 2,205 Bytes
4e5fc16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""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()