-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategories.py
More file actions
56 lines (47 loc) · 1.65 KB
/
Copy pathcategories.py
File metadata and controls
56 lines (47 loc) · 1.65 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
Plot's canonical category taxonomy — the single source of truth.
Until this file existed, the same 11-string list lived in five places:
llm_intent.ALLOWED_CATEGORIES
recommendation_bigquery.SEGMENT_TO_CATEGORY (target side)
demo/demo.html (chip array)
UI/tokens.js (chip definitions)
UI/api.js (chip-id translator)
Adding a new category like "Music & Live Shows" required editing all five
in lockstep and missing one was an actual bug. Python files now import
from here. The frontend stays separate (different language) but a small
runtime invariant in `recommendation_bigquery` catches any drift between
its segment mapping and this list.
"""
from __future__ import annotations
from typing import Literal
ALLOWED_CATEGORIES: tuple[str, ...] = (
"Food & Drink",
"Outdoors",
"Entertainment",
"Arts & Workshops",
"Nightlife",
"Sports & Recreation",
"Wellness & Beauty",
"Shopping",
"Pets & Animals",
"Music & Live Shows",
)
# Same set, as a Pydantic-friendly Literal type. Use this in request models
# (e.g. UserPreference.categories) when you want FastAPI to reject unknown
# categories at validation time rather than silently filtering them later.
Category = Literal[
"Food & Drink",
"Outdoors",
"Entertainment",
"Arts & Workshops",
"Nightlife",
"Sports & Recreation",
"Wellness & Beauty",
"Shopping",
"Pets & Animals",
"Music & Live Shows",
]
ALLOWED_SET: frozenset[str] = frozenset(ALLOWED_CATEGORIES)
def is_allowed(category: str | None) -> bool:
"""True if the given string is one of the canonical categories."""
return bool(category) and category in ALLOWED_SET