File size: 737 Bytes
4a14841
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Tunable settings from config.toml at the repository root.

    from rag_chatbot.shared.settings import settings
    settings.rag.context_models
"""

import os
import tomllib
from types import SimpleNamespace

from rag_chatbot.shared.paths import PROJECT_ROOT

CONFIG_PATH = PROJECT_ROOT / "config.toml"


def _namespace(value):
    if isinstance(value, dict):
        return SimpleNamespace(**{key: _namespace(item) for key, item in value.items()})
    return value


with CONFIG_PATH.open("rb") as file:
    settings = _namespace(tomllib.load(file))


def secret(name: str) -> str:
    """A secret from the environment, else from config.toml [secrets]."""
    return os.environ.get(name) or getattr(settings.secrets, name, "") or ""