aien-train
AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Brought by drakestapleton
aien-train / tools / omegallm-ui / check.py
| 1 | #!/usr/bin/env python3 |
| 2 | """HTTP test oracle only. Not a model runtime or installation dependency.""" |
| 3 | import argparse |
| 4 | import hashlib |
| 5 | import json |
| 6 | import time |
| 7 | import urllib.error |
| 8 | import urllib.request |
| 9 | from pathlib import Path |
| 10 | |
| 11 | p = argparse.ArgumentParser() |
| 12 | p.add_argument("--port", type=int, choices=(8098, 8099), required=True) |
| 13 | p.add_argument("--output", type=Path, required=True) |
| 14 | a = p.parse_args() |
| 15 | model = "Omega-Astra-Aienux" if a.port == 8099 else "Omega-Astra-2026-11-04" |
| 16 | base = f"http://127.0.0.1:{a.port}" |
| 17 | results = [] |
| 18 | |
| 19 | def request(path, body=None, headers=None): |
| 20 | return urllib.request.urlopen(urllib.request.Request( |
| 21 | base + path, None if body is None else json.dumps(body).encode(), |
| 22 | {"Content-Type": "application/json", **(headers or {})}), timeout=180) |
| 23 | |
| 24 | body = {"model": model, "messages": [{"role": "user", "content": |
| 25 | "Once upon a time, a little robot found a lost kitten."}], |
| 26 | "temperature": 0, "seed": 42, "max_tokens": 1, "stream": True} |
| 27 | start = time.monotonic() |
| 28 | text = "" |
| 29 | first = None |
| 30 | done = False |
| 31 | with request("/v1/chat/completions", body) as response: |
| 32 | for raw in response: |
| 33 | if not raw.startswith(b"data: "): |
| 34 | continue |
| 35 | line = raw[6:].strip() |
| 36 | if line == b"[DONE]": |
| 37 | done = True |
| 38 | break |
| 39 | part = json.loads(line)["choices"][0]["delta"].get("content", "") |
| 40 | if part and first is None: |
| 41 | first = time.monotonic() - start |
| 42 | text += part |
| 43 | assert text == " The" and done, (text, done) |
| 44 | results.append({"case": "stream-parity", "model": model, "text": text, |
| 45 | "first_text_seconds": first, "total_seconds": time.monotonic() - start, "pass": True}) |
| 46 | |
| 47 | for name, payload, headers, expected in [ |
| 48 | ("unknown-model", {"model": "unknown", "messages": []}, {}, 404), |
| 49 | ("empty-prompt", {"model": model, "messages": []}, {}, 400), |
| 50 | ("foreign-origin", body, {"Origin": "https://example.invalid"}, 403), |
| 51 | ("foreign-host", body, {"Host": "example.invalid"}, 403), |
| 52 | ("tools", {**body, "tools": [{}]}, {}, 400), |
| 53 | ]: |
| 54 | try: |
| 55 | with request("/v1/chat/completions", payload, headers) as r: |
| 56 | status = r.status |
| 57 | except urllib.error.HTTPError as e: |
| 58 | status = e.code |
| 59 | assert status == expected, (name, status, expected) |
| 60 | results.append({"case": name, "status": status, "pass": True}) |
| 61 | |
| 62 | with request("/") as r: |
| 63 | actual = r.read() |
| 64 | with urllib.request.urlopen(urllib.request.Request("http://127.0.0.1:8097/", |
| 65 | headers={"Accept-Encoding": "gzip"}), timeout=10) as r: |
| 66 | reference = r.read() |
| 67 | assert actual == reference, "UI asset proxy changed the upstream bytes" |
| 68 | results.append({"case": "ui-assets", "sha256": hashlib.sha256(actual).hexdigest(), "pass": True}) |
| 69 | |
| 70 | with request("/v1/chat/completions", {"model": "build-mac/qwen.gguf", "messages": [ |
| 71 | {"role": "user", "content": "What is 17 plus 25? Answer with only the number."}], |
| 72 | "temperature": 0, "max_tokens": 8, "stream": False}) as r: |
| 73 | answer = json.load(r)["choices"][0]["message"]["content"] |
| 74 | assert "42" in answer, answer |
| 75 | results.append({"case": "qwen-route", "text": answer, "pass": True}) |
| 76 | a.output.parent.mkdir(parents=True, exist_ok=True) |
| 77 | a.output.write_text(json.dumps({"port": a.port, "results": results}, indent=2) + "\n") |
| 78 | print(f"PASS port={a.port} checks={len(results)}") |