Weather follow-ups keep the topic and place and move the day (tomorrow, next Monday, 모레, the weekend); only the asked days reach the model; one "Let me check"
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
"""Weather talks of several turns (English, Korean, mixed): a follow-up keeps the topic and the place and moves the
|
||||
day ("and tomorrow?", "모레는요?", "next Monday?", "what about Busan?", "the weather then?" after a date answer); a
|
||||
day past or beyond the 7-day forecast is said plainly. Checked without the internet or the LLM, on a fake forecast
|
||||
with today fixed (Friday 23 October 2026): the route lumi.answer() takes (keyword rule, else brain._after on the
|
||||
model's "none" or "search"), the place, the days (web.asked_day: 0 today, 1 Saturday ... 6 Thursday) and the forecast
|
||||
lines the answer is made from. python tests/dialogues_weather.py (also run by tests/test_web.py)
|
||||
|
||||
W(text, place, days): a weather lookup at `place` ("" = here, Seoul) for `days` (None = the whole forecast).
|
||||
S(text, said): a turn answered by talk (the model's own answer, e.g. a date). N(text): not a weather lookup.
|
||||
"""
|
||||
import datetime
|
||||
|
||||
from assistant import brain, web
|
||||
|
||||
TODAY = datetime.date(2026, 10, 23) # a Friday
|
||||
MARKS = ["home", "dock2", "p1", "p2"]
|
||||
|
||||
|
||||
def W(text, place, days, llm="none"):
|
||||
return {"text": text, "place": place, "days": days, "llm": llm}
|
||||
|
||||
|
||||
def S(text, said):
|
||||
return {"text": text, "said": said}
|
||||
|
||||
|
||||
def N(text):
|
||||
return {"text": text, "place": None}
|
||||
|
||||
|
||||
FAR, PAST = "too far ahead", "already past"
|
||||
DIALOGUES = [
|
||||
# the owner's talk of 2026-10-23 15:37 (logs/lumi.log), Korean and English
|
||||
[W("오늘 날씨 어때요?", "", [0]), W("내일 어때요?", "", [1], "search"), W("다음 주 월요일 어때요?", "", [3], "search"),
|
||||
W("날씨 어때요?", "", [3])],
|
||||
[W("How is the weather today?", "", [0]), W("And tomorrow?", "", [1]), W("What about next week Monday?", "", [3]),
|
||||
W("And the weather?", "", [3])],
|
||||
# a date answered first, then "the weather then?"
|
||||
[S("What date is next Monday?", "Next Monday is the 26th of October."), W("And the weather then?", "", [3])],
|
||||
[S("다음 주 월요일이 며칠이에요?", "다음 주 월요일은 10월 26일이에요."), W("그날 날씨는요?", "", [3])],
|
||||
[S("What day is it tomorrow?", "Tomorrow is Saturday."), W("How's the weather?", "", [1])],
|
||||
# the day moves, the place stays
|
||||
[W("What's the weather in Busan?", "Busan", None), W("And tomorrow?", "Busan", [1]), W("And Sunday?", "Busan", [2])],
|
||||
[W("부산 날씨 어때요?", "Busan", None), W("내일은요?", "Busan", [1]), W("모레는요?", "Busan", [2])],
|
||||
[W("제주 날씨 알려줘", "Jeju City", None), W("그럼 토요일은 비 와요?", "Jeju City", [1])],
|
||||
[W("Weather in Tokyo tomorrow?", "Tokyo", [1]), W("How about the day after?", "Tokyo", [2]),
|
||||
W("And the day after that?", "Tokyo", [3])],
|
||||
[W("내일 날씨 어때?", "", [1]), W("그 다음 날은?", "", [2]), W("다음날은요?", "", [3])],
|
||||
# the place moves, the day stays
|
||||
[W("Will it rain tomorrow?", "", [1]), W("What about Busan?", "Busan", [1]), W("And Daegu?", "Daegu", [1])],
|
||||
[W("내일 비 와요?", "", [1]), W("그럼 부산은?", "Busan", [1])],
|
||||
[W("What's the weather on Saturday?", "", [1]), W("What about Busan on Sunday?", "Busan", [2])],
|
||||
[W("오늘 서울 날씨 어때요?", "Seoul", [0]), W("부산은 내일 어때요?", "Busan", [1])],
|
||||
# weekends and weeks
|
||||
[W("What's the weather this weekend?", "", [1, 2]), W("And next weekend?", "", [8, 9])],
|
||||
[W("이번 주말 날씨 어때요?", "", [1, 2]), W("다음 주 수요일은요?", "", [5])],
|
||||
[W("주말에 비 와요?", "", [1, 2]), W("일요일은?", "", [2])],
|
||||
[W("How's the weather next week?", "", [3, 4, 5, 6, 7, 8, 9])],
|
||||
[W("Will it rain this week?", "", [0, 1, 2])],
|
||||
# beyond the forecast, in the past
|
||||
[W("What's the weather next Friday?", "", [7]), W("And Thursday?", "", [6])],
|
||||
[W("다음 주 토요일 날씨 어때요?", "", [8]), W("그럼 화요일은?", "", [4])],
|
||||
[W("Weather in 10 days?", "", [10])],
|
||||
[W("어제 날씨 어땠어요?", "", [-1]), W("오늘은요?", "", [0])],
|
||||
[W("What was the weather yesterday?", "", [-1]), W("And tomorrow?", "", [1])],
|
||||
# mixed English and Korean
|
||||
[W("내일 weather 어때?", "", [1]), W("And Busan 내일은?", "Busan", [1])],
|
||||
[W("What's the weather in Seoul?", "Seoul", None), W("모레는?", "Seoul", [2])],
|
||||
[W("오늘 날씨?", "", [0]), W("And Monday?", "", [3])],
|
||||
# in three days, today's own weekday
|
||||
[W("What will the weather be in three days?", "", [3]), W("And Friday?", "", [0])],
|
||||
[W("3일 후 날씨 어때요?", "", [3]), W("글피는요?", "", [3])],
|
||||
# the day moves through a long talk, a remark in between ends the follow-up
|
||||
[W("Weather today?", "", [0]), W("Tomorrow?", "", [1]), W("And Sunday?", "", [2]), W("What about Monday?", "", [3]),
|
||||
W("And Tuesday?", "", [4])],
|
||||
[W("오늘 날씨 어때요?", "", [0]), N("고마워요"), W("날씨 어때요?", "", None)],
|
||||
[W("What's the weather like tomorrow?", "", [1]), N("Thanks, see you tomorrow!")],
|
||||
[W("내일 기온 몇 도예요?", "", [1]), W("다음 주 월요일은요?", "", [3]), W("부산은요?", "Busan", [3])],
|
||||
]
|
||||
|
||||
|
||||
class _Date(datetime.date):
|
||||
@classmethod
|
||||
def today(cls):
|
||||
return TODAY
|
||||
|
||||
|
||||
def forecast(place):
|
||||
days = [(TODAY + datetime.timedelta(days=i)).strftime("%A %d %B") for i in range(web.WEATHER_DAYS)]
|
||||
lines = [f"Today ({days[0]})" if i == 0 else f"Tomorrow ({days[1]})" if i == 1 else d for i, d in enumerate(days)]
|
||||
return f"Weather in {place or 'Seoul'} now: clear sky, 15 degrees, wind 3 km/h.\n" + \
|
||||
"\n".join(f"{n}: partly cloudy, {8 + i} to {18 + i} degrees, chance of rain {10 * i} percent." for i, n in enumerate(lines))
|
||||
|
||||
|
||||
def check():
|
||||
saved = web.datetime
|
||||
web.datetime = type("dt", (), {"date": _Date, "timedelta": datetime.timedelta})
|
||||
try:
|
||||
for n, talk in enumerate(DIALOGUES):
|
||||
b = brain.Brain()
|
||||
for turn in talk:
|
||||
text, where = turn["text"], f"dialogue {n}: {turn['text']!r}"
|
||||
if "said" in turn:
|
||||
b.history.append((text, f"ACTION: none -\n{turn['said']}"))
|
||||
continue
|
||||
rule = brain.intent(text, MARKS)
|
||||
if rule and rule[0] == "weather":
|
||||
target = rule[1]
|
||||
else:
|
||||
h = b._after({"action": turn.get("llm", "none"), "target": text}, text)
|
||||
target = h["target"] if h["action"] == "weather" else None
|
||||
if turn["place"] is None:
|
||||
assert target is None, (where, "not weather", target)
|
||||
b.history.append((text, "ACTION: none -\nYou're welcome."))
|
||||
continue
|
||||
assert target is not None, (where, "not routed to the weather", rule)
|
||||
place = b.weather_place(target, text)
|
||||
days = b.weather_on(text)
|
||||
assert (place, days) == (turn["place"], turn["days"]), (where, place, days)
|
||||
facts = web.weather_on(forecast(place), days, TODAY)
|
||||
for d in days or []:
|
||||
name = (TODAY + datetime.timedelta(days=d)).strftime("%A %d %B")
|
||||
line = next((l for l in facts.split("\n") if name in l), "")
|
||||
assert line and ((FAR in line) == (d >= web.WEATHER_DAYS)) and ((PAST in line) == (d < 0)), (where, facts)
|
||||
if days:
|
||||
assert len(facts.split("\n")) == len(days) + 1, (where, facts) # no other day's line
|
||||
asked = text + brain.WEATHER_ASKED
|
||||
b.history.append((asked, "It will be partly cloudy."))
|
||||
b.last_lookup = asked
|
||||
finally:
|
||||
web.datetime = saved
|
||||
return len(DIALOGUES)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"weather dialogues ok: {check()}")
|
||||
@@ -170,15 +170,15 @@ CASES = [
|
||||
C([PRES], "thanks", "closing", "thanks for the answer: you're welcome, silence ends"),
|
||||
|
||||
# ---------- after the weather ----------
|
||||
C([WX], "and tomorrow?", "search", "tomorrow's weather in Seoul", r"weather.*tomorrow"),
|
||||
C([WX], "Tomorrow?", "search", "tomorrow's weather in Seoul", r"weather.*Tomorrow"),
|
||||
C([WX], "what about tomorrow?", "search", "tomorrow's weather in Seoul", r"weather.*tomorrow"),
|
||||
C([WX], "and the weekend?", "search", "the weather this weekend", r"weather.*weekend"),
|
||||
C([WX], "and the day after tomorrow?", "search", "the weather the day after tomorrow", r"weather.*tomorrow"),
|
||||
C([WX], "sorry, I meant tomorrow", "search", "tomorrow's weather", r"weather.*tomorrow"),
|
||||
C([WX_KO], "그럼 내일은?", "search", "내일 날씨", r"weather.*내일"),
|
||||
C([WX_KO], "내일은?", "search", "내일 날씨", r"weather.*내일"),
|
||||
C([WX_KO], "주말은요?", "search", "주말 날씨", r"weather.*주말"),
|
||||
C([WX], "and tomorrow?", "weather", "tomorrow's weather in Seoul", r"weather.*tomorrow"),
|
||||
C([WX], "Tomorrow?", "weather", "tomorrow's weather in Seoul", r"weather.*Tomorrow"),
|
||||
C([WX], "what about tomorrow?", "weather", "tomorrow's weather in Seoul", r"weather.*tomorrow"),
|
||||
C([WX], "and the weekend?", "weather", "the weather this weekend", r"weather.*weekend"),
|
||||
C([WX], "and the day after tomorrow?", "weather", "the weather the day after tomorrow", r"weather.*tomorrow"),
|
||||
C([WX], "sorry, I meant tomorrow", "search|weather", "tomorrow's weather", r"weather.*tomorrow"),
|
||||
C([WX_KO], "그럼 내일은?", "weather", "내일 날씨", r"weather.*내일"),
|
||||
C([WX_KO], "내일은?", "weather", "내일 날씨", r"weather.*내일"),
|
||||
C([WX_KO], "주말은요?", "weather", "주말 날씨", r"weather.*주말"),
|
||||
C([WX], "what about Busan?", "weather", "the weather in Busan", r"Busan"),
|
||||
C([WX], "and Tokyo?", "weather", "the weather in Tokyo", r"Tokyo"),
|
||||
C([WX], "How about in London?", "weather", "the weather in London", r"London"),
|
||||
|
||||
@@ -323,7 +323,7 @@ CASES_MORE = [
|
||||
C([WX], "what about Incheon?", "weather", "the weather in Incheon", r"Incheon"),
|
||||
C([WX], "and New York?", "weather", "the weather in New York", r"New York"),
|
||||
C([WX], "in Daejeon?", "weather", "the weather in Daejeon", r"Daejeon"),
|
||||
C([WX], "and next week?", "search", "the weather next week", r"weather.*next week"),
|
||||
C([WX], "and next week?", "weather", "the weather next week", r"weather.*next week"),
|
||||
C([WX], "tonight?", "search|weather", "the weather tonight"),
|
||||
C([WX], "what about this evening?", "search|weather", "the weather this evening"),
|
||||
C([WX], "should I take an umbrella?", "weather", "will it rain today"),
|
||||
@@ -332,20 +332,20 @@ CASES_MORE = [
|
||||
C([WX], "great", "talk", "a reaction"),
|
||||
C([WX], "nice, thanks", "closing", "thanks for the answer"),
|
||||
C([WX], "what time is it?", "llm", "a topic shift: the time"),
|
||||
C([WX, T("cool", "")], "and tomorrow?", "search", "a reaction between keeps the weather topic", r"tomorrow"),
|
||||
C([WX, T("cool", "")], "and tomorrow?", "search|weather", "a reaction between keeps the weather topic", r"tomorrow"),
|
||||
C([WX, NAME_Q], "and tomorrow?", "llm", "small talk between: no weather to go on"),
|
||||
C([WX_KO], "그럼 부산은요?", "weather", "부산 날씨는요", r"Busan"),
|
||||
C([WX_KO], "대구는?", "weather", "대구 날씨는", r"Daegu"),
|
||||
C([WX_KO], "인천 날씨는?", "weather", "인천 날씨는", r"Incheon"),
|
||||
C([WX_KO], "모레는?", "search", "모레 날씨는", r"weather.*모레"),
|
||||
C([WX_KO], "다음 주는요?", "search", "다음 주 날씨는요", r"weather.*다음 ?주"),
|
||||
C([WX_KO], "모레는?", "weather", "모레 날씨는", r"weather.*모레"),
|
||||
C([WX_KO], "다음 주는요?", "weather", "다음 주 날씨는요", r"weather.*다음 ?주"),
|
||||
C([WX_KO], "오늘 밤은?", "search|weather", "오늘 밤 날씨는"),
|
||||
C([WX_KO], "우산 챙겨야 돼?", "weather", "비 와? 우산 필요해?"),
|
||||
C([WX_KO], "헐 덥겠다", "talk", "날씨에 대한 반응"),
|
||||
C([WX_KO], "와 좋다", "talk", "반응"),
|
||||
C([WX_KO], "and Busan?", "weather", "mixed: 부산 날씨는", r"Busan"),
|
||||
C([WX_KO], "tomorrow는?", "search", "code-switch: 내일 날씨는", r"weather.*tomorrow"),
|
||||
C([WX_KO, T("오 좋네", "")], "내일은요?", "search", "반응 뒤에도 날씨 얘기: 내일 날씨", r"weather.*내일"),
|
||||
C([WX_KO], "tomorrow는?", "search|weather", "code-switch: 내일 날씨는", r"weather.*tomorrow"),
|
||||
C([WX_KO, T("오 좋네", "")], "내일은요?", "weather", "반응 뒤에도 날씨 얘기: 내일 날씨", r"weather.*내일"),
|
||||
C([WX_KO, KO_AGE], "그럼 내일은?", "llm", "사이에 다른 주제: 날씨 아님"),
|
||||
C([TOKYO], "and Kyoto?", "weather", "the weather in Kyoto", r"Kyoto"),
|
||||
C([TOKYO], "what about tomorrow there?", "search|weather", "tomorrow's weather in Tokyo", r"tomorrow|Tokyo"),
|
||||
|
||||
+21
-2
@@ -104,6 +104,25 @@ outs = iter([["search NY weather\n", "It is 15 degrees. Clear."]])
|
||||
assert list(brain.Brain().respond_from("Weather?", "x")) == ["It is 15 degrees.", "Clear."]
|
||||
outs = iter([["Search results say 330 m."]])
|
||||
assert list(brain.Brain().respond_from("Eiffel?", "x")) == ["Search results say 330 m."]
|
||||
# "Let me check." is said by lumi before the lookup: never again inside the answer
|
||||
outs = iter([["Let me check. It is 15 degrees. 확인해 볼게요."]])
|
||||
assert list(brain.Brain().respond_from("Weather?", "x")) == ["It is 15 degrees."]
|
||||
|
||||
# the days a weather question asks (today: Friday 23 October 2026), and only their lines of the forecast
|
||||
fri = datetime.date(2026, 10, 23)
|
||||
for q, days in {"오늘 날씨": [0], "and tomorrow?": [1], "모레는요?": [2], "내일모레": [2], "next Monday?": [3],
|
||||
"다음 주 월요일 어때요?": [3], "this weekend": [1, 2], "이번 주말": [1, 2], "and Friday?": [0],
|
||||
"next Friday": [7], "yesterday": [-1], "어제": [-1], "in 2 days": [2], "사흘 뒤": [3], "what about Busan?": None,
|
||||
"the day after": [2]}.items():
|
||||
assert web.asked_day(q, [1], fri) == days, (q, web.asked_day(q, [1], fri))
|
||||
week = "Weather in Seoul now: clear sky, 15 degrees.\n" + "\n".join(
|
||||
f"{(fri + datetime.timedelta(days=i)).strftime('%A %d %B')}: rain." for i in range(7))
|
||||
assert web.weather_on(week, [3], fri) == "Forecast for Seoul:\nMonday 26 October: rain."
|
||||
assert web.weather_on(week, [0], fri).startswith("Weather in Seoul now") and web.weather_on(week, None, fri) == week
|
||||
assert "too far ahead, the forecast reaches only to Thursday 29 October" in web.weather_on(week, [9], fri)
|
||||
assert "already past" in web.weather_on(week, [-1], fri)
|
||||
from tests import dialogues_weather # 30+ weather talks, EN / KO / mixed
|
||||
dialogues_weather.check()
|
||||
# respond_stream: "search ..." under "ACTION: none" or without "ACTION:" is the lookup, never said; its words are not
|
||||
# the query
|
||||
outs = iter([["ACTION: none -\n", "search Lotte World", " ticket price"]])
|
||||
@@ -187,8 +206,8 @@ def fake_say_stream(pieces, lang=None, abort=None):
|
||||
|
||||
|
||||
class FakeBrain:
|
||||
weather_place = brain.Brain.weather_place
|
||||
weather_at = ""
|
||||
weather_place, weather_on = brain.Brain.weather_place, brain.Brain.weather_on
|
||||
weather_at, weather_days, history = "", None, []
|
||||
|
||||
def respond_from(self, asked, facts):
|
||||
events.append(("llm", asked, time.time()))
|
||||
|
||||
Reference in New Issue
Block a user