Hearing: no false wakes from whisper's prompt, own-voice filter only while Lumi talks, Korean retry with a Korean prompt, f16 whisper model, ASR bench

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-22 02:03:07 +09:00
co-authored by Claude Opus 5.5
parent c31bee4d2f
commit 8451fd5837
19 changed files with 2523 additions and 122 deletions
+53 -16
View File
@@ -3,6 +3,7 @@
.venv/bin/python tests/web_check.py # every case and dialogue -> logs/web_check.md / .json
.venv/bin/python tests/web_check.py cases # only the single questions (or: dialogues)
.venv/bin/python tests/web_check.py nobel # only questions containing this
.venv/bin/python tests/web_check.py new # the second set (tests/web_cases2.py) -> logs/web_check2.*
Each turn goes the way lumi.answer() sends it (keyword rules, a follow-up of a lookup, else the LLM's action line;
search -> brain.search_query, not sure -> brain.search_terms), then web.search / web.weather and
@@ -17,10 +18,38 @@ import pathlib
import re
import sys
import time
import urllib.request
from assistant import brain, lumi, web
from assistant import brain, llm_direct, lumi, web
from tests.conversation_check import NOW, rules_route
from tests.web_cases import CASES, DIALOGUES
from tests import web_cases, web_cases2
PROMPTS = [] # every prompt sent to the runner, in order: the tokens it had to read (not cached)
_render = llm_direct.render
llm_direct.render = lambda *a, **k: PROMPTS.append(_render(*a, **k)) or PROMPTS[-1]
def _tokens(text):
port = llm_direct._ports.get(brain.MODEL) or llm_direct._find_port(brain.MODEL)
req = urllib.request.Request(f"http://127.0.0.1:{port}/tokenize", json.dumps({"content": text}).encode())
with urllib.request.urlopen(req, timeout=10) as r:
return json.loads(r.read())["tokens"]
def new_tokens(first):
"""Prompt tokens the runner reads for the prompts from PROMPTS[first] on, each after the one before (the first
after the warm-up prefill; one slot, as on the robot when nobody else uses the model): what the visitor waits
for, ~1300 tokens a second."""
total = 0
for i in range(max(first, 1), len(PROMPTS)):
a, b = _tokens(PROMPTS[i - 1]), _tokens(PROMPTS[i])
same = next((k for k, (x, y) in enumerate(zip(a, b)) if x != y), min(len(a), len(b)))
total += len(b) - same
return total
web.openai_ready = lambda: False # the free search only: the OpenAI credit is kept for the conference
web.openai_answer = lambda *a, **k: None
ROOT = pathlib.Path(__file__).resolve().parents[1]
OUT_JSON = ROOT / "logs" / "web_check.json"
@@ -44,9 +73,6 @@ Decide:
A number or name that is in neither is false.
- found: does the fetched text contain the answer to the question?
Answer JSON {{"answers": true or false, "grounded": true or false, "found": true or false, "why": "a few words"}}."""
SCHEMA = {"type": "object", "properties": {"answers": {"type": "boolean"}, "grounded": {"type": "boolean"},
"found": {"type": "boolean"}, "why": {"type": "string"}},
"required": ["answers", "grounded", "found", "why"]}
def turn(b, lang, text):
@@ -95,7 +121,8 @@ def turn(b, lang, text):
facts = web.weather(target) if action == "weather" else web.search(target)
out["fetch_s"], out["facts"] = time.time() - tf, facts or "NO INTERNET"
words = []
for s in b.respond_from(text, facts or "No results."):
asked = f"{text} (the weather)" if action == "weather" else text # as lumi.look_up asks it
for s in b.respond_from(asked, facts or "No results."):
words.append(s)
if out["first_s"] is None or out["route"] == "unsure" and len(words) == 1:
out["first_s"] = time.time() - t0
@@ -107,7 +134,9 @@ def judge(q, res, context=""):
msg = JUDGE.format(today=time.strftime("%Y-%m-%d"), context=context, q=q, a=res["answer"],
facts=(res["facts"] or "")[:FACTS_TO_JUDGE])
try:
return json.loads(brain._chat([{"role": "user", "content": msg}], SCHEMA, temperature=0))
out = brain._chat([{"role": "user", "content": msg + " Only the JSON."}], temperature=0) # the runner
return {"answers": False, "grounded": False, "found": False, "why": out[:80]} | \
json.loads(re.search(r"\{.*\}", out, re.S).group(0)) # directly: Ollama queues behind others
except Exception as e: # noqa: BLE001 - shown in the report
return {"answers": False, "grounded": False, "found": False, "why": f"judge failed: {e}"}
@@ -120,15 +149,18 @@ def score(must, res, verdict):
return gold and verdict["answers"] and (verdict["grounded"] or not looked)
def run(only=None, part=None):
def run(only=None, part=None, cases=web_cases):
rows = []
groups = ([] if part == "dialogues" else [[c] for c in CASES]) + ([] if part == "cases" else DIALOGUES)
groups = ([] if part == "dialogues" else [[c] for c in cases.CASES]) + ([] if part == "cases" else cases.DIALOGUES)
for group in groups:
if only and not any(only.lower() in q.lower() for _, q, _ in group):
continue
b, context = brain.Brain(), ""
for lang, q, must in group:
b.warm(MARKS) # as lumi.py does when it starts to listen: the runner reads the prompt's
start = len(PROMPTS) # start while the visitor talks; only what comes after is waited for
res = turn(b, lang, q)
res["new_tokens"] = new_tokens(start)
rows.append({"q": q, "lang": lang, "must": must, "dialogue": len(group) > 1, "context": context, **res})
first = f"{res['first_s']:.1f}" if res["first_s"] else "-"
print(f"{first:>5}s {res['route']:<12} {q}\n -> {res['answer'][:160]}", flush=True)
@@ -141,11 +173,12 @@ def run(only=None, part=None):
return rows
def report(rows):
OUT_JSON.write_text(json.dumps(rows, ensure_ascii=False, indent=1))
def report(rows, out_json=OUT_JSON, out_md=OUT_MD):
out_json.write_text(json.dumps(rows, ensure_ascii=False, indent=1))
looked = [r for r in rows if r["target"]]
firsts = sorted(r["first_s"] for r in looked if r["first_s"])
fetches = sorted(r["fetch_s"] for r in looked if r["fetch_s"])
toks = sorted(r.get("new_tokens", 0) for r in looked)
pct = lambda xs, p: xs[min(len(xs) - 1, int(p * len(xs)))] if xs else 0
lines = [f"# Web answers check, {time.strftime('%Y-%m-%d %H:%M')}", "",
f"- passed: {sum(r['ok'] for r in rows)} / {len(rows)} (stable facts with a must: "
@@ -155,18 +188,22 @@ def report(rows):
f"- looked up: {len(looked)}; judge: answers {sum(r['answers'] for r in looked)}, grounded "
f"{sum(r['grounded'] for r in looked)}, answer in the fetched text {sum(r['found'] for r in looked)}",
f"- first sentence after a lookup: median {pct(firsts, 0.5):.1f} s, 90 % {pct(firsts, 0.9):.1f} s, "
f"max {pct(firsts, 1):.1f} s; fetch median {pct(fetches, 0.5):.1f} s, max {pct(fetches, 1):.1f} s", "",
f"max {pct(firsts, 1):.1f} s; fetch median {pct(fetches, 0.5):.1f} s, max {pct(fetches, 1):.1f} s",
f"- prompt tokens read for a looked-up turn (not cached, one user): median {pct(toks, 0.5)}, 90 % "
f"{pct(toks, 0.9)}", "",
"| ok | first s | route | question | answer | why |", "|---|---|---|---|---|---|"]
for r in rows:
cell = lambda s: str(s).replace("|", "/").replace("\n", " ")[:200]
lines.append(f"| {'✅' if r['ok'] else '❌'} | {r['first_s'] or 0:.1f} | {r['route']} | {cell(r['q'])} | "
f"{cell(r['answer'])} | {cell(r['why'])} |")
OUT_MD.write_text("\n".join(lines) + "\n")
print("\n".join(lines[:6]))
out_md.write_text("\n".join(lines) + "\n")
print("\n".join(lines[:7]))
if __name__ == "__main__":
args = sys.argv[1:]
new = "new" in args
part = next((a for a in args if a in ("cases", "dialogues")), None)
only = next((a for a in args if a not in ("cases", "dialogues")), None)
report(run(only, part))
only = next((a for a in args if a not in ("cases", "dialogues", "new")), None)
rows = run(only, part, web_cases2 if new else web_cases)
report(rows, *((OUT_JSON.with_name("web_check2.json"), OUT_MD.with_name("web_check2.md")) if new else ()))