forked from ChelseaKR/sprout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_materialize_content.py
More file actions
63 lines (53 loc) · 2.35 KB
/
Copy path_materialize_content.py
File metadata and controls
63 lines (53 loc) · 2.35 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
57
58
59
60
61
62
63
"""One-shot: turn the content-workflow JSON output into committed corpus + eval files."""
from __future__ import annotations
import json
import sys
from pathlib import Path
import yaml
ROOT = Path(__file__).resolve().parent.parent
SRC = Path(sys.argv[1])
data = json.loads(SRC.read_text(encoding="utf-8"))
data = data.get("result", data)
processed = ROOT / "corpus" / "processed"
processed.mkdir(parents=True, exist_ok=True)
suites_dir = ROOT / "eval" / "suites"
suites_dir.mkdir(parents=True, exist_ok=True)
manifest_docs: list[dict[str, object]] = []
for doc in data["documents"]:
slug = doc["slug"]
(processed / f"{slug}.md").write_text(doc["en_markdown"].rstrip() + "\n", encoding="utf-8")
(processed / f"{slug}.es.md").write_text(doc["es_markdown"].rstrip() + "\n", encoding="utf-8")
common = {
"source_name": "Synthetic Plant-Care Notes",
"url": f"https://example.invalid/{slug}",
"license": "CC0-1.0",
"fetch_date": "2026-05-01",
"topic": "care",
}
manifest_docs.append({"file": f"{slug}.md", "title": doc["title_en"], "language": "en", **common})
manifest_docs.append({"file": f"{slug}.es.md", "title": doc["title_es"], "language": "es", **common})
manifest = {
"_note": "Synthetic, CC0-1.0 reference corpus. Toxicity reflects publicly known status; "
"prose is original. Not authoritative horticulture. See docs/cards/data-card-corpus.md.",
"documents": sorted(manifest_docs, key=lambda d: str(d["file"])),
}
(ROOT / "corpus" / "manifest.yaml").write_text(
yaml.safe_dump(manifest, sort_keys=False, allow_unicode=True), encoding="utf-8"
)
total_cases = 0
for suite in data["suites"]:
cases = suite["cases"]
# Drop any keys that are None so the YAML stays clean.
clean = [{k: v for k, v in c.items() if v is not None} for c in cases]
(suites_dir / f"{suite['key']}.yaml").write_text(
yaml.safe_dump({"cases": clean}, sort_keys=False, allow_unicode=True), encoding="utf-8"
)
total_cases += len(clean)
print(f" {suite['key']}: {len(clean)} cases")
probes = data.get("probes", [])
(ROOT / "eval" / "judge_probes.yaml").write_text(
yaml.safe_dump({"probes": probes}, sort_keys=False, allow_unicode=True), encoding="utf-8"
)
print(f"documents: {len(data['documents'])} plants (x2 languages)")
print(f"eval cases: {total_cases}")
print(f"judge probes: {len(probes)}")