borderless / ui /intake /loader.py
spagestic's picture
data expanded
43b2c38
Raw
History Blame Contribute Delete
930 Bytes
# ui/intake/loader.py
from __future__ import annotations
from functools import lru_cache
from pathlib import Path
from typing import Any
import yaml
DATA_DIR = Path(__file__).resolve().parents[2] / "data" / "intake"
CHOICES_DIR = DATA_DIR / "choices"
@lru_cache(maxsize=1)
def load_intake_choices() -> dict[str, list[str]]:
choices: dict[str, list[str]] = {}
for path in sorted(CHOICES_DIR.glob("*.yaml")):
with path.open(encoding="utf-8") as handle:
data = yaml.safe_load(handle)
if not isinstance(data, list):
raise ValueError(f"{path.name} must contain a YAML list")
choices[path.stem] = list(data)
return choices
@lru_cache(maxsize=1)
def load_demo_personas() -> list[dict[str, Any]]:
with (DATA_DIR / "personas.yaml").open(encoding="utf-8") as handle:
data = yaml.safe_load(handle)
return list(data["personas"])