Ray-Man05/fao-data-llm
0
1import os2import tomllib3from pathlib import Path4from types import SimpleNamespace5 6 7def _namespace(d: dict) -> SimpleNamespace:8 ns = SimpleNamespace()9 for k, v in d.items():10 setattr(ns, k, _namespace(v) if isinstance(v, dict) else v)11 return ns12 13 14def _load() -> SimpleNamespace:15 local = Path(__file__).parent / "config.toml"16 parent = Path(__file__).parent.parent / "config.toml"17 18 if local.exists():19 path = local20 elif parent.exists():21 path = parent22 else:23 raise FileNotFoundError("config.toml not found in backend/ or project root.")24 25 with open(path, "rb") as f:26 ns = _namespace(tomllib.load(f))27 28 api_key = os.getenv("OPENROUTER_API_KEY")29 if not api_key:30 raise RuntimeError("OPENROUTER_API_KEY environment variable is not set.")31 ns.llm.api_key = api_key32 33 return ns34 35 36settings = _load()37 