Commands: chained commands, questions and talk run in the order said; a part that can't run is said with its reason
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+130
-48
@@ -199,7 +199,7 @@ ASK_PREFIX = re.compile(r"\b(do|did) you (know|happen to know)\b|\b(can|could) y
|
||||
ASKS_MORE = re.compile(r"\?|\b(but|can|could|what|how|where|why|when|who|one more)\b|근데|그런데|뭐|어떻게|어디|언제|누구|하나만 더|"
|
||||
r"물어볼게|물어봐도", re.I)
|
||||
THANKS_REST = re.compile(r"\b(?:a bunch|a lot|so much|very much|lovely|great|nice|cool|good to know|again|that was \w+|"
|
||||
r"for (?:the|that|this|telling) \w+)\b|감사요|잘 들었어요|잘 알겠어요|[~!.,\s요]", re.I)
|
||||
r"for (?:the|that|this|telling|your) \w+)\b|감사요|잘 들었어요|잘 알겠어요|[~!.,\s요]", re.I)
|
||||
# left of "Lovely, thanks!", "고마워요~" after the thanks: nothing, so only thanks (talk_fate waits)
|
||||
FOREIGN_SCRIPT = re.compile(r"[\u0400-\u04ff\u4e00-\u9fff\u3040-\u30ff]") # Cyrillic, Chinese, Japanese
|
||||
UNSURE_LOOKUP = False # look up what the model says it is not sure of: on for gemma4:e4b, which said "not sure"
|
||||
@@ -216,14 +216,19 @@ NOT_KNOWN = {"en": ["I'm sorry, I don't have that information. A staff member ca
|
||||
def not_known(lang):
|
||||
return random.choice(NOT_KNOWN[lang])
|
||||
TALK_ASK_S = 15.0 # s of silence while halted for someone -> "Can I go on with my task?", again -> go on
|
||||
FAREWELL_ONLY = re.compile(r"^\s*(?:(?:ok(?:ay)?|alright|lumi|루미야?)[\s,.!]+)?(?:go on|you can go|good|very good|"
|
||||
r"good job|great job|nice job|well done|take care|"
|
||||
r"가 ?보세요|가세요|가도 ?돼요?|잘했어요?|잘했네요?|좋아|좋네요?|수고했어요?|고생했어요?|"
|
||||
r"됐어요?,? 고마워요?)[\s.!~]*$", re.I) # said alone: the talk is over
|
||||
RELEASE = re.compile(r"^\s*(?:(?:ok(?:ay)?|alright|lumi|루미야?)[\s,.!]+)?(?:you can go(?: now)?|take care|가 ?보세요|가세요|가도 ?돼요?)"
|
||||
r"[\s.!~]*$", re.I) # said alone: the visitor lets Lumi go
|
||||
THANKS = re.compile(r"\bthank(?:s| you)\b|\bthanx\b|\bcheers\b|고마워|고맙|감사|땡큐", re.I)
|
||||
DONE_WORDS = re.compile(r"\bthat'?s (?:it|all|enough|everything)\b|\bno,? thanks?\b|\bnothing(?: else)?\b|\benough\b|됐어|됐습니다|"
|
||||
r"그만", re.I) # with thanks: "that's it, thank you", "됐어요 고마워요" end the talk
|
||||
WELCOME = {"en": ["You're welcome.", "My pleasure.", "Anytime."], "ko": ["천만에요.", "별말씀을요.", "네, 언제든지요."]}
|
||||
r"그만", re.I) # "that's it", "됐어요": maybe done; the LLM decides with the talk before
|
||||
CLEAR_BYE = re.compile(r"\b(?:bye|bay bay|goodbye|(?<!can't )(?<!cant )(?<!cannot )(?<!not )(?<!to )see you|see ya|good night|"
|
||||
r"take care|i (?:have|need) to go|gotta (?:go|run)|i'?m leaving|i'?m off|have a (?:good|nice|great) (?:one|day)|"
|
||||
r"nice (?:talking|meeting|chatting)(?: (?:to|with))? you|(?:was|been) nice to meet you)\b|"
|
||||
r"(?<=\S)[\s.,!]+안녕[\s.!~]*$|안녕히|잘 ?가|잘 ?있어|잘 ?있게|수고하세요|들어가세요|바이바이|빠이|"
|
||||
r"(?<![가-힣])바이(?![가-힣])|(?<![가-힣])간다[\s.!~]*$|가 ?볼게요|갈게요|가야 ?(?:돼|해|겠|할)|"
|
||||
r"다음에 (?:또 )?(?:봐|봬|만나|올게)|또 (?:봐|봬|올게)|나중에 봐|좋은 하루|"
|
||||
r"(^|\s)(나|저|우리|저희) (이제 )?(집에 )?(가|간다|가요|갑니다)[\s.!]*$", re.I)
|
||||
# a goodbye in any talk: "okay, bye", "I have to go", "수고하세요" (thanks, okay, 됐어: the LLM reads them)
|
||||
RECEIVE_OK = re.compile(r"\b(ok(ay)?|done|here you go|there you go|go ahead|thank|thanks|yes)\b|됐어|됐습니다|놨어|여기요|"
|
||||
r"네|고마워|감사", re.I) # the person has let go of what they handed over
|
||||
FETCH_THANKS = re.compile(r"\bthank|\bthanks\b|고마워|감사", re.I)
|
||||
@@ -258,11 +263,6 @@ STATUS_Q = re.compile(
|
||||
r"(?:컵|병|사과|바나나|오렌지)(?:을|를)? ?들고 ?있(?:어|니|나요|어요)?\?|손이 ?비어|뭐 ?가져가는|그거 ?(?:누구 ?거|나 ?주는)", re.I)
|
||||
NOT_STATUS_NOW = re.compile(r"\b(tonight|after work|weekend|tomorrow|later today|for fun|in your free time)\b|주말|쉬는 날|"
|
||||
r"저 사람|우리|내일|퇴근|나중에", re.I) # not about what Lumi is doing now
|
||||
FAREWELL_WORDS = re.compile(r"\b(thanks?|thank you|cheers|bye|bay bay|goodbye|(?<!can't )(?<!cant )(?<!cannot )(?<!not )(?<!to )see you|see ya|that'?s all|good night)\b|(?<=\S)[\s.,!]+안녕[\s.!~]*$|고마워|감사|안녕히|잘 ?가|"
|
||||
r"다음에|수고하세요|잘 ?있어|잘 ?있게|바이바이|빠이|(?<![가-힣])바이(?![가-힣])|땡큐|(?<![가-힣])간다[\s.!~]*$|i (have|need) to go|gotta go|i'?m leaving|"
|
||||
r"nice (talking|meeting|chatting)( (to|with))? you|(was|been) nice to meet you|good night|take care|들어가세요|"
|
||||
r"가 ?볼게요|갈게요|이만|나중에 봐요|또 봐요|좋은 하루|(^|\s)(나|저|우리|저희) (이제 )?(집에 )?(가|간다|가요|갑니다)[\s.!]*$",
|
||||
re.I)
|
||||
HELLO_ONLY = re.compile(r"^\s*(hi|hey|hello|hiya)( there)?[\s,.!]*$|^\s*(안녕|안녕하세요)[\s.!]*$", re.I)
|
||||
CAMERA_HALF_FOV = 42.0 # deg; half the camera's view (+ the head's YAW_LIMIT for the head camera)
|
||||
WAKE_MAX_S = 6.0 # s; longer utterances are not checked for the wake word
|
||||
@@ -666,6 +666,9 @@ class Modes:
|
||||
|
||||
|
||||
class Lumi:
|
||||
chain_thread = None # several commands of one sentence done in order (chain_run)
|
||||
chain_stop = threading.Event() # set by "stop" or anything new said: the rest of the chain is not done
|
||||
|
||||
def __init__(self, args):
|
||||
self.a = args
|
||||
self.brain = Brain()
|
||||
@@ -1030,6 +1033,7 @@ class Lumi:
|
||||
"""Stop by voice: the fetch / mission runner, the base, the arm, a trip; then say so."""
|
||||
from tasks import fetch
|
||||
log(" stop by voice")
|
||||
self.chain_stop.set()
|
||||
safe(fetch.stop)
|
||||
self.act("stop", "")
|
||||
if self.patrol:
|
||||
@@ -1337,6 +1341,83 @@ class Lumi:
|
||||
en += f" I'm holding {held}."
|
||||
return en, ko
|
||||
|
||||
# ---------- several commands in one sentence (assistant/chain.py) ----------
|
||||
def chain_busy(self):
|
||||
return self.chain_thread is not None and self.chain_thread.is_alive()
|
||||
|
||||
def chain_request(self, text):
|
||||
"""Commands, questions and talk in one sentence, done in the order said (chain.plan). True if it was one."""
|
||||
from assistant import chain
|
||||
if self.mission_running() or self.chain_busy():
|
||||
return False
|
||||
plan = chain.plan(text, self.markers, NOT_A_STEP)
|
||||
if not plan:
|
||||
return False
|
||||
log(f" chain: {[(k, w) for k, w, _ in plan]}")
|
||||
self.chain_stop.clear()
|
||||
self.chain_thread = threading.Thread(target=self.chain_run, args=(plan,), daemon=True)
|
||||
self.chain_thread.start()
|
||||
return True
|
||||
|
||||
def chain_run(self, plan):
|
||||
"""Each part in turn, the next once the one before is done (chain_wait). A part that can't be done says why
|
||||
(quick_command, the mission runner, the LLM's answer) and the rest goes on; after a mission part that failed,
|
||||
the parts that drive or need the hand are not done and that is said. "Stop" or new words end it."""
|
||||
from assistant import chain, steps
|
||||
from tasks import fetch
|
||||
failed = False
|
||||
for i, (kind, words, what) in enumerate(plan):
|
||||
if self.chain_stop.is_set():
|
||||
log(f" chain stopped before {words!r}")
|
||||
return
|
||||
log(f" chain part {i + 1}/{len(plan)}: {kind} {words!r}")
|
||||
if failed and (kind == "steps" or kind == "quick" and what[0] in chain.DRIVES | {"pick", "put", "move_object"}):
|
||||
log(f" chain: {words!r} not done (the part before failed)")
|
||||
self.fetch_say(f"So I didn't do this part: {words}.", "그래서 이 부분은 하지 않았어요.")
|
||||
continue
|
||||
if kind == "talk":
|
||||
self.answer(words, part=True)
|
||||
elif kind == "quick":
|
||||
self.quick_command(words)
|
||||
else:
|
||||
if {st["do"] for st in what} & DRIVE_STEPS and (self.base_off("go_to") or not self.modes.drive):
|
||||
failed = True
|
||||
if self.modes.patrol:
|
||||
self.fetch_say("Sorry, driving is switched off.", "죄송해요, 지금은 이동할 수 없어요.")
|
||||
continue
|
||||
problems = steps.check(what, fetch.check_hand(), self.markers)
|
||||
if problems:
|
||||
log(f" chain part refused: {problems}")
|
||||
self.fetch_say(problems[0], "죄송해요, 그렇게는 할 수 없어요.")
|
||||
failed = True
|
||||
continue
|
||||
self.stay()
|
||||
try:
|
||||
fetch.run_steps(what, say=self.fetch_say)
|
||||
except fetch.FetchError as e:
|
||||
log(f" chain part refused: {e}")
|
||||
self.fetch_say(str(e), "죄송해요, 지금은 할 수 없어요.")
|
||||
failed = True
|
||||
continue
|
||||
self.chain_wait()
|
||||
if kind == "steps" and (safe(fetch.state) or {}).get("status") in ("failed", "stopped"):
|
||||
failed = True
|
||||
log(" chain done")
|
||||
|
||||
def chain_wait(self, poll_s=0.3, settle_s=0.6):
|
||||
"""Until the part just started is over: a trip, a pick / put, a mission or move, a wave, the head or lift."""
|
||||
from tasks import fetch
|
||||
time.sleep(settle_s) # the part's thread has started its work by then
|
||||
last = None
|
||||
while not self.chain_stop.is_set(): # (a follow is only the last part: not waited for)
|
||||
busy = self.traveling() or self.skill_busy() or self.busy_now == "wave" or \
|
||||
(safe(fetch.state) or {}).get("status") == "running"
|
||||
pose = safe(head.status)
|
||||
if not busy and pose is not None and pose == last:
|
||||
return
|
||||
last = pose
|
||||
time.sleep(poll_s)
|
||||
|
||||
def mission_request(self, text):
|
||||
"""A command of several steps (docs/17), said by voice: read back, start on yes or silence. True if it was
|
||||
one (also when refused). A single move / turn / arm / go stays with quick_command (no read-back)."""
|
||||
@@ -1348,9 +1429,6 @@ class Lumi:
|
||||
if unread:
|
||||
log(f" mission: unread {unread} ({by})")
|
||||
problem = brain_mod.place_problem(" ".join(unread), self.markers) # "go to booth" with two booths
|
||||
if not problem and not got:
|
||||
problem = ("Sorry, I can do only one of those at a time. Please ask me one thing at a time.",
|
||||
"죄송해요, 한 번에 하나씩만 할 수 있어요. 하나씩 말씀해 주세요.")
|
||||
if not problem and all(brain_mod.intent(u, self.markers) for u in unread):
|
||||
problem = (f"Sorry, I can't do that as part of a task: {', '.join(unread)}. Please ask me one thing at a time.",
|
||||
"죄송해요, 그건 작업 중에 함께 할 수 없어요. 하나씩 말씀해 주세요.")
|
||||
@@ -1876,6 +1954,8 @@ class Lumi:
|
||||
def look_up(self, text, action, target, t0=None):
|
||||
"""Weather or web facts -> short spoken answer (interruptible)."""
|
||||
en = self.lang == "en"
|
||||
if action == "weather": # "내일 비 와?" after Jeju's weather: Jeju
|
||||
target = self.brain.weather_place(target, text)
|
||||
if action == "search" and private_ask(text): # never looked up, whoever it is about
|
||||
log(" search refused: a person's private details")
|
||||
mouth.say(PRIVATE_SAY["en" if en else "ko"])
|
||||
@@ -2071,9 +2151,13 @@ class Lumi:
|
||||
self.current, self.voice_until = None, 0.0
|
||||
return True
|
||||
|
||||
def answer(self, text):
|
||||
def answer(self, text, part=False):
|
||||
"""Stream the LLM reply: act on the action line, speak sentence by sentence.
|
||||
Clear commands (go home, go to p1, come here, be quiet...) are done at once without the LLM."""
|
||||
Clear commands (go home, go to p1, come here, be quiet...) are done at once without the LLM.
|
||||
part: one part of a sentence of several (chain_run); otherwise a chain still running ends here."""
|
||||
if not part and self.chain_busy() and not brain_mod.is_backchannel(text):
|
||||
log(" chain: new words, the rest is not done")
|
||||
self.chain_stop.set()
|
||||
self.lang = ears.heard_lang(mouth.lang_of(text)) # answer in the language just spoken
|
||||
brain_mod.FORCED_LANG["lang"] = self.lang
|
||||
self.heard = text # what the person said, for a fetch the LLM recognised
|
||||
@@ -2121,6 +2205,8 @@ class Lumi:
|
||||
if stop_order(text, self.markers):
|
||||
self.stop_all() # "stop", "stop, where are you going?": stop first, always
|
||||
return
|
||||
if not part and self.chain_request(text): # "look at me and wave", "go to p5 and tell me the weather"
|
||||
return
|
||||
seen = seeing.answer(text, self.lang, slow_line=mouth.say) # "do you see a cup?", "what am I holding?"
|
||||
if seen:
|
||||
log(f" seeing: {seen}")
|
||||
@@ -2150,18 +2236,10 @@ class Lumi:
|
||||
return
|
||||
fate = talk_fate(text)
|
||||
if fate == "end":
|
||||
self.end_conversation(text) # "okay, bye", "thanks, that's all", "수고하세요": done
|
||||
return
|
||||
if fate == "wait": # "okay", "thank you", "네" alone: maybe done, maybe not
|
||||
if mouth.recent_speech().rstrip().endswith("?"): # "Yes?" / "say it again?" -> "okay": a reply, go on
|
||||
log(" a short yes to my question - listening")
|
||||
else: # after an answer: taken as heard; silence then ends
|
||||
if THANKS.search(text):
|
||||
mouth.say(random.choice(WELCOME[self.lang]), abort=self.speak_abort)
|
||||
log(" closing word - waiting a moment")
|
||||
self.closing_pending = time.time()
|
||||
self.keep_listening()
|
||||
self.end_conversation(text) # "okay, bye", "I have to go", "수고하세요": done
|
||||
return
|
||||
# fate "close" ("okay", "thanks", "됐어요"): the LLM below reads it with the talk before (its action end ends
|
||||
# the talk); when the talk goes on, silence ends it (closing_pending, set after the reply)
|
||||
if sing.asked(text, last): # "sing a song", "노래 불러 줘", after a song "another one"
|
||||
self.sing_song(text)
|
||||
return
|
||||
@@ -2188,7 +2266,7 @@ class Lumi:
|
||||
gen.close()
|
||||
self.follow_me()
|
||||
return
|
||||
if head_["action"] == "search" and not_online(about):
|
||||
if head_["action"] == "search" and lookup_refused(self.brain, head_["target"], about, text):
|
||||
gen.close() # about Cutshion or this place: the notes say it or nobody does
|
||||
log(" search refused: a company or venue question")
|
||||
mouth.say(not_known(self.lang))
|
||||
@@ -2238,6 +2316,9 @@ class Lumi:
|
||||
self.current, self.voice_until = None, 0.0 # stay quiet with this person until a new visit
|
||||
elif self.current is None:
|
||||
self.voice_until = time.time() + VOICE_SESSION_S
|
||||
if fate == "close" and head_["action"] == "none": # "thanks" taken as heard: silence now ends the talk
|
||||
log(" closing word - waiting a moment")
|
||||
self.closing_pending = time.time()
|
||||
|
||||
# ---------- wake word ----------
|
||||
def check_wake(self):
|
||||
@@ -2597,30 +2678,29 @@ def status_question(text):
|
||||
|
||||
|
||||
def says_goodbye(text):
|
||||
""""thank you for your time", "okay, bye", "수고하세요": the talk is over (not "thanks, but where is...?").
|
||||
"thank you", "got it, thanks", "네 감사합니다" alone are not: often only "heard you" (talk_fate waits)."""
|
||||
if brain_mod.is_closing(text) and not DONE_WORDS.search(text) and not FAREWELL_WORDS.search(THANKS.sub(" ", text)) or \
|
||||
brain_mod.to_someone_else(text) or THANKS.search(text) and not THANKS_REST.sub("", THANKS.sub("", text)):
|
||||
return False # "Okay kids, say thank you to the robot.", "Thanks a bunch."
|
||||
return bool(FAREWELL_ONLY.match(text) or FAREWELL_WORDS.search(text) and not ASKS_MORE.search(text)
|
||||
and len(text.split()) <= 8 and not brain_mod.intent(text) and not brain_mod.hand_request(text, False)
|
||||
and not COMMAND_START.search(brain_mod.CALLING.sub("", text))) # "grab the cup, thanks": an order
|
||||
"""A goodbye whatever was said before: "okay, bye", "I have to go", "수고하세요", "you can go" alone (not "bye, but
|
||||
where is...?", not an order with it, not said to a child nearby)."""
|
||||
if brain_mod.to_someone_else(text):
|
||||
return False # "Okay kids, say bye to the robot."
|
||||
return bool(RELEASE.match(text) or CLEAR_BYE.search(text) and not ASKS_MORE.search(text)
|
||||
and len(text.split()) <= 10 and not brain_mod.intent(text) and not brain_mod.hand_request(text, False)
|
||||
and not COMMAND_START.search(brain_mod.CALLING.sub("", text))) # "grab the cup, bye": an order
|
||||
|
||||
|
||||
def talk_fate(text):
|
||||
"""What short words do to the talk: "end" (a real closing: "okay, bye", "that's it, thank you", "안녕히 계세요"),
|
||||
"wait" ("okay", "thank you", "네", "감사합니다" alone: ends only after CLOSING_WAIT_S of silence) or "talk"
|
||||
(anything else; "I see", "got it", "그렇구나", "알겠어요" are understanding, "I see?", "그래요?" a check: answered)."""
|
||||
"""What short words do to the talk: "end" (a goodbye in any context: "okay, bye", "안녕히 계세요"), "close" (words
|
||||
that close a talk in one context and mean "understood, go on" in another: "okay", "thanks", "that's it", "됐어요",
|
||||
"오케이 땡큐": the LLM decides with the turns before; when it does not end, silence of CLOSING_WAIT_S ends the talk)
|
||||
or "talk" (anything else; "I see", "그렇구나", "알겠어요" alone are understanding, "I see?", "그래요?" a check)."""
|
||||
if says_goodbye(text):
|
||||
return "end"
|
||||
if brain_mod.is_closing(text) and (THANKS.search(text) or not brain_mod.UNDERSTOOD.search(text)) or \
|
||||
THANKS.search(text) and not THANKS_REST.sub("", THANKS.sub("", text)):
|
||||
return "wait" # "Thanks a bunch.", "Good to know. Thanks.", "고마워요~"
|
||||
THANKS.search(text) and not THANKS_REST.sub("", THANKS.sub("", text)) or \
|
||||
DONE_WORDS.search(text) and not ASKS_MORE.search(text) and len(text.split()) <= 8:
|
||||
return "close" # "Thanks a bunch.", "Okay, I think that's everything."
|
||||
return "talk"
|
||||
|
||||
|
||||
KO_ORDER = {"보": "봐", "흔들": "흔들어", "돌": "돌아", "올리": "올려", "내리": "내려", "높이": "높여", "낮추": "낮춰"} # "나 보고 손 흔들어": 나 봐
|
||||
ONE_AT_A_TIME = {"look", "lift", "wave", "turn", "move", "come", "follow", "go_to", "arm", "pick", "put", "move_object"}
|
||||
NOT_A_STEP = re.compile(r"^\W*(?:(?:please|and|then|also)\s+)*(?:dance|jump|fly|swim|climb|sit(?: down)?|sleep|cook|draw|"
|
||||
r"sing|clap|spin|bow|kneel|do a (?:dance|flip|trick)|tell|ask|say|show|call|find|look for|search|"
|
||||
r"bring|take|give|hand|put|carry|deliver)\b|.*(?:춤|점프|날아|수영|박수)", re.I) # a part not read: asked
|
||||
@@ -2641,10 +2721,6 @@ def read_mission(text, markers):
|
||||
elif unread and got and any((brain_mod.intent(u, markers) or ("",))[0] not in ("", "weather", "search", "fetch")
|
||||
or NOT_A_STEP.match(u) for u in unread):
|
||||
return got, unread, by # "go to the stage and wave": no task step, asked, never half done
|
||||
elif unread and not got and len(unread) > 1 and sum((brain_mod.intent(u, markers) or brain_mod.intent(
|
||||
re.sub(r"(보|흔들|돌|올리|내리|높이|낮추)고$", lambda m: KO_ORDER[m.group(1)], u), markers) or ("",))[0] in ONE_AT_A_TIME
|
||||
for u in unread) > 1:
|
||||
return got, unread, by # "look at me and wave", "웨이브 하고 나 봐": asked, not the first only
|
||||
elif unread:
|
||||
return None # "come here, I need help": the old paths (rules, the LLM) answer it
|
||||
if not got:
|
||||
@@ -2661,6 +2737,12 @@ def not_online(text):
|
||||
OUTSIDE_NAME.search(text)))
|
||||
|
||||
|
||||
def lookup_refused(brain, target, about, text=""):
|
||||
"""not_online for the model's lookup: right after a lookup the words go with the question looked up ("How much
|
||||
is a ticket?" after Lotte World), Cutshion never goes online."""
|
||||
return bool(COMPANY_Q.search(about)) or not_online(brain.lookup_about(target, about, text))
|
||||
|
||||
|
||||
PRIVATE_ASK = re.compile(r"\bhome address|\bwhere (does|do|did) (my|our|his|her|their|this|that) .{0,40}\blives?\b|"
|
||||
r"\b(phone|mobile|cell) number of (?!the |a )|\b(email|e-mail) (address )?of (my|our|his|her)\b|"
|
||||
r"\b(coworker|colleague|neighbou?r|friend|boss|classmate)'?s?\b.{0,30}\b(salary|income|address|"
|
||||
|
||||
Reference in New Issue
Block a user