aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / scripts / allen / test_allen_voice.py
| 1 | """Tests for allen_voice against the real catalog. usage: python3 test_allen_voice.py CATALOG_JSON [VOICE_DIR]""" |
| 2 | import hashlib, json, os, sys |
| 3 | sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
| 4 | import allen_voice |
| 5 | |
| 6 | CAT = sys.argv[1] |
| 7 | VDIR = sys.argv[2] if len(sys.argv) > 2 else os.path.dirname(CAT) |
| 8 | fails = 0 |
| 9 | |
| 10 | |
| 11 | def check(name, cond): |
| 12 | global fails |
| 13 | print(("PASS " if cond else "FAIL ") + name) |
| 14 | fails += not cond |
| 15 | |
| 16 | |
| 17 | v = allen_voice.Voice(CAT) |
| 18 | sit = lambda ids: [v.clips[i]["situation"] for i in ids] |
| 19 | |
| 20 | check("morning greeting + menu", sit(v.pick("hey", hour=9)) == ["greeting.morning", "intro.menu"]) |
| 21 | check("late night greeting", sit(v.pick("hello aien", hour=2))[0] == "greeting.late_night") |
| 22 | check("return visit greeting", sit(v.pick("hi", returning=True, hour=15))[0] == "greeting.return_visit") |
| 23 | check("greeting only on turn 0", v.pick("hi", turn=3) == []) |
| 24 | check("cached answer omega", sit(v.pick("what is omega?", answer_id="omega")) == ["explain.omega"]) |
| 25 | check("are you allen", sit(v.pick("wait, are you Allen?", turn=2)) == ["smalltalk.are_you_allen"]) |
| 26 | check("vibe coder", sit(v.pick("I can't code, I just vibe code, is this for me?", turn=1)) == ["encouragement.vibe_coder"]) |
| 27 | check("donation", sit(v.pick("how can I donate?", turn=4)) == ["donation.how"]) |
| 28 | check("sponsor", sit(v.pick("can I sponsor drake on github?", turn=4)) == ["donation.how"]) |
| 29 | check("thanks", sit(v.pick("thanks man", turn=5)) == ["smalltalk.thanks"]) |
| 30 | check("bye", sit(v.pick("bye!", turn=6)) == ["goodbye.general"]) |
| 31 | check("explicit situation", sit(v.pick(situation="error.busy")) == ["error.busy"]) |
| 32 | check("no match -> text only", v.pick("explain the paged KV allocator in detail", turn=2) == []) |
| 33 | check("unknown situation -> text only", v.pick(situation="nope.none") == []) |
| 34 | check("deterministic", v.pick("hey", hour=9) == v.pick("hey", hour=9)) |
| 35 | a = v.pick(situation="goodbye.general", user_text="x") |
| 36 | check("seen clips skipped", v.pick(situation="goodbye.general", user_text="x", seen=a) != a) |
| 37 | check("gated: repo clips off by default", v.pick("check out my repo github.com/a/b", turn=1) == []) |
| 38 | check("gated: menu never mentions repo when repo-coach off", |
| 39 | all("repo" not in v.clips[i]["text"].lower() for i in v.by_situation["intro.menu"])) |
| 40 | v2 = allen_voice.Voice(CAT, features={"repo-coach", "voice-input"}) |
| 41 | check("gated: repo clips on with feature", sit(v2.pick("github.com/a/b", turn=1)) == ["repo.how"]) |
| 42 | check("gated: voice help on with feature", sit(v2.pick("can I use the microphone?", turn=1)) == ["voice.help"]) |
| 43 | check("files() shape", set(v.files(v.pick("hey", hour=9))[0]) == {"id", "file", "text", "duration"}) |
| 44 | |
| 45 | cat = json.load(open(CAT)) |
| 46 | bad = [c["id"] for c in cat["clips"] |
| 47 | if hashlib.sha256(open(os.path.join(VDIR, os.path.basename(c["file"])), "rb").read()).hexdigest() != c["sha256"]] |
| 48 | check("every clip file matches its sha256 (%d clips)" % len(cat["clips"]), not bad) |
| 49 | check("every clip has license and source", all(c.get("license") and c.get("source", {}).get("voice_id") for c in cat["clips"])) |
| 50 | print("RESULT", "PASS" if not fails else "FAIL %d" % fails) |
| 51 | sys.exit(1 if fails else 0) |