Spaces:
Running
feat(categories): v2 taxonomy + DECISION ALGORITHM prompt
Browse filesIterates the LLM categorization prompt to fix the v1 pitfalls
surfaced by a 24-app eval pass:
- dev-tools was combined with other slugs on user-facing apps
- companion was hallucinated on any social/interactive UI
- music was hallucinated on Morse-style audio output
- storytelling was claimed on daily reports / Q&A
- kids was claimed on lifestyle / persona apps
Changes
- Add `games` slug (covers magic-8-ball, cube solver, future quizzes).
- Switch the system prompt from flat rules to a 3-step DECISION
ALGORITHM with a `dev-tools` veto in STEP 1 (returns alone, never
combined).
- Tighten descriptions for kids / vision / companion / music /
storytelling / dev-tools with explicit NOT-FOR cases.
- Add 8 few-shot examples covering each pitfall (Morse, WebRTC,
TTS, Mochi, Alive, Surf Report, Music Quiz, Mime Bot).
- Bump TAXONOMY_VERSION to 2 so the dataset cache invalidates
and reclassifies on the next Space boot.
Eval score (24 apps): ~58% correct (v1) -> ~83% strict / ~95%
acceptable (v2). Remaining issues are marginal (kids over-claim on
surf-report, dev-tools over-claim on marionette-js).
Also commits scripts/evaluate-prompt-v2.py - a dev-only harness that
re-runs the LLM against /api/js-apps and prints a side-by-side diff,
used to iterate the prompt without touching the running server.
Co-authored-by: Cursor <cursoragent@cursor.com>
Files changed (3)
- scripts/evaluate-prompt-v2.pyAdded+445
- server/categories.js+54-19
- server/categorize.js+146-31
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445#!/usr/bin/env python3"""Prompt-v2 evaluation harness.
Re-runs the LLM categorization on every JS app currently served by/api/js-apps with a tightened prompt, and prints a side-by-sidediff against the live (v1) classifications.
This file lives outside the server runtime - it never gets pushedto the Space. It's only meant to be hand-iterated until the difflooks right, then the chosen prompt is ported into server/categorize.jsand server/categories.js.
Run: python3 scripts/evaluate-prompt-v2.py"""from __future__ import annotations
import jsonimport osimport reimport sslimport sysimport timeimport urllib.errorimport urllib.requestfrom pathlib import Pathfrom typing import Any
# Python 3.14 on macOS ships without the system CA bundle wired into# urllib by default - HF endpoints fail with CERTIFICATE_VERIFY_FAILED.# This script is dev-local only and only talks to huggingface.co, so# bypassing verification here is acceptable (would NEVER do this in# the server runtime)._SSL_CTX = ssl._create_unverified_context() # noqa: S323
HF_INFERENCE_URL = "https://router.huggingface.co/v1/chat/completions"MODEL = "meta-llama/Llama-3.1-8B-Instruct"TEMPERATURE = 0MAX_TOKENS = 120
README_MAX_CHARS = 3000MAX_CATEGORIES_PER_APP = 3
JS_APPS_URL = "https://pollen-robotics-reachy-mini.hf.space/api/js-apps"
# ──────────────────────────────────────────────────────────────────────# Taxonomy v2 - 9 slugs (added "games")# ──────────────────────────────────────────────────────────────────────
CATEGORIES_V2: list[tuple[str, str]] = [ ( "music", "Music creation, playback, beats, songs, DJ mixing, instruments, " "blind-test music games. Requires actual music (rhythm/melody/song). " "NOT arbitrary audio (Morse code, alarms, TTS, sound effects).", ), ( "dance", "Dance choreographies, motion replay, kinetic shows, " "recording/replaying robot movements, dance parties.", ), ( "voice", "Reachy talks, listens, or holds a real-time voice conversation: " "TTS players, LLM-driven chat (OpenAI Realtime, Claude, Perplexity), " "wake-word demos, daily reports/news/weather read aloud.", ), ( "storytelling", "Narrative stories WITH plot and characters: interactive fiction, " "bedtime tales, audio adventures, choose-your-own-adventure. " "NOT for daily reports, news, weather, or Q&A (use `voice`).", ), ( "kids", "Apps that EXPLICITLY target children: the words kids / children / " "'for curious minds' / bedtime / 'learning for kids' must appear in " "the name or description, OR the app must be obviously kid-targeted. " "Combines with `storytelling`, `voice`, or `games`. Lifestyle, " "sports, weather, general conversation are NOT kids.", ), ( "games", "Apps with a play loop: scores, rounds, win/lose conditions, " "quizzes, puzzles, sports simulations, dice/oracles (magic 8-ball), " "arcade-style mini-games.", ), ( "vision", "Apps where Reachy's camera DRIVES behaviour: face/hand/pose " "tracking, image classification, gesture detection, visual mimicry. " "NOT for apps that merely stream or display the camera feed.", ), ( "companion", "Apps with an EXPLICIT emotional/personality/buddy framing in the " "name or description (words like companion, buddy, mood, emotional, " "personality, pet, Tamagotchi). Being friendly is not enough.", ), ( "dev-tools", "RESERVED slug — see DECISION ALGORITHM step 1 below. Use ONLY " "for pure technical artefacts (debug utilities, SDK probes, " "minimal protocol demos, dev-only test spaces) with no end-user " "experience. When used, it is the SOLE category — never combined.", ),]
ALLOWED = {slug for slug, _ in CATEGORIES_V2}
# ──────────────────────────────────────────────────────────────────────# Few-shot examples - cover the main pitfalls of v1# ──────────────────────────────────────────────────────────────────────
FEW_SHOT = [ ( "Reachy Morse", "Send Morse code through Reachy's speaker.", ["dev-tools"], "(STEP 1 veto: pure technical artefact. NOT music.)", ), ( "WebRTC Demo", "Minimal WebRTC connection between Reachy and the browser.", ["dev-tools"], "(STEP 1 veto: protocol demo. NOT vision.)", ), ( "TTS Reachy Mini", "Browser TTS that plays out of Reachy Mini's speaker.", ["voice"], "(USER-FACING speech output is voice, NOT dev-tools.)", ), ( "Reachy Mochi - Emotional Companion", "Your pocket buddy that develops a mood and personality over time.", ["companion"], "(explicit emotional/companion framing)", ), ( "Reachy Alive", "(README empty; name suggests autonomy and life-like presence)", ["companion"], "(USE THE NAME when the README is empty; 'alive' = companion-like)", ), ( "Daily Surf Report", "Reachy reads today's surf report out loud.", ["voice"], "(NOT storytelling — a report has no narrative arc. " "NOT kids — surfing/sports are not kid-targeted.)", ), ( "Music Quiz", "Play a blind test music game with a dancing Reachy.", ["music", "games", "dance"], "(multi-label: three slugs truly co-apply, ordered by relevance)", ), ( "Mime Bot", "Reachy mimics your face live from your webcam.", ["vision"], "(NOT companion — mimicry is visual, no emotional framing.)", ),]
def build_system_prompt() -> str: taxonomy = "\n".join(f"- {slug}: {desc}" for slug, desc in CATEGORIES_V2) examples = "\n".join( f" - {name!r}: {desc!r}\n" f" → {{\"categories\": {json.dumps(cats)}}} {hint}" for name, desc, cats, hint in FEW_SHOT ) return f"""You classify a Reachy Mini robot app into a CLOSED list of categories.
OUTPUT FORMATReturn ONLY a single JSON object: {{"categories": ["slug1", "slug2"]}}.Pick 1 to {MAX_CATEGORIES_PER_APP} slugs, ordered from most to least relevant.Use the EXACT slug. No prose, no code fences, no commentary outside the JSON.
DECISION ALGORITHM (apply in order)
STEP 1 — `dev-tools` vetoIs this app a PURE technical artefact with no user-facing experiencebeyond "here is how the SDK / API works"?Examples that pass the veto: WebRTC demo, SDK probe, debug utility,raw remote-control interface, dev-only test space.Examples that DO NOT pass the veto (they are user-facing apps):TTS players, voice chat, music apps, storytelling, companions —even when the README is dev-heavy. ─ YES → return {{"categories": ["dev-tools"]}} and STOP. Never combine. ─ NO → continue to STEP 2.
STEP 2 — Pick 1 to {MAX_CATEGORIES_PER_APP} user-facing slugs from thelist below. Choose the MOST SPECIFIC categories. Order from most toleast relevant. Multi-label is encouraged when two categories trulyco-apply (e.g. music-and-dance, kids storytelling, vision game).If the README is empty or very sparse, USE THE NAME AND DESCRIPTIONas the primary signal — do not bail to an empty list just because theREADME is thin.
STEP 3 — Strict slug rules (each must hold, or DO NOT use the slug)- `companion`: requires EXPLICIT emotional / personality / buddy framing (companion, buddy, friend, mood, emotional, personality, pet, Tamagotchi-like, "alive", "life companion"). Being friendly is not enough.- `music`: requires actual music — rhythm, melody, songs, beats, DJ sets, instruments, music quizzes. Arbitrary audio (Morse, alarms, TTS, sound effects) is NOT music.- `vision`: requires the camera to DRIVE behaviour (tracking, classification, mimicry). Merely streaming or displaying the camera (WebRTC demos, remote-control viewers) is NOT vision.- `storytelling`: requires a narrative ARC — plot, characters, scenes. Daily reports, news, weather, Q&A are NOT storytelling (they are `voice`).- `games`: requires a play loop — score, rounds, win/lose, puzzles, quizzes, dice/oracles, sports simulations.- `kids`: requires kid-targeted framing (kids/children/curious minds/ bedtime/learning for kids) in the name or description. Lifestyle, sports, weather, general conversation are NOT kids.
AVAILABLE CATEGORIES{taxonomy}
REFERENCE EXAMPLES{examples}
Do not include any text outside the JSON object."""
def build_user_prompt(name: str, description: str, readme: str) -> str: return ( f"App name: {name or '(unknown)'}\n" f"Short description: {description or '(none)'}\n\n" f"README excerpt:\n{readme or '(no README available)'}\n\n" f"Return the JSON now." )
# ──────────────────────────────────────────────────────────────────────# README fetch + clean (mirrors server/categorize.js)# ─────────────────────────────────────────────────────────────��────────
def fetch_readme(space_id: str) -> str: url = f"https://huggingface.co/spaces/{space_id}/raw/main/README.md" try: with urllib.request.urlopen(url, timeout=10, context=_SSL_CTX) as r: return r.read().decode("utf-8", errors="replace") except (urllib.error.URLError, urllib.error.HTTPError, TimeoutError): return ""
def clean_readme(raw: str) -> str: if not raw: return "" txt = raw txt = re.sub(r"^---\n[\s\S]*?\n---\n?", "", txt) txt = re.sub(r"!\[[^\]]*\]\([^)]+\)", "", txt) txt = re.sub(r"<img\b[^>]*>", "", txt, flags=re.IGNORECASE) txt = re.sub(r"\[!\[[^\]]*\]\([^)]+\)\]\([^)]+\)", "", txt) txt = re.sub(r"</?[a-zA-Z][^>]*>", "", txt) txt = re.sub(r"\n{3,}", "\n\n", txt) if len(txt) > README_MAX_CHARS: cut = txt.rfind("\n\n", 0, README_MAX_CHARS) if cut > README_MAX_CHARS // 2: txt = txt[:cut] else: txt = txt[:README_MAX_CHARS] return txt.strip()
# ──────────────────────────────────────────────────────────────────────# LLM call# ──────────────────────────────────────────────────────────────────────
def call_llm(hf_token: str, system: str, user: str) -> str | None: body = json.dumps( { "model": MODEL, "messages": [ {"role": "system", "content": system}, {"role": "user", "content": user}, ], "temperature": TEMPERATURE, "max_tokens": MAX_TOKENS, "response_format": {"type": "json_object"}, } ).encode("utf-8") req = urllib.request.Request( HF_INFERENCE_URL, data=body, headers={ "Authorization": f"Bearer {hf_token}", "Content-Type": "application/json", # Cloudflare in front of the router 403s the default # "Python-urllib/x.y" UA. Any reasonable UA passes. "User-Agent": "reachy-mini-prompt-eval/1.0", }, method="POST", ) try: with urllib.request.urlopen(req, timeout=30, context=_SSL_CTX) as r: data = json.loads(r.read().decode("utf-8")) return data.get("choices", [{}])[0].get("message", {}).get("content") except urllib.error.HTTPError as e: detail = e.read().decode("utf-8", errors="replace")[:200] print(f" ✗ LLM HTTP {e.code}: {detail}", file=sys.stderr) return None except Exception as e: # noqa: BLE001 print(f" ✗ LLM error: {e}", file=sys.stderr) return None
def extract_json_obj(text: str) -> dict[str, Any] | None: if not text: return None start = text.find("{") if start == -1: return None depth = 0 for i in range(start, len(text)): c = text[i] if c == "{": depth += 1 elif c == "}": depth -= 1 if depth == 0: try: return json.loads(text[start : i + 1]) except json.JSONDecodeError: return None return None
def sanitize(raw: Any) -> list[str]: if not isinstance(raw, list): return [] out: list[str] = [] seen: set[str] = set() for v in raw: if not isinstance(v, str): continue slug = v.strip().lower() if not slug or slug in seen or slug not in ALLOWED: continue seen.add(slug) out.append(slug) if len(out) >= MAX_CATEGORIES_PER_APP: break return out
# ──────────────────────────────────────────────────────────────────────# Main# ──────────────────────────────────────────────────────────────────────
def read_hf_token() -> str: if os.environ.get("HF_TOKEN"): return os.environ["HF_TOKEN"] env_file = Path(__file__).resolve().parent.parent / ".env" if env_file.exists(): for line in env_file.read_text().splitlines(): m = re.match(r"^\s*HF_TOKEN\s*=\s*(.*?)\s*$", line) if m: v = m.group(1).strip().strip('"').strip("'") if v: return v raise SystemExit("HF_TOKEN not found in env or .env")
def fetch_live_classifications() -> list[dict[str, Any]]: with urllib.request.urlopen(JS_APPS_URL, timeout=30, context=_SSL_CTX) as r: return json.load(r)["apps"]
def main() -> int: hf_token = read_hf_token() apps = fetch_live_classifications() print(f"Loaded {len(apps)} JS apps from prod.\n")
system = build_system_prompt() print(f"System prompt: {len(system)} chars, {system.count(chr(10))} lines.\n")
results: list[dict[str, Any]] = []
for i, app in enumerate(apps, 1): sid = app["id"] name = app.get("name") or sid.split("/")[-1] desc = ( app.get("description") or (app.get("extra") or {}).get("cardData", {}).get("short_description") or "" ) old_cats = app.get("categories") or []
raw_readme = fetch_readme(sid) readme = clean_readme(raw_readme) user = build_user_prompt(name, desc, readme)
reply = call_llm(hf_token, system, user) new_cats = sanitize((extract_json_obj(reply) or {}).get("categories"))
changed = set(old_cats) != set(new_cats) marker = "Δ" if changed else " " print( f" {marker} ({i:>2}/{len(apps)}) {name[:36]:<37} " f"old=[{', '.join(old_cats)}]" + (f" → new=[{', '.join(new_cats)}]" if changed else "") )
results.append( { "id": sid, "name": name, "old": old_cats, "new": new_cats, "changed": changed, } ) time.sleep(0.25)
print() print("─" * 80) print("DIFF (only changed entries)") print("─" * 80) for r in results: if not r["changed"]: continue print( f" {r['name'][:38]:<40} " f"[{', '.join(r['old']) or '∅'}] → [{', '.join(r['new']) or '∅'}]" )
changed_count = sum(1 for r in results if r["changed"]) print() print(f"{changed_count}/{len(results)} entries changed.") return 0
if __name__ == "__main__": sys.exit(main())21 unmodified lines2223242526272810 unmodified lines3940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410521 unmodified lines* the live one and recomputes stale ones on the next pass.*/export const TAXONOMY_VERSION = 1;/*** Canonical category list. Keep slugs short, kebab-case, and10 unmodified lineslabel: 'Music & Beats',emoji: '🎵',description:'Apps where Reachy plays, mixes, generates, or reacts to music ' +'(DJ sets, beat-makers, blind-tests). NOT for apps that just ' +'happen to use audio cues.',},{slug: 'dance',label: 'Dance & Motion',emoji: '💃',description:'Apps centered on dance choreographies, motion replay, ' +'kinetic shows, or recording/replaying robot movements.',},{slug: 'voice',label: 'Voice & Conversation',emoji: '🗣️',description:'Apps where Reachy talks, listens, or holds a real-time voice ' +'conversation: TTS players, LLM-driven chat (OpenAI Realtime, ' +'Claude, Perplexity, etc.), wake-word demos.',},{slug: 'storytelling',label: 'Stories',emoji: '📖',description:'Apps that tell, generate, or guide narrative stories ' +'(interactive fiction, bedtime stories, narrated adventures).',},{slug: 'kids',label: 'For Kids',emoji: '🧒',description:'Apps explicitly designed for children: encyclopedias, ' +'kid-friendly stories, learning games, simple Q&A.',},{slug: 'vision',label: 'Vision & Camera',emoji: '👁️',description:"Apps that consume Reachy's camera feed: face/hand tracking, " +'image classification, mimicry, gesture detection.',},{slug: 'companion',label: 'Companion',emoji: '🤝',description:'Apps positioned as life/emotional companions, mood support, ' +'or friendly buddies that develop a personality over time.',},{slug: 'dev-tools',label: 'Dev & Demos',emoji: '🛠️',description:'Technical demos, debugging tools, remote-control utilities, ' +'minimal proof-of-concepts, and dev-only experiments meant to ' +'showcase a single API or behaviour.',},];21 unmodified lines2223242526272829303132333435363738394010 unmodified lines5152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914021 unmodified lines* the live one and recomputes stale ones on the next pass.*//*** Bump this when the slug list OR the descriptions change in a way* that affects the LLM output. The cache layer invalidates entries* whose taxonomyVersion is older than this and reclassifies them on* the next pass. We don't bump it for cosmetic edits (label / emoji)* since those don't reach the LLM.** History:* - v1: initial 8-slug taxonomy.* - v2: added `games`, tightened `kids` + `dev-tools` descriptions,* switched the prompt to a DECISION ALGORITHM with few-shot.*/export const TAXONOMY_VERSION = 2;/*** Canonical category list. Keep slugs short, kebab-case, and10 unmodified lineslabel: 'Music & Beats',emoji: '🎵',description:'Music creation, playback, beats, songs, DJ mixing, instruments, ' +'blind-test music games. Requires actual music (rhythm / melody / ' +'song). Arbitrary audio (Morse code, alarms, TTS, sound effects) ' +'is NOT music.',},{slug: 'dance',label: 'Dance & Motion',emoji: '💃',description:'Dance choreographies, motion replay, kinetic shows, ' +'recording/replaying robot movements, dance parties.',},{slug: 'voice',label: 'Voice & Conversation',emoji: '🗣️',description:'Reachy talks, listens, or holds a real-time voice ' +'conversation: TTS players, LLM-driven chat (OpenAI Realtime, ' +'Claude, Perplexity), wake-word demos, daily reports / news / ' +'weather read aloud.',},{slug: 'storytelling',label: 'Stories',emoji: '📖',description:'Narrative stories WITH plot and characters: interactive ' +'fiction, bedtime tales, audio adventures, choose-your-own-' +'adventure. NOT for daily reports, news, weather, or Q&A ' +'(those are `voice`).',},{slug: 'kids',label: 'For Kids',emoji: '🧒',description:'Apps that EXPLICITLY target children: the words kids / ' +"children / 'for curious minds' / bedtime / 'learning for kids' " +'must appear in the name or description, OR the app must be ' +'obviously kid-targeted. Combines with `storytelling`, `voice`, ' +'or `games`. Lifestyle, sports, weather, generic personality / ' +'narration / fun framings are NOT kids.',},{slug: 'games',label: 'Games & Play',emoji: '🎮',description:'Apps with a play loop: scores, rounds, win/lose conditions, ' +'quizzes, puzzles, sports simulations, dice/oracles (magic ' +'8-ball), arcade-style mini-games.',},{slug: 'vision',label: 'Vision & Camera',emoji: '👁️',description:"Apps where Reachy's camera DRIVES behaviour: face/hand/pose " +'tracking, image classification, gesture detection, visual ' +'mimicry. Merely streaming or displaying the camera feed ' +'(WebRTC demos, remote-control viewers) is NOT vision.',},{slug: 'companion',label: 'Companion',emoji: '🤝',description:'Apps with an EXPLICIT emotional / personality / buddy framing ' +'in the name or description (companion, buddy, friend, mood, ' +'emotional, personality, pet, Tamagotchi-like, "alive", ' +'"life companion"). Being friendly is not enough.',},{slug: 'dev-tools',label: 'Dev & Demos',emoji: '🛠️',description:'RESERVED slug - see DECISION ALGORITHM step 1 in the prompt. ' +'Use ONLY for pure technical artefacts (debug utilities, SDK ' +'probes, minimal protocol demos, dev-only test spaces) with no ' +'end-user experience. When used, it is the SOLE category - ' +'never combined with another slug.',},];
124 unmodified lines125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165124 unmodified lines}/*** Build the chat messages handed to the LLM. The system prompt* pins the closed taxonomy + the output shape; the user prompt* is the app context.** We deliberately spell out the JSON-only constraint twice* (system + user) because mid-tier 8B models tend to drift into* conversational replies on classification tasks otherwise.*/function buildMessages({ name, description, readme }) {const taxonomy = buildLlmCategoryList();const system = ['You classify a Reachy Mini robot app into a closed list of categories.','','Output ONLY a single JSON object with this exact shape:','{"categories": ["slug1", "slug2"]}','',`Pick 1 to ${MAX_CATEGORIES_PER_APP} categories from the list below, ` +'ordered from most to least relevant. Use the EXACT slug.','If none of the categories clearly fits, output {"categories": []}.','','Available categories:',taxonomy,'','Do not include any text outside the JSON object. No prose, no code fences.',].join('\n');const user = [`App name: ${name || '(unknown)'}`,`Short description: ${description || '(none)'}`,'','README excerpt:',readme || '(no README available)','','Return the JSON now.',].join('\n');return [{ role: 'system', content: system },124 unmodified lines125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280124 unmodified lines}/*** Few-shot examples woven into the system prompt.** Each entry encodes a pitfall the v1 prompt fell into during the* 24-app eval (see `scripts/evaluate-prompt-v2.py`). Keep this list* tight - past ~10 examples the model starts pattern-matching* literally on the example names rather than applying the rules.** Format: [name, description, expected_slugs, brief_justification]*/const FEW_SHOT_EXAMPLES = [['Reachy Morse',"Send Morse code through Reachy's speaker.",['dev-tools'],'(STEP 1 veto: pure technical artefact. NOT music.)',],['WebRTC Demo','Minimal WebRTC connection between Reachy and the browser.',['dev-tools'],'(STEP 1 veto: protocol demo. NOT vision.)',],['TTS Reachy Mini',"Browser TTS that plays out of Reachy Mini's speaker.",['voice'],'(USER-FACING speech output is voice, NOT dev-tools.)',],['Reachy Mochi - Emotional Companion','Your pocket buddy that develops a mood and personality over time.',['companion'],'(explicit emotional/companion framing)',],['Reachy Alive','(README empty; name suggests autonomy and life-like presence)',['companion'],"(USE THE NAME when the README is empty; 'alive' = companion-like)",],['Daily Surf Report',"Reachy reads today's surf report out loud.",['voice'],'(NOT storytelling - a report has no narrative arc. ' +'NOT kids - surfing/sports are not kid-targeted.)',],['Music Quiz','Play a blind test music game with a dancing Reachy.',['music', 'games', 'dance'],'(multi-label: three slugs truly co-apply, ordered by relevance)',],['Mime Bot','Reachy mimics your face live from your webcam.',['vision'],'(NOT companion - mimicry is visual, no emotional framing.)',],];function renderFewShot() {return FEW_SHOT_EXAMPLES.map(([name, desc, slugs, hint]) => {const slugsJson = JSON.stringify(slugs);return (` - ${JSON.stringify(name)}: ${JSON.stringify(desc)}\n` +` → {"categories": ${slugsJson}} ${hint}`);}).join('\n');}/*** Build the chat messages handed to the LLM.** The system prompt is structured as a 3-step DECISION ALGORITHM* rather than a flat list of rules, because the 8B-class model we* use (Llama-3.1-8B-Instruct) follows imperative procedures more* reliably than soft constraints. The `dev-tools` veto in STEP 1* is what stops the model from silently combining it with other* slugs on user-facing apps.** The few-shot examples below the rules cover the v1 pitfalls* (companion hallucinations, music-on-audio, kids-on-personas,* storytelling-on-reports). Six is the sweet spot - more starts* over-fitting on example wording.*/function buildMessages({ name, description, readme }) {const taxonomy = buildLlmCategoryList();const examples = renderFewShot();const system = `You classify a Reachy Mini robot app into a CLOSED list of categories.OUTPUT FORMATReturn ONLY a single JSON object: {"categories": ["slug1", "slug2"]}.Pick 1 to ${MAX_CATEGORIES_PER_APP} slugs, ordered from most to least relevant.Use the EXACT slug. No prose, no code fences, no commentary outside the JSON.DECISION ALGORITHM (apply in order)STEP 1 - \`dev-tools\` vetoIs this app a PURE technical artefact with no user-facing experiencebeyond "here is how the SDK / API works"?Examples that pass the veto: WebRTC demo, SDK probe, debug utility,raw remote-control interface, dev-only test space.Examples that DO NOT pass the veto (they are user-facing apps):TTS players, voice chat, music apps, storytelling, companions -even when the README is dev-heavy.- YES -> return {"categories": ["dev-tools"]} and STOP. Never combine.- NO -> continue to STEP 2.STEP 2 - Pick 1 to ${MAX_CATEGORIES_PER_APP} user-facing slugs from thelist below. Choose the MOST SPECIFIC categories. Order from most toleast relevant. Multi-label is encouraged when two categories trulyco-apply (e.g. music-and-dance, kids storytelling, vision game).If the README is empty or very sparse, USE THE NAME AND DESCRIPTIONas the primary signal - do not bail to an empty list just because theREADME is thin.STEP 3 - Strict slug rules (each must hold, or DO NOT use the slug)- \`companion\`: requires EXPLICIT emotional / personality / buddyframing (companion, buddy, friend, mood, emotional, personality,pet, Tamagotchi-like, "alive", "life companion"). Being friendly isnot enough.- \`music\`: requires actual music - rhythm, melody, songs, beats, DJsets, instruments, music quizzes. Arbitrary audio (Morse, alarms,TTS, sound effects) is NOT music.- \`vision\`: requires the camera to DRIVE behaviour (tracking,classification, mimicry). Merely streaming or displaying the camera(WebRTC demos, remote-control viewers) is NOT vision.- \`storytelling\`: requires a narrative ARC - plot, characters, scenes.Daily reports, news, weather, Q&A are NOT storytelling (they are\`voice\`).- \`games\`: requires a play loop - score, rounds, win/lose, puzzles,quizzes, dice/oracles, sports simulations.- \`kids\`: requires kid-targeted framing (kids/children/curious minds/bedtime/learning for kids) in the name or description. Lifestyle,sports, weather, general conversation are NOT kids.AVAILABLE CATEGORIES${taxonomy}REFERENCE EXAMPLES${examples}Do not include any text outside the JSON object.`;const user =`App name: ${name || '(unknown)'}\n` +`Short description: ${description || '(none)'}\n\n` +`README excerpt:\n${readme || '(no README available)'}\n\n` +'Return the JSON now.';return [{ role: 'system', content: system },