Skip to content

Config

Config

Bases: BaseModel

Source code in Docs2KG/utils/config.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
class Config(BaseModel):
    openai: AgentOpenAIConfig
    ollama: AgentOLLAMAConfig
    huggingface: AgentHuggingFaceConfig
    llamacpp: AgentLlamaCppConfig
    data: DataConfig
    semantic_kg: SemanticKGConfig

    @classmethod
    def from_yaml(cls, yaml_path: Path) -> "Config":
        """Load configuration from a YAML file."""
        if not yaml_path.exists():
            raise FileNotFoundError(f"Config file not found: {yaml_path}")

        with open(yaml_path) as f:
            config_dict = safe_load(f)

        return cls(**config_dict)

from_yaml(yaml_path) classmethod

Load configuration from a YAML file.

Source code in Docs2KG/utils/config.py
82
83
84
85
86
87
88
89
90
91
@classmethod
def from_yaml(cls, yaml_path: Path) -> "Config":
    """Load configuration from a YAML file."""
    if not yaml_path.exists():
        raise FileNotFoundError(f"Config file not found: {yaml_path}")

    with open(yaml_path) as f:
        config_dict = safe_load(f)

    return cls(**config_dict)

get_config() cached

Get the configuration singleton. The lru_cache decorator ensures this is only created once and reused.

Source code in Docs2KG/utils/config.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
@lru_cache()
def get_config() -> Config:
    """
    Get the configuration singleton.
    The lru_cache decorator ensures this is only created once and reused.
    """
    try:
        config = Config.from_yaml(CONFIG_FILE)
        logger.info("Configuration loaded successfully")
        return config
    except Exception as e:
        logger.error(f"Failed to load configuration: {e}")
        raise