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 / test_allen_voice.py

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