126 lines
6.1 KiB
Python
126 lines
6.1 KiB
Python
"""Self-check of the quick answers (assistant/quick_answers.py): python tests/test_quick_answers.py
|
|
|
|
Needs the embedding server (assistant/knowledge.embed starts it); nothing moves. Standalone questions get their kind,
|
|
in other words than the bank's too; follow-ups, camera questions, commands and company facts never do."""
|
|
import re
|
|
|
|
from assistant import quick_answers as qa
|
|
|
|
TALK = [("what does cutshion make?", "Cutshion makes robot applications, such as barista and cooking robots.")]
|
|
|
|
KIND = { # words (no talk before) -> kind
|
|
"who made you?": "maker", "Lumi, who built you?": "maker", "누가 만들었어요?": "maker", "어느 회사 로봇이에요?": "maker",
|
|
"what's your name?": "name", "이름이 뭐예요?": "name", "니 이름 머야": "name",
|
|
"how old are you?": "age", "몇 살이에요?": "age", "너 몇 살이야?": "age",
|
|
"who are you?": "who", "넌 누구니?": "who", "introduce yourself please": "who",
|
|
"how tall are you?": "height", "키가 몇이에요?": "height",
|
|
"how long does your battery last?": "battery_life", "배터리 몇 시간 가요?": "battery_life",
|
|
"what languages do you speak?": "languages", "영어 할 줄 알아?": "languages",
|
|
"are you chatgpt?": "chatgpt", "너 챗GPT 써?": "chatgpt", "무슨 AI 써요?": "model",
|
|
"are you a robot?": "robot", "감정 있어요?": "robot",
|
|
"hello": "hello", "안녕하세요": "hello", "hi lumi": "hello",
|
|
"how much do you weigh?": "weight", "how fast can you go?": "speed",
|
|
}
|
|
IN_TALK = { # words after TALK -> kind or None
|
|
"how old are you?": "age", "who made you?": "maker", "what's your name?": "name",
|
|
"how old?": None, "몇 살이에요?": None, "hello": None, "why?": None, "really?": None, "and you?": None,
|
|
"who runs it?": None, "how many people work there?": None, "진짜?": None, "왜요?": None, "너는?": None, "무겁습니까?": None, "어떤 로봇이요?": None,
|
|
}
|
|
NEVER = [ # no talk before: never a quick answer
|
|
"can you see me?", "what am I holding?", "what colour is my shirt?", "how old do I look?", "how tall am I?",
|
|
"나 보여?", "내 옷 무슨 색이야?", "카메라로 뭐 보여요?",
|
|
"come here", "follow me", "wave at me", "sing a song", "이리 와", "손 흔들어 줘", "노래 불러 줘",
|
|
"how many employees does Cutshion have?", "직원이 몇 명이에요?", "how much do you cost?", "가격이 얼마예요?",
|
|
"how long does charging take?", "충전 얼마나 걸려요?", "how old is Cutshion?", "who is the CEO?", "대표가 누구예요?",
|
|
"what's the weather?", "what time is it?", "thanks", "고마워요", "okay", "bye",
|
|
"what's your name and how old are you?", "who made you? and why?", "how much can you lift?",
|
|
"what can you do?", "how much battery is left?", "who made your arm?", "너 얼마야?", "얼마나 무거운 거 들 수 있어?",
|
|
"로봇 미국 회사 맞아요?",
|
|
]
|
|
FACT = {"chatgpt": r"\bno\b|아니", "name": r"lumi|루미", "who": r"lumi|루미", "age": r"\b2\b|two|두 살", "maker": r"cutshion|쿳션",
|
|
"height": r"146", "battery_life": r"10", "languages": r"english|영어", "model": r"gemma|젬마",
|
|
"robot": r"robot|로봇", "weight": r"96", "speed": r"0\.6"}
|
|
|
|
|
|
class _ToLLM(Exception):
|
|
pass
|
|
|
|
|
|
def through_answer():
|
|
"""lumi.Lumi.answer(): the quick answer is said and kept in the talk; "why?" next goes to the LLM."""
|
|
import types
|
|
from assistant import lumi
|
|
from audio import mouth
|
|
from tasks import fetch
|
|
said = []
|
|
lumi.LOG_FILE = "/dev/null"
|
|
mouth.say = lambda text, lang=None, abort=None: said.append(text)
|
|
lumi.ears.understood = lambda *a: True
|
|
lumi.ears.last_stt = {"language": "english", "logprob": -0.1}
|
|
fetch.check_hand = lambda: False
|
|
L = lumi.Lumi.__new__(lumi.Lumi)
|
|
L.lang, L.current, L.closing_pending, L.markers = "en", None, None, ["home", "stage"]
|
|
|
|
def llm(*a, **k):
|
|
raise _ToLLM()
|
|
L.brain = types.SimpleNamespace(history=[], topic=llm, is_lookup_follow_up=lambda t: False)
|
|
for name in ("follow_stop", "drive_words", "fetch_voice", "quick_command"):
|
|
setattr(L, name, lambda *a: False)
|
|
L.voice_setting = lambda text, last: False
|
|
L.mission_running = L.chain_busy = lambda: False
|
|
L.fetch_status = lambda: None
|
|
L.keep_listening = lambda: None
|
|
L.speak_abort = lambda: False
|
|
bad = 0
|
|
L.answer("who made you?")
|
|
if not said or not re.search(r"cutshion", said[-1], re.I) or L.brain.history[-1][0] != "who made you?":
|
|
bad += 1
|
|
print(f"FAIL through answer: {said} {L.brain.history}")
|
|
try:
|
|
L.answer("why?")
|
|
bad += 1
|
|
print("FAIL: why? after a quick answer did not go to the LLM")
|
|
except _ToLLM:
|
|
pass
|
|
return bad
|
|
|
|
|
|
def main():
|
|
bad = 0
|
|
for words, want in KIND.items():
|
|
got = qa.kind_of(words)
|
|
if got != want:
|
|
bad += 1
|
|
print(f"FAIL kind {words!r}: {got} (want {want})")
|
|
for words, want in IN_TALK.items():
|
|
got = qa.kind_of(words, TALK)
|
|
if got != want:
|
|
bad += 1
|
|
print(f"FAIL in talk {words!r}: {got} (want {want})")
|
|
for words in NEVER:
|
|
got = qa.kind_of(words)
|
|
if got:
|
|
bad += 1
|
|
print(f"FAIL never {words!r}: {got}")
|
|
for kind, (_, lines) in qa.KINDS.items(): # every answer says its fact; Korean polite, the right name
|
|
for lang, says in lines.items():
|
|
for s in says:
|
|
if kind in FACT and not re.search(FACT[kind], s, re.I) or lang == "ko" and \
|
|
(not re.search(r"(?:요|다)[.!]?$", s) or re.search(r"컷션|커션", s)):
|
|
bad += 1
|
|
print(f"FAIL answer {kind}/{lang}: {s}")
|
|
a, b = qa.answer("how old are you?", "en"), qa.answer("how old are you?", "en")
|
|
if not a or a == b:
|
|
bad += 1
|
|
print(f"FAIL variety: {a!r} then {b!r}")
|
|
if not re.search(r"[가-힣]", qa.answer("몇 살이에요?", "ko") or ""):
|
|
bad += 1
|
|
print("FAIL Korean answer")
|
|
bad += through_answer()
|
|
print("quick answers:", "all passed" if not bad else f"{bad} failed")
|
|
return bad
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(1 if main() else 0)
|