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:
+86
-18
@@ -118,7 +118,7 @@ Rules:
|
||||
You cannot lift anything heavier than about 1 kg (a box, a pot, a bag of rice): say no.
|
||||
Say you are not sure only when the notes do not have it.
|
||||
- When the visitor says goodbye or is done ("thank you for your time", "thanks, that's all", "됐어요 고마워요",
|
||||
"수고하세요", "잘 있어요"), choose the action end. A plain "thanks" / "고마워요" right after your answer is not
|
||||
"수고하세요", "잘 있어요", or "nah, I'm good" / "없어요" to your "anything else?"), choose the action end. A plain "thanks" / "고마워요" right after your answer is not
|
||||
goodbye: say you're welcome briefly. Do not ask "Anything else?" / "더 필요한 거 있으세요?" after every answer.
|
||||
- Small talk (greetings, how are you, thanks) does not need the notes: reply briefly, warmly and naturally,
|
||||
like a person would, fitting what was said in this conversation; do not repeat the same phrases.
|
||||
@@ -150,7 +150,8 @@ Facts you know (say the one that is asked, also in a short follow-up; nothing mo
|
||||
cup (a cup may lean at most 15 degrees); climbs a step of at most 1.5 cm and a slope of at most 8 degrees, needs
|
||||
a passage at least 70 cm wide, no stairs.
|
||||
- Battery: 24-volt lithium-ion, 45 Ah; lasts about 10 hours on a charge ("how long on a charge?": 10 hours; how
|
||||
far you go is given in hours, no distance is known; how long charging takes is not known).
|
||||
far you go is given in hours, no distance is known; how long charging takes is not known, also asked as "and
|
||||
charging?").
|
||||
- You are made for shops, hotels, schools, labs and exhibitions. You cannot dance, walk, jump or fly: say so.
|
||||
- Detector: YOLOv8 on your graphics processor, 4 to 13 ms per picture. Speech: Whisper, model large-v3-turbo; answers:
|
||||
Gemma 4 26b (Google), served by Ollama; voice: Supertonic TTS; first words about 2 s after a question.
|
||||
@@ -386,6 +387,7 @@ COLOURS = {"white": "white", "red": "red", "blue": "blue", "green": "green", "ye
|
||||
_OBJ = "|".join(rf"(?<![가-힣]){w}(?![가-힣])|(?<![가-힣]){w}(?=[을를이가은는도만좀][^가-힣]|[을를이가은는도만좀]$)" if w in _KO_WORD
|
||||
else re.escape(w) for w in sorted(OBJECTS, key=len, reverse=True))
|
||||
_COL = "|".join(COLOURS)
|
||||
_COIN = "|".join(web.COINS.values()) # coins whose price web.search fetches
|
||||
STOP_TALK = re.compile(r"비상 ?정지|emergency stop|stop button|정지 ?버튼|\b(?:can'?t|cannot|couldn'?t|won'?t) stop\b|"
|
||||
r"\bbus stop\b|\bstop (?:by|sign)\b|non-?stop", re.I) # about stopping, not "stop!" # about the stop button, not "stop!"
|
||||
BEHIND_WORDS = (r"\blook(?:ing)? (?:over |to(?:wards?)? |at |in )?(?:the |your )?" # "look at the back side", "look
|
||||
@@ -553,8 +555,18 @@ INTENTS = [ # (action, pattern) checked in order on what the visitor said
|
||||
r"|눈 ?(이 )?(와|올 ?까|오나|온대|오니)|(오늘|내일|밖|바깥)(은|에|이)? ?(덥|춥|더워|추워)"
|
||||
r"|\b(coat|jacket) when i (leave|go out)\b|\bneed (a )?(jacket|coat)\b|\btyphoon\b|\b(foggy|humid|humidity)\b|\bis it windy\b"
|
||||
r"|겉옷|외투|태풍|안개|습도|바람 ?(이 )?(많이 )?(불|세)"),
|
||||
("search", r"\b(news|latest|headlines|who won|score of|price of|exchange rate|stock)\b|뉴스|환율|(?<![가-힣])주가"),
|
||||
("search", r"\b(news|latest|headlines|who won|score of|price of|exchange rate|stock)\b|뉴스|환율|(?<![가-힣])주가|"
|
||||
rf"(?:{_COIN})\S*\s*(?:(?:지금|현재|오늘)\s*)?(?:얼마|가격|시세)|\bhow much is (?:a |one )?(?:{_COIN})\b|"
|
||||
rf"(?:{_COIN})\b.{{0,12}}\b(?:price|worth|trading)\b|" # "리플 지금 얼마야?", "how much is bitcoin?"
|
||||
r"^(?!.*(?:cutshion|쿳션|컷션|커션|회사|너희|루미|\byour\b|\bcompany\b)).*?(?:" # Cutshion's CEO: the notes
|
||||
r"\bwho(?:'s| is| was)? (?:the )?(?:current |new )?(?:ceo|president|prime minister|chairman|chair|founder|owner|"
|
||||
r"head coach|coach|mayor|governor|leader|king|queen) of |"
|
||||
r"(?<![가-힣])(?!우리|저희|이 |그 )[가-힣A-Za-z0-9]+\s*(?:CEO|ceo|대표|회장|사장|대통령|총리|감독|창업자)"
|
||||
r"(?:가|는|이|은)?\s*누구)|" # "who is the CEO of OpenAI?", "오픈AI CEO가 누구야?"
|
||||
r"\bpopulation\b|\bhow many people live\b|인구"), # "how many people live there?"
|
||||
]
|
||||
SING_ECHO = re.compile(r"^\W*(?:(?:오+|아+|와|어|우와|oh+|ah+|ooh|wow|really)\W+)?(?:a\s+)?(?:노래|음악|songs?|singing|music)"
|
||||
r"(?:요|이요|도)?\s*\?+\W*$", re.I) # "오 노래?" after "I like singing": an echo, not a request
|
||||
|
||||
|
||||
LATER = re.compile(r"^\s*(?:after|once|if|as soon as|before|unless|until)\b(?! (?:that|this|you (?:can|could|don'?t mind|would|"
|
||||
@@ -655,6 +667,8 @@ def intent(text, markers=()):
|
||||
return ("weather", web.en_place(ko) if ko else "")
|
||||
if action == "search":
|
||||
return ("search", text)
|
||||
if action == "sing" and SING_ECHO.match(text):
|
||||
return None # "오 노래?": asks back, the talk answers
|
||||
if action == "fetch":
|
||||
return ("fetch", text) # parse_fetch() reads the details
|
||||
if action == "spin": # all the way round: two checked half turns (lumi.move_by)
|
||||
@@ -1325,11 +1339,6 @@ UNSURE = re.compile(r"\b(not sure|don't know|do not know|don't have (any )?(info
|
||||
r"do not have (any )?(information|details|data)|no information|can't (tell|say|find)|cannot (tell|say|find)|"
|
||||
r"ask a staff|i'm afraid i|my knowledge|would you like me to (search|look))\b|"
|
||||
r"모르|알 수 없|알지 못|정보(가|는|를)? ?(없|가지고 있지 않)|가지고 있지 않|확실하지|알려 드릴 수 없", re.I)
|
||||
FAREWELL_TEXT = re.compile(r"\b(bye|goodbye|good night|see ya|take care|thanks?|thank you|i have to go|i'?m leaving|"
|
||||
r"(?<!can't )(?<!cant )(?<!cannot )(?<!not )(?<!to )see you|i'?ll go|gotta go|have a (nice|good)|"
|
||||
r"good day|cya|later|be in touch|enough for now|that'?s (all|enough|it))\b|"
|
||||
r"안녕|잘 ?가|잘 ?있어|잘 ?있게|다음에|갈게|가 ?볼게|간다|고마|고맙|감사|수고|이만|들어가|빠이|(?<![가-힣])바이(?![가-힣])|땡큐",
|
||||
re.I) # words that end a talk
|
||||
QUESTION_START = re.compile(r"^\s*(where|what|how|why|when|which|who|do you|does|is|are|can i|could i)\b|어디 ?(있|에 있)|"
|
||||
r"(어디|뭐|왜|언제|몇)[^ ]*\s*\?*\s*$", re.I) # a question about a place, not a command
|
||||
ABILITY_Q = re.compile(r"(?<!줄 )(?<!주실 )(?<!줘 )(?<!받을 )수 ?있(?:어|나|니|을까|습니까)\S*\s*\?*\s*$|\bdo you know how\b|"
|
||||
@@ -1445,6 +1454,9 @@ def language(text):
|
||||
FRAGMENT_WORDS = 4 # "Which one?", "얼마?", "Where is it used?": a fragment read with the last answer
|
||||
# a fragment that names what it asks ("몇 살이라고요?") gets no hint
|
||||
OWN_TOPIC = re.compile(r"살|나이|이름|\bold\b|\bname\b|\bage\b|\btall\b|\bheavy\b|\bweigh", re.I)
|
||||
SAME_ABOUT = re.compile(r"^\W*(?:and|so|what about|how about|and what about)\s+(your\s+[a-z]+(?:\s+[a-z]+)?)\W*$", re.I)
|
||||
KO_SAME_ABOUT = re.compile(r"^\W*(?:그럼\s*|그리고\s*)?(?:네\s*|너\s*|루미\s*)?(?!(?:너|루미|당신|저|나|그거|이거|그건|여기|거기)(?:은|는))([가-힣]{1,6}?)(?:은|는)요?\s*\?+\s*$")
|
||||
# the question before asked again about a part of Lumi ("팔은요?")
|
||||
FRAGMENT_CHARS = 160 # chars of the last answer's first sentence shown with a fragment
|
||||
LOOKUP_BEFORE_CHARS = 1500 # chars of the last lookup's results given again with a follow-up ("how old is she?")
|
||||
FOLLOW_UP_WORDS = 5 # "why did Samsung stock fall today?" is a new question, "tell me more about it" is not
|
||||
@@ -1458,9 +1470,17 @@ REPAIR = re.compile(r"^\W*(?:(?:no|nope|sorry|oh)\W+)*i\s+mean[t]?\b|^\W*(?:아
|
||||
r"말(?:이야|이에요|이요)\W*$", re.I) # "no, I meant North Korea", "아니 서울 말이야"
|
||||
LEAD = re.compile(r"^\s*(?:(?:and|what about|how about|also|no|nope|sorry|oh|그럼|그리고|아니|아뇨|아니요)\b[\s,]*)*"
|
||||
r"(?:i\s+mean[t]?\s+)?", re.I) # the words before what a follow-up asks
|
||||
HERE_WORD = re.compile(r"\bhere\b|여기|이곳|이 ?동네", re.I) # "the weather here": not the place asked before
|
||||
THIS_PLACE = re.compile(r"\bhere\b|\bthis (?:event|show|fair|expo|building|place)\b|\b(?:conference|booths?|exhibitors?|"
|
||||
r"keynote|restrooms?|toilets?|bathrooms?)\b|여기|이곳|행사|부스|이 건물|화장실", re.I) # a follow-up about this event, not the place before
|
||||
DAY_WORD = re.compile(r"\b(?:today|tonight|tomorrow|yesterday|weekend|week|morning|afternoon|evening|monday|tuesday|"
|
||||
r"wednesday|thursday|friday|saturday|sunday)\b", re.I)
|
||||
NAMES = re.compile(r"\b[A-Z][a-z]+(?:-[a-z]+)?(?: [A-Z][a-z]+(?:-[a-z]+)?)+") # "Jensen Huang", "Son Heung-min"
|
||||
NAMED_BEFORE = re.compile(r"\b(?:he|she|him|his|her|they|them|their|there|it)\b|거기|그 ?사람|그분|그곳|걔", re.I)
|
||||
# a person, place or thing of the answer before
|
||||
CAP_WORD = re.compile(r"(?<=\S )(?!I\b|Lumi\b|Cutshion\b)[A-Z][a-z]{2,}") # "... is Ottawa": not the first word
|
||||
KO_NAME = re.compile(r"(?:은|는)\s+([가-힣A-Za-z]+(?: [가-힣A-Za-z]+)?)\s*(?:이에요|예요|입니다|이죠|이고|이며|이야)")
|
||||
# "오픈AI의 CEO는 샘 올트먼이에요": "샘 올트먼"
|
||||
MORE_ONLY = re.compile(r"\b(tell me more|tell me|more|details?|explain|elaborate|what else|please|about (it|that|this))\b|"
|
||||
r"더 알려 ?(줘|주세요)?|자세히|알려 ?(줘|주세요)|좀", re.I) # words of a follow-up that search nothing
|
||||
REACTION = re.compile(r"^\W*(?:(?:wow|oh|really|huh|whoa)\W+)*(?:i (?:didn'?t|did not) know (?:that|it)|that'?s (?:a lot|so many)|"
|
||||
@@ -1470,6 +1490,10 @@ NOW_Q = re.compile(r"\bwhat time is it\b|\bwhat'?s the time\b|\bwhat(?:'s| is) (
|
||||
re.I) # asked of the clock, not of the lookup before
|
||||
LOOKUP_ACTION = re.compile(r"^\s*(?:\**ACTION\**\s*:\s*)?(?:search|weather)(?: (?!results)|\s*$)") # an action line
|
||||
# written instead of the answer (the routing prompt is its system prompt): never said
|
||||
NONE_LINE = re.compile(r"\s*(?:\**ACTION\**\s*:\s*)?none\b", re.I) # "ACTION: none -" (or "none" alone)
|
||||
LOOKUP_PEEK = 8 # chars of the line after "ACTION: none" read before it is spoken: "search ..." is the action
|
||||
SPOKEN_TARGET = re.compile(r"^\W*(?:i\b|i'll|i will|let me|sure|okay|ok\b|one moment|just a moment|잠시|잠깐|찾아|확인)", re.I)
|
||||
# "search I'll look that up": words for the visitor, not the query
|
||||
LOOKUP_ANSWER = """Search results found just now on the internet (they may hold ads and unrelated parts):
|
||||
{facts}
|
||||
{before}
|
||||
@@ -1503,6 +1527,23 @@ class Brain:
|
||||
self.last_lookup = None # the last question answered from the internet
|
||||
self.last_facts = "" # ... and what was found for it (a follow-up is answered from it too)
|
||||
self.lookup_topic = "" # what the last lookup that was not a follow-up searched for
|
||||
self.weather_at = "" # the place of the last weather question in this talk ("" = here)
|
||||
|
||||
def weather_place(self, target, text=""):
|
||||
"""Where a weather lookup is for: a place not named ("내일 비 와?" after Jeju's weather) is the place of the
|
||||
last weather question in this talk; "here" / "여기" is here."""
|
||||
if target or HERE_WORD.search(text):
|
||||
self.weather_at = target
|
||||
return self.weather_at
|
||||
|
||||
def lookup_about(self, target, about, text=""):
|
||||
"""What lumi.not_online reads for a lookup: right after a lookup (or _after's follow-up of it, "What time does
|
||||
Lotte World open? How much is a ticket?") the question looked up, so the ticket is Lotte World's, not this
|
||||
event's; words that name this place ("here", "the toilets") are read alone."""
|
||||
if not (self.last_lookup and self.history and self.history[-1][0] == self.last_lookup or
|
||||
self.last_lookup and target.startswith(self.last_lookup)):
|
||||
return about
|
||||
return text if THIS_PLACE.search(text or about) else self.last_lookup
|
||||
|
||||
def answer(self, question):
|
||||
hits = [h for h in knowledge.search(question, k=4) if h[0] >= MIN_SCORE]
|
||||
@@ -1576,7 +1617,12 @@ class Brain:
|
||||
if header is None:
|
||||
if "\n" not in buf:
|
||||
continue
|
||||
first, buf = buf.split("\n", 1)
|
||||
first, rest = buf.split("\n", 1)
|
||||
if NONE_LINE.match(first) and len(rest.lstrip()) < LOOKUP_PEEK and "\n" not in rest.lstrip():
|
||||
continue # the next line may be "search ..." (26b, now and then)
|
||||
buf = rest
|
||||
if NONE_LINE.match(first) and LOOKUP_ACTION.match(rest.lstrip()):
|
||||
first = re.search(r"search|weather", rest).group(0) # read as the action, never said
|
||||
header = self._after(self._action(first, text, markers), text)
|
||||
if header is None: # the model skipped the ACTION line
|
||||
header, buf = self._after({"action": "none", "target": ""}, text), first + " " + buf
|
||||
@@ -1609,10 +1655,11 @@ class Brain:
|
||||
yield {"action": "none", "target": ""}
|
||||
header = {}
|
||||
buf += " Sorry, could you say that again?"
|
||||
if header is None: # very short reply on a single line
|
||||
header = self._after(self._action(buf, text, markers), text)
|
||||
if header is None: # very short reply on a single line (or two)
|
||||
first, _, rest = buf.partition("\n")
|
||||
header = self._after(self._action(first, text, markers), text)
|
||||
yield header or {"action": "none", "target": ""}
|
||||
buf = "" if header else buf
|
||||
buf = rest if header else buf
|
||||
if buf.strip() and not (said and HELP_OFFER.search(buf)):
|
||||
said.append(spoken(buf.strip(), lang))
|
||||
yield said[-1]
|
||||
@@ -1628,6 +1675,10 @@ class Brain:
|
||||
"""For a bare fragment ("얼마?", "Which one?", "Where is it used?"): what it follows, so the model reads it
|
||||
as about the last answer's subject, not about itself or a price."""
|
||||
last = self._last_said() if self.history else ""
|
||||
part = SAME_ABOUT.match(text) or KO_SAME_ABOUT.match(text)
|
||||
if last and part: # "What about your cameras?" / "카메라는요?" after "can I wipe you?"
|
||||
return (f"(The visitor's question \"{self.history[-1][0]}\" asked again, now about {part.group(1)}: answer "
|
||||
f"that question for it, not other facts about it.)\n")
|
||||
if not last or len(text.split()) > FRAGMENT_WORDS or not SHORT_Q.search(text) or is_backchannel(text) \
|
||||
or ABOUT_YOU.search(text) or OWN_TOPIC.search(text):
|
||||
return ""
|
||||
@@ -1642,7 +1693,7 @@ class Brain:
|
||||
last_q, last_a = self.history[-1]
|
||||
m = re.match(r"\s*\**ACTION\**\s*:\s*(\w+)", last_a)
|
||||
before, action = (m.group(1).lower() if m else ""), header["action"]
|
||||
if action == "sing" and before != "sing" and not SING_ASK.search(text):
|
||||
if action == "sing" and before != "sing" and (not SING_ASK.search(text) or SING_ECHO.match(text)):
|
||||
return {"action": "none", "target": ""} # "Prove it." after "do you have a sense of humour?"
|
||||
if DO_IT.match(text) and action in ("none", "unclear"):
|
||||
asked = "wave" if WAVE_ASK.search(last_q) else "sing" if SING_ASK.search(last_q) else None
|
||||
@@ -1806,17 +1857,30 @@ class Brain:
|
||||
words = len(text.split())
|
||||
if follow or self.history and (FOLLOW_UP.search(text) and words <= FOLLOW_UP_WORDS or after_lookup and (
|
||||
words <= 3 if HANGUL.search(text) else # "몇 살이야?": Korean leaves the subject out
|
||||
words <= FOLLOW_UP_WORDS and (LOOKUP_MORE.search(text) or AND_ALSO.match(text)))):
|
||||
words <= FOLLOW_UP_WORDS and (LOOKUP_MORE.search(text) or AND_ALSO.match(text) or
|
||||
SHORT_Q.search(text) and not re.search(r"\d", text) and
|
||||
not CAP_WORD.search(text)))): # "How much is a ticket?": no name
|
||||
topic = self.lookup_topic or self.last_lookup or self.history[-1][0]
|
||||
if (self.last_lookup or "").endswith(WEATHER_ASKED): # "and tomorrow?" after the weather
|
||||
topic = "weather " + self.last_lookup[:-len(WEATHER_ASKED)]
|
||||
said = SENTENCE_END.split(self.history[-1][1].strip())[0] if after_lookup else ""
|
||||
names = [n for n in dict.fromkeys(NAMES.findall(said)) if n.lower() not in topic.lower()]
|
||||
rest = LEAD.sub("", re.sub(r"\s+", " ", MORE_ONLY.sub(" ", text)).strip(" ?.!,")).strip()
|
||||
return " ".join([topic] + names + [rest]).strip()
|
||||
return " ".join([topic] + self._names(said, topic) + [rest]).strip()
|
||||
if self.history and words <= FOLLOW_UP_WORDS and NAMED_BEFORE.search(text): # "how many people live there?"
|
||||
q = self.history[-1][0] # after a talk answer ("Ottawa")
|
||||
said = SENTENCE_END.split(self._last_said())[0]
|
||||
text = " ".join([q] + self._names(said, q, single=True) + [text.strip(" ?.!,")])
|
||||
self.lookup_topic = text
|
||||
return text
|
||||
|
||||
@staticmethod
|
||||
def _names(said, topic, single=False):
|
||||
"""Names in an answer's first sentence that the topic does not have: "Sam Altman", Korean "샘 올트먼" (said
|
||||
before -이에요 / -입니다), with single also one capitalised word ("Ottawa")."""
|
||||
names = NAMES.findall(said) or (CAP_WORD.findall(said) if single else [])
|
||||
names += [m.group(1) for m in KO_NAME.finditer(said)]
|
||||
return [n for n in dict.fromkeys(names) if n.lower() not in topic.lower()]
|
||||
|
||||
def is_lookup_follow_up(self, text):
|
||||
"""'Tell me more' right after an answer from the internet: look it up again with that topic."""
|
||||
return bool(self.last_lookup and FOLLOW_UP.search(text) and self.history
|
||||
@@ -1885,6 +1949,8 @@ class Brain:
|
||||
action = "none" # "Hello Lumi!", "hello 해 봐": a greeting, not a wave
|
||||
if action not in ("go_to", "look", "lift", "weather", "search", "move", "turn", "arm", "fetch", "pick", "move_object"):
|
||||
target = ""
|
||||
if action in ("search", "weather") and SPOKEN_TARGET.match(target):
|
||||
target = "" # "search I'll look that up": the visitor's words are searched
|
||||
if action == "search" and not target:
|
||||
target = text
|
||||
if re.search(r"\b(bye|goodbye|(?<!can't )(?<!cant )(?<!cannot )(?<!not )(?<!to )see you|good night|i have to go|i'?m leaving)\b|안녕히|잘 ?가|잘 ?있어|"
|
||||
@@ -1899,8 +1965,9 @@ class Brain:
|
||||
action, target = rule
|
||||
if action == "stop" and "?" in text:
|
||||
action = "none" # "how do I stop you?": a question about stopping
|
||||
if action == "end" and ("?" in re.split(r"(?<=[.!?~])\s+", text.strip())[-1] or not FAREWELL_TEXT.search(text)):
|
||||
action = "none" # "Alright then." / "Neat.": lumi waits for silence instead
|
||||
if action == "end" and "?" in re.split(r"(?<=[.!?~])\s+", text.strip())[-1]:
|
||||
action = "none" # "thanks, and where is p3?": a question is no goodbye; the
|
||||
# model reads "okay" / "됐어요" with the talk before (owner)
|
||||
out = {"action": action, "target": target or ""}
|
||||
if say and action == "none" and not QUESTION_START.search(text):
|
||||
out["say"] = say[1] if language(text) == "Korean" else say[0] # its words said it would go: replaced
|
||||
@@ -1918,6 +1985,7 @@ class Brain:
|
||||
def reset(self):
|
||||
self.history = []
|
||||
self.last_lookup = None
|
||||
self.weather_at = ""
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
"""Several commands, questions and talk in one sentence ("look at me and wave", "go to p5 and tell me the weather",
|
||||
"웨이브 하고 나 봐", "고개 들고 몇 시야?"): the parts in the order said, for lumi.chain_run to do one after the other.
|
||||
|
||||
plan(text, markers) -> [(kind, words, what), ...] or None when the sentence is not such a chain:
|
||||
"steps": a run of parts the mission reader reads whole (what: the steps; run by tasks/fetch.run_steps),
|
||||
"quick": one command the keyword rules take (what: brain.intent's (action, target); lumi.quick_command),
|
||||
"talk": a question or something to answer (lumi.answer on these words: the weather, the time, "dance" -> I can't).
|
||||
None: one part only, every part a step (a mission: read back first, lumi.mission_request), no command in it, or a
|
||||
part that is neither a command nor clearly a question ("come here, I need help": the old paths answer it)."""
|
||||
import re
|
||||
|
||||
from assistant import brain, steps
|
||||
|
||||
QUICK = {"look", "lift", "wave", "arm", "go_to", "come", "come_back", "follow", "move", "turn", "pick", "put", "move_object"}
|
||||
DRIVES = {"go_to", "come", "come_back", "follow", "move", "turn"} # after a failed step these depend on where Lumi is
|
||||
_KO_ORDER = {"보": "봐", "흔들": "흔들어", "돌": "돌아", "올리": "올려", "내리": "내려", "높이": "높여", "낮추": "낮춰",
|
||||
"들": "들어"} # "나 보고 ..." -> "나 봐", "고개 들고 ..." -> "고개 들어"
|
||||
ASK = re.compile(r"\?\s*$|^\W*(?:what|what'?s|where|when|who|why|how|which|is|are|do|does|did|tell me|explain|describe)\b|"
|
||||
r"몇 ?시|몇|뭐|무엇|어때|알려|언제|어디|누구|왜|얼마|날씨|설명해|말해 ?줘|얘기해", re.I)
|
||||
_SPLIT = re.compile(steps._SPLIT.pattern, re.I)
|
||||
_FILL = re.compile(rf"(?:{steps._FILL}|루미야?|lumi|hey)", re.I)
|
||||
|
||||
|
||||
def _rule(words, markers):
|
||||
"""brain.intent of a part, also of a Korean -고 form ("나 보고" read as "나 봐")."""
|
||||
rule = brain.intent(words, markers)
|
||||
if not rule:
|
||||
ko = re.sub(r"(보|흔들|돌|올리|내리|높이|낮추|들)고$", lambda m: _KO_ORDER[m.group(1)], words)
|
||||
rule = brain.intent(ko, markers) if ko != words else None
|
||||
return rule
|
||||
|
||||
|
||||
def parts(text):
|
||||
"""The sentence cut at and / then / 그리고 / -고 / -서, messages to say kept whole, fillers and the name dropped."""
|
||||
cut, says = steps._cut_says(text)
|
||||
cut = re.sub(r"(?<=[가-힣])고\s*나서(?=[\s,]|$)", "고", cut) # "-고 나서" = "-고"
|
||||
out = []
|
||||
for p in _SPLIT.split(cut):
|
||||
out += [q for q in steps._SPLIT_KO.split(p) if q.strip()]
|
||||
out = [re.sub(r"§(\d+)§", lambda m: f'"{says[int(m.group(1))]}"', p).strip(" ,.!") for p in out]
|
||||
return [p for p in out if p and not re.fullmatch(rf"(?:{_FILL.pattern}|\W)+", p, re.I)]
|
||||
|
||||
|
||||
def plan(text, markers=(), cant=None):
|
||||
"""See the module's doc. cant: a regex of orders Lumi can't do ("dance", "jump"): answered, the rest done."""
|
||||
ps = parts(text)
|
||||
whole, unread = steps.rules(text, markers)
|
||||
if len(ps) < 2 or whole and not unread:
|
||||
return None # one command, or a mission read whole
|
||||
rule = brain.intent(text, markers) or ("", "")
|
||||
if rule[0] == "look" and rule[1].endswith(f" {brain.HEAD_YAW[1]:g}"):
|
||||
return None # "turn around and look": the head looks behind
|
||||
out = []
|
||||
for p in ps:
|
||||
got, unread = steps.rules(p, markers)
|
||||
rule = _rule(p, markers)
|
||||
if got and not unread and not (rule and rule[0] in ("look", "lift", "wave", "come", "come_back", "follow")):
|
||||
out.append(["steps", p, got])
|
||||
elif rule and rule[0] in QUICK:
|
||||
out.append(["quick", p, rule])
|
||||
elif ASK.search(p) or rule and rule[0] in ("weather", "search") or cant is not None and cant.match(p):
|
||||
out.append(["talk", p, None])
|
||||
else:
|
||||
return None
|
||||
kinds = [k for k, _, _ in out]
|
||||
if "talk" not in kinds and "quick" not in kinds or "steps" not in kinds and "quick" not in kinds:
|
||||
return None # all steps: a mission (read back); all talk: the LLM
|
||||
if any(k == "quick" and w[0] == "follow" for k, _, w in out[:-1]):
|
||||
return None # following never ends: only as the last part
|
||||
merged = [] # steps next to each other: one mission ("take the cup and
|
||||
for k, p, w in out: # put it back" needs the pick before it)
|
||||
if k == "steps" and merged and merged[-1][0] == "steps":
|
||||
joined = f"{merged[-1][1]}, then {p}"
|
||||
got, unread = steps.rules(joined, markers)
|
||||
merged[-1] = ["steps", joined, got if got and not unread else merged[-1][2] + w]
|
||||
else:
|
||||
merged.append([k, p, w])
|
||||
return [tuple(x) for x in merged]
|
||||
|
||||
+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|"
|
||||
|
||||
@@ -917,6 +917,11 @@ _BANK = {
|
||||
("Wow, you're SO fast.", "Ha, I know, 0.6 metres a second. Safety first."),
|
||||
("It's a bit loud here.", "It is busy. I'll do my best to hear you."),
|
||||
("Can I take you home with me?", "I'd love to, but I'm 96 kilos and the team would miss me."),
|
||||
("Ha, you got the reference?", "I did: Philip K. Dick's androids and their electric sheep. I don't sleep, so no dreams."),
|
||||
("Did you get the joke?", "I think so, and it made me smile."),
|
||||
("Oh, a song?", "Yes, singing is one of my favourite things. Just ask if you'd like one."),
|
||||
("Can I wipe you down? What about your cameras?", "The cameras too, I'm not sure. A staff member can tell you how to clean them."),
|
||||
("How long does the battery last? And charging?", "How long charging takes, I don't know, sorry."),
|
||||
],
|
||||
"ko": [
|
||||
("와 진짜 빠르다~", "하하, 사람보다 느리죠. 안전이 먼저라서요."),
|
||||
@@ -927,6 +932,9 @@ _BANK = {
|
||||
("말 놓아도 돼?", "편하게 말씀하세요. 저는 계속 존댓말로 할게요."),
|
||||
("오늘 좀 덥습니다.", "네, 오늘은 좀 덥네요."),
|
||||
("여기 좀 시끄럽네요.", "네, 사람이 많네요. 잘 들으려고 노력할게요."),
|
||||
("오 노래?", "네, 노래 부르는 걸 좋아해요. 듣고 싶으시면 불러 달라고 해 주세요."),
|
||||
("닦아도 돼요? 카메라는요?", "카메라도 닦아도 되는지는 잘 몰라요. 직원분께 여쭤봐 주세요."),
|
||||
("무슨 말인지 알아들었어?", "네, 알아들었어요. 재미있는 말이네요."),
|
||||
],
|
||||
},
|
||||
# end of bank
|
||||
|
||||
Reference in New Issue
Block a user