"""Pre-generate replies for every suggested prompt, for every model, so the Space can serve them without a GPU. PORT=7862 python app.py # in another terminal (TAMEEZ_LIMITS=off so the cache build isn't rate-limited) python tools/build_cache.py http://127.0.0.1:7862/gradio/ > frontend/public/cached_replies.json Greedy decoding, 384 new tokens, system prompt "You are a helpful assistant.", exactly as the live chat by default. """ import json import re import sys from pathlib import Path from gradio_client import Client data = (Path(__file__).resolve().parents[1] / "frontend" / "src" / "data.js").read_text(encoding="utf-8") block = data[data.index("export const TESTS"):data.index("export const STAGES")] prompts = [] for arr in re.findall(r"prompts:\s*\[(.*?)\]", block, re.S): prompts += [json.loads(s) for s in re.findall(r'"(?:[^"\\]|\\.)*"', arr)] client = Client(sys.argv[1], verbose=False) out = [] for p in prompts: entry = {"prompt": p, "replies": {}} for model in ["tiny-aya", "tiny-aya-fire", "llama"]: entry["replies"][model] = client.predict(p, [], model, 384, 0.0, api_name="/chat").strip() print(f"[{model}] {p[:50]} -> {len(entry['replies'][model])} chars", file=sys.stderr) out.append(entry) json.dump(out, sys.stdout, ensure_ascii=False, indent=1)