File size: 1,332 Bytes
e954acb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from functools import lru_cache
from pathlib import Path
from typing import Any
import yaml

from configs.config_models import StepModelsConfigs


@lru_cache
def load_config(config_path: Path, _format: str = "dict") -> dict[str, Any] | str:
    """
    Load configuration from a YAML file into a dictionary.

    Parameters
    ----------
    config_path : Path
        Path to the YAML configuration file.
    _format : str, optional
        The format in which to return the configuration, by default "dict".

    Returns
    -------
    dict[str, Any] | str
        A dictionary containing the configuration parameters if _format="dict",
        otherwise the raw YAML content as a string.
    """
    with open(config_path, "r") as file:
        content = file.read()

    if _format == "dict":
        return yaml.safe_load(content)
    else:
        return content


def load_module_config(config_path, config_model=None):
    """
    Load a YAML configuration file and validate against a Pydantic model.
    """
    config_data = load_config(config_path)

    if config_model:
        return config_model(**config_data)

    return config_data


PROMPT_LIBRARY = load_config(Path(__file__).parent / "prompt_library.yaml")
APP_STEPS_CONFIGS = load_module_config(
    Path(__file__).parent / "config.yaml", StepModelsConfigs
)