31 lines
709 B
Python
31 lines
709 B
Python
"""
|
|
config_loader.py — Load JSON config files from Config/
|
|
"""
|
|
import json
|
|
import os
|
|
from Core.env_loader import PROJECT_ROOT
|
|
|
|
_cache = {}
|
|
|
|
|
|
def load_config(name: str) -> dict:
|
|
"""
|
|
Load Config/config_{name}.json and cache it.
|
|
|
|
Usage:
|
|
cfg = load_config("Brain")
|
|
model = cfg["ollama_model"]
|
|
"""
|
|
if name in _cache:
|
|
return _cache[name]
|
|
path = os.path.join(PROJECT_ROOT, "Config", f"config_{name}.json")
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
data = json.load(f)
|
|
_cache[name] = data
|
|
return data
|
|
|
|
|
|
def config_path(relative: str) -> str:
|
|
"""Resolve a config-relative path to absolute."""
|
|
return os.path.join(PROJECT_ROOT, relative)
|