venthrive-api / news /business_types.py
GitHub Actions
Sync from GitHub · 2026-10-20 00:01 UTC
1f5f31a
Raw History Blame Contribute Delete
897 Bytes
"""
Subsector ids the news classifier is allowed to use for `business_types`.
Sourced from data/sectors.ts via scripts/export-subsectors.mjs — re-run that
script and this file picks up the change automatically, no code edit needed.
See ADR-0015 for why subsector-level (not sector or niche) was chosen.
"""
import json
from pathlib import Path
_PATH = Path(__file__).resolve().parent / "subsectors.json"
SUBSECTORS: list[dict] = json.loads(_PATH.read_text(encoding="utf-8"))
VALID_IDS: set[str] = {s["id"] for s in SUBSECTORS}
def labels_for_prompt() -> str:
"""'id — label' lines, for embedding the allowed list in the classifier prompt."""
return "\n".join(f"- {s['id']} — {s['label']}" for s in SUBSECTORS)
def valid_subset(ids: list[str]) -> list[str]:
"""Drops any id the model hallucinated that isn't in our taxonomy."""
return [i for i in ids if i in VALID_IDS]