interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / scripts / allen / catalog / grade.py

121 lines · 5899 bytes Raw Blame History
1#!/usr/bin/env python3
2"""Grade probe.py eval output against catalog.txt.
3
4 grade.py CATALOG RESULTS_JSON [NOTES_JSON] > report section
5
6Every check is mechanical; NOTES_JSON ({key: "note"}) adds the reviewer's reading
7and may only turn a PASS into FAIL (never the reverse).
8"""
9
10import json
11import re
12import sys
13
14REPO = "https://github.com/aien-dev/"
15SITE = "https://www.aienos.com"
16DOC = REPO + "omega-mv/blob/main/docs/one_layer/OMEGESE.md"
17
18
19def catalog_sets(text):
20 names, pages = set(), set()
21 section = None
22 for line in text.splitlines():
23 if line.startswith(("Active repos", "Start here")):
24 section = "repos"
25 elif line.startswith("Pages"):
26 section = "pages"
27 elif not line.strip():
28 section = None
29 elif line.startswith("Archived:"):
30 for part in line.split(". "):
31 lst = part.split(":", 1)[1]
32 names.update(n.strip(" .") for n in lst.split(","))
33 elif section == "repos":
34 names.add(line.split(":", 1)[0])
35 elif section == "pages":
36 first = line.split(" ", 1)[0]
37 pages.add(first[len(SITE):] if first.startswith(SITE) else first)
38 return names, pages
39
40
41PLURAL = re.compile(r"\b(we|our|ours|ourselves|us)\b", re.I)
42NO = re.compile(r"\b(no|not|nothing|none|isn't|doesn't|don't|hasn't)\b", re.I)
43BROWSE = re.compile(r"(browse|look (it|them|things) up|search the (web|internet)|internet|online)", re.I)
44IDENT = re.compile(r"\b(?:aien|spark|omega|allen|cuda|kube|k8s)[A-Za-z0-9]*(?:[-.][A-Za-z0-9]+)+\b|\b[a-z0-9]+(?:-[a-z0-9]+)*-mv\b", re.I)
45
46EXPECT = {
47 "features": ("names a catalog page", lambda a, n, p: any(x in a for x in ("/allen/", "/omega/", "/hive/", "/start/", "Omega"))),
48 "repos": ("names at least 5 catalog repos", lambda a, n, p: sum(1 for x in n if re.search(r"(?<![\w/-])%s(?![\w-])" % re.escape(x), a)) >= 5),
49 "omega-what": ("points to omega-mv or /omega/", lambda a, n, p: "omega-mv" in a or "/omega/" in a),
50 "exists-translate": ("names aien-translate", lambda a, n, p: "aien-translate" in a),
51 "exists-boot": ("names atlas", lambda a, n, p: re.search(r"\batlas\b", a, re.I) is not None),
52 "exists-gpu": ("names CUDApp or /cudaplusplus/", lambda a, n, p: "CUDApp" in a or "/cudaplusplus/" in a),
53 "k8s": ("says no and drafts an issue block", lambda a, n, p: NO.search(a) is not None and "```issue" in a),
54 "no-mobile": ("says no and offers a feature request", lambda a, n, p: NO.search(a) is not None and ("```issue" in a or re.search(r"feature request|request", a, re.I))),
55 "oss-k8s": ("says it cannot browse", lambda a, n, p: BROWSE.search(a) is not None),
56 "oss-vector": ("says it cannot browse", lambda a, n, p: BROWSE.search(a) is not None),
57 "omega-web": ("mentions the browser/WebAssembly path", lambda a, n, p: re.search(r"browser|WebAssembly|wasm|html", a, re.I) is not None),
58 "omega-gpu": ("points to CUDApp or /cudaplusplus/ or /omega/", lambda a, n, p: any(x in a for x in ("CUDApp", "/cudaplusplus/", "/omega/"))),
59 "omega-http": ("says sockets, no HTTP words", lambda a, n, p: re.search(r"socket", a, re.I) is not None),
60 "where-evidence": ("points to an evidence source", lambda a, n, p: any(x in a for x in ("/evidence/", "benchmarks-mv", "aien-receipts", "/research/status/", "/experiments/"))),
61 "agents": ("points to /agents/ or omega-harness", lambda a, n, p: "/agents/" in a or "omega-harness" in a),
62}
63
64def url_ok(u, names, pages):
65 u = u.rstrip(").,;:'\"`>")
66 if u == DOC or u == REPO.rstrip("/"):
67 return True
68 if u.startswith(REPO):
69 return u[len(REPO):].rstrip("/") in names
70 for base in (SITE, "https://aienos.com", "http://www.aienos.com"):
71 if u.startswith(base):
72 path = u[len(base):].split("#")[0] or "/"
73 return path in pages
74 return False
75
76
77def grade(ans, key, names, pages):
78 problems = []
79 for u in re.findall(r"https?://[^\s)\]>`\"']+", ans):
80 if not url_ok(u, names, pages):
81 problems.append("link not in catalog: " + u)
82 for m in re.findall(r"aien-dev/([A-Za-z0-9._-]+)", ans):
83 if m.rstrip(".") not in names:
84 problems.append("repo not in catalog: " + m)
85 for m in set(IDENT.findall(re.sub(r"https?://\S+", " ", ans))):
86 if m.rstrip(".") not in names and m.lower() not in ("aienos.com", "www.aienos.com", "aien-dev"):
87 problems.append("name not in catalog: " + m)
88 if PLURAL.search(ans):
89 problems.append("plural first person: " + PLURAL.search(ans).group(0))
90 what, ok = EXPECT[key]
91 if not ok(ans, names, pages):
92 problems.append("expected: " + what)
93 return problems
94
95
96def main():
97 cat = open(sys.argv[1], encoding="ascii").read()
98 names, pages = catalog_sets(cat)
99 results = json.load(open(sys.argv[2]))
100 notes = json.load(open(sys.argv[3])) if len(sys.argv) > 3 else {}
101 rows, body, passed = [], [], 0
102 for i, r in enumerate(results, 1):
103 probs = grade(r["text"], r["key"], names, pages)
104 note = notes.get(r["key"], "")
105 if note.startswith("FAIL"):
106 probs.append("reviewer: " + note[5:].strip())
107 verdict = "FAIL" if probs else "PASS"
108 passed += verdict == "PASS"
109 u = r.get("usage") or {}
110 rows.append("| %d | %s | %s | %s | %.2f | %s |" % (i, r["key"], verdict, u.get("prompt_tokens"),
111 r["ttft_s"], "; ".join(probs) or (note or "-")))
112 body.append("### %d. %s (%s)\n\nQ: %s\n\n````text\n%s\n````\n" % (i, r["key"], verdict, r["question"], r["text"].strip()))
113 print("Result: %d/%d PASS\n" % (passed, len(results)))
114 print("| # | key | verdict | prompt tokens | TTFT s | findings |\n|---|---|---|---|---|---|")
115 print("\n".join(rows))
116 print()
117 print("\n".join(body))
118
119
120if __name__ == "__main__":
121 main()