creative-brain-os / scripts /export_eval_briefs.py
kpranav022's picture
Claude Opus 5.5 (1M context)
Stop paying twice, measure every run, and make the picture, voice and props hold up
13354e2
Raw History Blame Contribute Delete
2.8 kB
"""Export recent real briefs as the eval set. Read-only: it only selects.
python scripts/export_eval_briefs.py # 60 briefs -> evals/briefs.jsonl
python scripts/export_eval_briefs.py --n 90 --out evals/briefs.jsonl
Pulls the newest `brief_intake` rows from agent_outputs (the request exactly as it
was submitted), then takes one per niche in turn so a busy niche can't crowd the
set. Each line is one GenerationRequest payload. Export more than you need and
prune by hand to ~30; see evals/README.md.
"""
from __future__ import annotations
import argparse
import json
import sys
from collections import OrderedDict
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
def round_robin(payloads: list[dict], n: int) -> list[dict]:
"""Newest-first payloads -> up to n, one niche at a time, newest of each first."""
by_niche: OrderedDict[str, list[dict]] = OrderedDict()
for p in payloads:
by_niche.setdefault(p.get("niche", ""), []).append(p)
picked: list[dict] = []
while len(picked) < n and any(by_niche.values()):
for queue in by_niche.values():
if queue and len(picked) < n:
picked.append(queue.pop(0))
return picked
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__.split("\n")[0])
parser.add_argument("--n", type=int, default=60)
parser.add_argument("--out", type=Path, default=ROOT / "evals" / "briefs.jsonl")
args = parser.parse_args(argv)
from app.schemas import GenerationRequest
from app.services.supabase_store import SupabaseStore
# agent_outputs.agent holds the DB enum ("orchestrator"); the internal name
# rides in output.internal_agent. stage "intake" is only ever brief_intake.
rows = SupabaseStore().select(
"agent_outputs",
filters={"agent": "orchestrator", "stage": "intake"},
order_by="created_at",
descending=True,
limit=max(args.n * 10, 500),
columns="output",
)
payloads = []
for row in rows:
output = dict(row.get("output") or {})
if output.pop("internal_agent", "brief_intake") != "brief_intake":
continue
try:
payloads.append(GenerationRequest.model_validate(output).model_dump(mode="json"))
except Exception: # noqa: BLE001 - an old row from a since-changed schema
continue
picked = round_robin(payloads, args.n)
args.out.parent.mkdir(parents=True, exist_ok=True)
args.out.write_text("".join(json.dumps(p) + "\n" for p in picked))
print(f"wrote {len(picked)} briefs across {len({p['niche'] for p in picked})} niches to {args.out}")
return 0
if __name__ == "__main__":
sys.exit(main())