Upload 2 files
Browse files- bench/README.md +36 -0
- bench/bench.py +159 -0
bench/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Genesis AI Code Bench
|
| 2 |
+
**Developed by: Within Us AI**
|
| 3 |
+
Generated: 2026-01-01
|
| 4 |
+
|
| 5 |
+
A lightweight evaluation harness for Genesis-style datasets that focuses on the signals
|
| 6 |
+
developers care about in practice:
|
| 7 |
+
|
| 8 |
+
- **Structure validity** (JSON parsing, required fields, schema consistency)
|
| 9 |
+
- **Tool-trace validity** (JSON array of tool calls with `tool` + `args`)
|
| 10 |
+
- **Diff validity** (`patch_diff` blocks contain recognizable unified-diff markers)
|
| 11 |
+
- **Self-grade validity** (score bounds, confidence bounds, presence of notes)
|
| 12 |
+
- **Governance presence** (audit/tests flags when expected)
|
| 13 |
+
- **Economics presence** (cost budgets + latency targets)
|
| 14 |
+
|
| 15 |
+
This bench is intentionally fast and offline-friendly. It does not execute repo tests; it
|
| 16 |
+
scores dataset quality and readiness for downstream training workflows.
|
| 17 |
+
|
| 18 |
+
## Quick start
|
| 19 |
+
```bash
|
| 20 |
+
python bench.py --jsonl path/to/train.jsonl --max_rows 5000
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
## Metrics produced
|
| 24 |
+
- `format_valid_rate`
|
| 25 |
+
- `required_fields_rate`
|
| 26 |
+
- `tool_trace_valid_rate`
|
| 27 |
+
- `patch_diff_valid_rate`
|
| 28 |
+
- `self_grade_valid_rate`
|
| 29 |
+
- `governance_present_rate`
|
| 30 |
+
- `economics_present_rate`
|
| 31 |
+
- `uniqueness_rate` (hash-based)
|
| 32 |
+
|
| 33 |
+
## Recommended use
|
| 34 |
+
- Run before upload to ensure Viewer-ready consistency
|
| 35 |
+
- Run after merges to confirm schema stability
|
| 36 |
+
- Compare v1.0 vs v1.1 addon impact
|
bench/bench.py
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
\
|
| 2 |
+
#!/usr/bin/env python3
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import json
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from typing import Any, Dict, Iterable, Tuple
|
| 9 |
+
|
| 10 |
+
REQUIRED_FIELDS = {"id","created","topic","task_type","difficulty","instruction","input","output","metadata","hash"}
|
| 11 |
+
|
| 12 |
+
def iter_jsonl(path: Path, max_rows: int | None) -> Iterable[Dict[str, Any]]:
|
| 13 |
+
n = 0
|
| 14 |
+
with path.open("r", encoding="utf-8") as f:
|
| 15 |
+
for line in f:
|
| 16 |
+
line = line.strip()
|
| 17 |
+
if not line:
|
| 18 |
+
continue
|
| 19 |
+
try:
|
| 20 |
+
obj = json.loads(line)
|
| 21 |
+
except Exception:
|
| 22 |
+
yield {"__parse_error__": True}
|
| 23 |
+
n += 1
|
| 24 |
+
if max_rows and n >= max_rows:
|
| 25 |
+
return
|
| 26 |
+
continue
|
| 27 |
+
yield obj
|
| 28 |
+
n += 1
|
| 29 |
+
if max_rows and n >= max_rows:
|
| 30 |
+
return
|
| 31 |
+
|
| 32 |
+
def is_tool_trace_valid(out: Any) -> bool:
|
| 33 |
+
# Accept either a parsed list OR a JSON string representing a list
|
| 34 |
+
if isinstance(out, str):
|
| 35 |
+
s = out.strip()
|
| 36 |
+
if not s:
|
| 37 |
+
return False
|
| 38 |
+
try:
|
| 39 |
+
out = json.loads(s)
|
| 40 |
+
except Exception:
|
| 41 |
+
return False
|
| 42 |
+
if not isinstance(out, list) or len(out) == 0:
|
| 43 |
+
return False
|
| 44 |
+
for step in out:
|
| 45 |
+
if not isinstance(step, dict):
|
| 46 |
+
return False
|
| 47 |
+
if "tool" not in step or "args" not in step:
|
| 48 |
+
return False
|
| 49 |
+
if not isinstance(step["tool"], str) or not isinstance(step["args"], dict):
|
| 50 |
+
return False
|
| 51 |
+
return True
|
| 52 |
+
|
| 53 |
+
def is_patch_diff_valid(out: Any) -> bool:
|
| 54 |
+
if not isinstance(out, str):
|
| 55 |
+
return False
|
| 56 |
+
s = out.strip()
|
| 57 |
+
if "```diff" in s:
|
| 58 |
+
# fenced diff
|
| 59 |
+
return ("-" in s and "+" in s)
|
| 60 |
+
# also allow plain diff-like strings
|
| 61 |
+
return s.startswith("-") or s.startswith("diff") or ("- " in s and "+ " in s)
|
| 62 |
+
|
| 63 |
+
def is_self_grade_valid(out: Any) -> bool:
|
| 64 |
+
if isinstance(out, str):
|
| 65 |
+
try:
|
| 66 |
+
out = json.loads(out)
|
| 67 |
+
except Exception:
|
| 68 |
+
return False
|
| 69 |
+
if not isinstance(out, dict):
|
| 70 |
+
return False
|
| 71 |
+
score = out.get("score")
|
| 72 |
+
conf = out.get("confidence")
|
| 73 |
+
notes = out.get("notes")
|
| 74 |
+
if not (isinstance(score, int) and 0 <= score <= 10):
|
| 75 |
+
return False
|
| 76 |
+
if not (isinstance(conf, (int, float)) and 0.0 <= float(conf) <= 1.0):
|
| 77 |
+
return False
|
| 78 |
+
if not (isinstance(notes, str) and len(notes) >= 3):
|
| 79 |
+
return False
|
| 80 |
+
return True
|
| 81 |
+
|
| 82 |
+
def main() -> int:
|
| 83 |
+
ap = argparse.ArgumentParser(description="Genesis AI Code Bench (Within Us AI)")
|
| 84 |
+
ap.add_argument("--jsonl", required=True, help="Path to JSONL file")
|
| 85 |
+
ap.add_argument("--max_rows", type=int, default=5000)
|
| 86 |
+
args = ap.parse_args()
|
| 87 |
+
|
| 88 |
+
path = Path(args.jsonl)
|
| 89 |
+
total = 0
|
| 90 |
+
format_valid = 0
|
| 91 |
+
required_ok = 0
|
| 92 |
+
tool_ok = tool_total = 0
|
| 93 |
+
diff_ok = diff_total = 0
|
| 94 |
+
grade_ok = grade_total = 0
|
| 95 |
+
gov_ok = 0
|
| 96 |
+
econ_ok = 0
|
| 97 |
+
hashes = set()
|
| 98 |
+
hash_total = 0
|
| 99 |
+
|
| 100 |
+
for obj in iter_jsonl(path, args.max_rows):
|
| 101 |
+
total += 1
|
| 102 |
+
if obj.get("__parse_error__"):
|
| 103 |
+
continue
|
| 104 |
+
format_valid += 1
|
| 105 |
+
|
| 106 |
+
keys = set(obj.keys())
|
| 107 |
+
if REQUIRED_FIELDS.issubset(keys):
|
| 108 |
+
required_ok += 1
|
| 109 |
+
|
| 110 |
+
# hash / uniqueness
|
| 111 |
+
h = obj.get("hash")
|
| 112 |
+
if isinstance(h, str) and h:
|
| 113 |
+
hash_total += 1
|
| 114 |
+
hashes.add(h)
|
| 115 |
+
|
| 116 |
+
# governance + economics (metadata)
|
| 117 |
+
md = obj.get("metadata", {})
|
| 118 |
+
if isinstance(md, dict):
|
| 119 |
+
if md.get("audit_required") is True:
|
| 120 |
+
gov_ok += 1
|
| 121 |
+
if isinstance(md.get("cost_budget"), int) and isinstance(md.get("latency_ms_target"), int):
|
| 122 |
+
econ_ok += 1
|
| 123 |
+
|
| 124 |
+
# task-specific validity
|
| 125 |
+
task = obj.get("task_type")
|
| 126 |
+
out = obj.get("output")
|
| 127 |
+
if task == "tool_trace":
|
| 128 |
+
tool_total += 1
|
| 129 |
+
if is_tool_trace_valid(out):
|
| 130 |
+
tool_ok += 1
|
| 131 |
+
elif task == "patch_diff":
|
| 132 |
+
diff_total += 1
|
| 133 |
+
if is_patch_diff_valid(out):
|
| 134 |
+
diff_ok += 1
|
| 135 |
+
elif task == "self_grade":
|
| 136 |
+
grade_total += 1
|
| 137 |
+
if is_self_grade_valid(out):
|
| 138 |
+
grade_ok += 1
|
| 139 |
+
|
| 140 |
+
def rate(num: int, den: int) -> float:
|
| 141 |
+
return 0.0 if den == 0 else round(num / den, 4)
|
| 142 |
+
|
| 143 |
+
report = {
|
| 144 |
+
"rows_scanned": total,
|
| 145 |
+
"format_valid_rate": rate(format_valid, total),
|
| 146 |
+
"required_fields_rate": rate(required_ok, total),
|
| 147 |
+
"tool_trace_valid_rate": rate(tool_ok, tool_total),
|
| 148 |
+
"patch_diff_valid_rate": rate(diff_ok, diff_total),
|
| 149 |
+
"self_grade_valid_rate": rate(grade_ok, grade_total),
|
| 150 |
+
"governance_present_rate": rate(gov_ok, total),
|
| 151 |
+
"economics_present_rate": rate(econ_ok, total),
|
| 152 |
+
"uniqueness_rate": rate(len(hashes), hash_total),
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
print(json.dumps(report, indent=2))
|
| 156 |
+
return 0
|
| 157 |
+
|
| 158 |
+
if __name__ == "__main__":
|
| 159 |
+
raise SystemExit(main())
|