Compare commits
4 Commits
app-v0.1.2
...
app-v0.1.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e90c47a95 | ||
|
|
c7655c58f4 | ||
|
|
b4f8f71dd2 | ||
|
|
9ba26c5bac |
@@ -36,7 +36,7 @@
|
||||
- 원하면 게임 중에는 봇을 일시정지할 수 있습니다.
|
||||
- **안티치트 보호**: 뱅가드 같은 안티치트가 걸린 게임이 실행 중이면 키보드·마우스 자동 조작을 막고 그 이유를 알려 줍니다.
|
||||
- **기존 기능 유지**: 메모리, 날씨, 웹 검색, 식단 기록, MCP, 브라우저 제어를 그대로 가져갑니다.
|
||||
- **기상청 날씨**: 관리 앱 "기능" 화면에 기상청 API허브 인증키를 넣으면 한국 안의 현재 날씨와 10일 뒤까지의 예보("내일 날씨", "주말 날씨")를 기상청에서 받습니다(초단기실황조회, 초단기예보조회, 단기예보조회, 중기기온조회, 중기육상예보조회 활용신청 필요). 키가 없거나 한국 밖이면 open-meteo에서 받고, 현재 날씨는 그다음 met.no에서 받습니다.
|
||||
- **기상청 날씨**: 관리 앱 "기능" 화면에 기상청 API허브 인증키를 넣으면 한국 안의 현재 날씨와 10일 뒤까지의 예보("내일 날씨", "주말 날씨")를 기상청에서 받습니다. "부산 연제구"처럼 구 단위로 물으면 그 구의 날씨를 답하고(장소는 OpenStreetMap에서 찾습니다), "자세히" 물으면 습도, 바람, 강수량까지 답합니다(초단기실황조회, 초단기예보조회, 단기예보조회, 중기기온조회, 중기육상예보조회 활용신청 필요). 키가 없거나 한국 밖이면 open-meteo에서 받고, 현재 날씨는 그다음 met.no에서 받습니다.
|
||||
- **관리 앱**:
|
||||
- 첫 실행 마법사, 대시보드, 모델 다운로드, 기능별 켜기/끄기를 제공합니다.
|
||||
- 로그 화면에서 로그를 보고, 복사하고, 내려받을 수 있습니다. 비밀값은 자동으로 가립니다.
|
||||
|
||||
2
app/Cargo.lock
generated
2
app/Cargo.lock
generated
@@ -1520,7 +1520,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
|
||||
|
||||
[[package]]
|
||||
name = "jarvis-app"
|
||||
version = "0.1.28"
|
||||
version = "0.1.30"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.22.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "jarvis-app"
|
||||
version = "0.1.28"
|
||||
version = "0.1.30"
|
||||
edition = "2021"
|
||||
rust-version = "1.85"
|
||||
description = "Jarvis v2 Windows app core: Discord voice, voice worker supervisor, chat channels"
|
||||
|
||||
4
app/shell/Cargo.lock
generated
4
app/shell/Cargo.lock
generated
@@ -2637,7 +2637,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
|
||||
|
||||
[[package]]
|
||||
name = "jarvis-app"
|
||||
version = "0.1.28"
|
||||
version = "0.1.30"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.22.1",
|
||||
@@ -2666,7 +2666,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jarvis-shell"
|
||||
version = "0.1.28"
|
||||
version = "0.1.30"
|
||||
dependencies = [
|
||||
"jarvis-app",
|
||||
"serde_json",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "jarvis-shell"
|
||||
version = "0.1.28"
|
||||
version = "0.1.30"
|
||||
edition = "2021"
|
||||
rust-version = "1.85"
|
||||
description = "Jarvis v2 management app window (Tauri 2 over the app core's AdminApi)"
|
||||
|
||||
32
evals/test_weather_detail.py
Normal file
32
evals/test_weather_detail.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
Eval: a request for the weather in detail reaches getWeather as detail=true, and a plain one does not.
|
||||
|
||||
With detail getWeather also gives the humidity, the wind and the rain amount (2026-11-18);
|
||||
without it the answer stays one short sentence for the voice reply.
|
||||
|
||||
Run: EVAL_JUDGE_MODEL=qwen3:8b ./scripts/run_evals.sh weather_detail
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from conftest import requires_judge_llm
|
||||
from test_weather_forecast_days import _ask
|
||||
|
||||
|
||||
def _detail(args):
|
||||
return (args or {}).get("detail") in (True, "true", "True")
|
||||
|
||||
|
||||
@pytest.mark.eval
|
||||
@requires_judge_llm
|
||||
class TestWeatherDetail:
|
||||
@pytest.mark.parametrize("query", ["부산 연제구 날씨 자세히 알려 줘", "give me the detailed weather for Busan"])
|
||||
def test_asked_in_detail_detail_is_set(self, mock_config, eval_db, eval_dialogue_memory, query):
|
||||
args = _ask(mock_config, eval_db, eval_dialogue_memory, query)
|
||||
assert args is not None, "getWeather was not called"
|
||||
assert _detail(args), args
|
||||
|
||||
def test_a_plain_question_is_not_detailed(self, mock_config, eval_db, eval_dialogue_memory):
|
||||
args = _ask(mock_config, eval_db, eval_dialogue_memory, "부산 연제구 날씨 어때?")
|
||||
assert args is not None, "getWeather was not called"
|
||||
assert not _detail(args), args
|
||||
25
evals/test_weather_district_place.py
Normal file
25
evals/test_weather_district_place.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""
|
||||
Eval: a district the user names reaches getWeather whole ("부산 연제구"), not only its city.
|
||||
|
||||
getWeather finds districts on OpenStreetMap (2026-11-18), so the place argument must keep
|
||||
the district for the answer to be about that spot.
|
||||
|
||||
Run: EVAL_JUDGE_MODEL=qwen3:8b ./scripts/run_evals.sh weather_district_place
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from conftest import requires_judge_llm
|
||||
from test_weather_forecast_days import _ask
|
||||
|
||||
|
||||
@pytest.mark.eval
|
||||
@requires_judge_llm
|
||||
@pytest.mark.parametrize("query,district", [
|
||||
("부산 연제구 날씨 어때?", "연제"),
|
||||
("서울 강남구 내일 날씨 알려 줘", "강남"),
|
||||
])
|
||||
def test_the_district_is_in_the_place(mock_config, eval_db, eval_dialogue_memory, query, district):
|
||||
args = _ask(mock_config, eval_db, eval_dialogue_memory, query)
|
||||
assert args is not None, "getWeather was not called"
|
||||
assert district in (args.get("location") or ""), args
|
||||
@@ -207,6 +207,28 @@ _MET_NO_URL = "https://api.met.no/weatherapi/locationforecast/2.0/compact"
|
||||
_MET_NO_HEADERS = {"User-Agent": "jarvis-voice-assistant/2 github.com/isair/jarvis"}
|
||||
|
||||
|
||||
# OpenStreetMap's place search: any language, down to districts (부산 연제구), which open-meteo's
|
||||
# geocoder (cities, Latin spellings) does not know. Its policy asks for an identifying User-Agent.
|
||||
_NOMINATIM_URL = "https://nominatim.openstreetmap.org/search"
|
||||
|
||||
|
||||
def _osm_place(name: str) -> Optional[Dict[str, Any]]:
|
||||
"""The place OpenStreetMap finds for a name: {'lat', 'lon', 'country_code'}; None if none or on failure."""
|
||||
try:
|
||||
resp = requests.get(_NOMINATIM_URL, headers=_MET_NO_HEADERS, timeout=_OPEN_METEO_TIMEOUT_SEC,
|
||||
params={"q": name, "format": "jsonv2", "limit": 1, "addressdetails": 1})
|
||||
resp.raise_for_status()
|
||||
found = resp.json()
|
||||
if not isinstance(found, list) or not found:
|
||||
return None
|
||||
place = found[0]
|
||||
code = ((place.get("address") or {}).get("country_code") or "").upper() or None
|
||||
return {"lat": float(place["lat"]), "lon": float(place["lon"]), "country_code": code}
|
||||
except Exception as e:
|
||||
debug_log(f" ⚠️ OpenStreetMap place search failed ({type(e).__name__})", "tools")
|
||||
return None
|
||||
|
||||
|
||||
def _met_no_wmo(symbol: str) -> Optional[int]:
|
||||
"""The WMO code closest to a met.no symbol code ('lightrainshowers_night' -> 80)."""
|
||||
s = (symbol or "").split("_")[0]
|
||||
@@ -259,8 +281,9 @@ _KMA_MID_URL = _KMA_API + "MidFcstInfoService/"
|
||||
_KMA_TIMEOUT_SEC = 5
|
||||
_KST = timezone(timedelta(hours=9))
|
||||
# KMA's own words: PTY (precipitation type, 0 = none) wins over SKY (sky state).
|
||||
_KMA_PTY_KO = {1: "비", 2: "비나 눈", 3: "눈", 5: "빗방울", 6: "빗방울과 눈날림", 7: "눈날림"}
|
||||
_KMA_PTY_WMO = {1: 63, 2: 69, 3: 73, 5: 51, 6: 68, 7: 71}
|
||||
# 4 (소나기) is in 단기예보 only, 5 to 7 in 초단기실황/초단기예보 only.
|
||||
_KMA_PTY_KO = {1: "비", 2: "비나 눈", 3: "눈", 4: "소나기", 5: "빗방울", 6: "빗방울과 눈날림", 7: "눈날림"}
|
||||
_KMA_PTY_WMO = {1: 63, 2: 69, 3: 73, 4: 81, 5: 51, 6: 68, 7: 71}
|
||||
_KMA_SKY_KO = {1: "맑음", 3: "구름 많음", 4: "흐림"}
|
||||
_KMA_SKY_WMO = {1: 0, 3: 2, 4: 3}
|
||||
_kma_key = ""
|
||||
@@ -372,8 +395,11 @@ def _kma_short_days(lat: float, lon: float, key: str, now: datetime, offsets: li
|
||||
temps = [float(v) for v in cats.get("TMP", {}).values()]
|
||||
lo = float(next(iter(cats["TMN"].values()))) if cats.get("TMN") else min(temps, default=None)
|
||||
hi = float(next(iter(cats["TMX"].values()))) if cats.get("TMX") else max(temps, default=None)
|
||||
reh = [float(v) for v in cats.get("REH", {}).values()]
|
||||
out[off] = {"date": date, "am": _kma_half(cats, False), "pm": _kma_half(cats, True), "min": lo,
|
||||
"max": hi, "pop": max((int(float(v)) for v in cats.get("POP", {}).values()), default=None)}
|
||||
"max": hi, "pop": max((int(float(v)) for v in cats.get("POP", {}).values()), default=None),
|
||||
"humidity": sum(reh) / len(reh) if reh else None,
|
||||
"wind_ms": max((float(v) for v in cats.get("WSD", {}).values()), default=None)}
|
||||
return out
|
||||
|
||||
|
||||
@@ -424,7 +450,8 @@ def _open_meteo_days(lat: float, lon: float, offsets: list) -> Dict[int, Dict[st
|
||||
try:
|
||||
resp = requests.get("https://api.open-meteo.com/v1/forecast", timeout=_OPEN_METEO_TIMEOUT_SEC, params={
|
||||
"latitude": lat, "longitude": lon, "timezone": "auto", "forecast_days": max(offsets) + 1,
|
||||
"daily": "weather_code,temperature_2m_max,temperature_2m_min,precipitation_probability_max"})
|
||||
"daily": "weather_code,temperature_2m_max,temperature_2m_min,precipitation_probability_max,"
|
||||
"wind_speed_10m_max,precipitation_sum"})
|
||||
resp.raise_for_status()
|
||||
daily = (resp.json() or {}).get("daily") or {}
|
||||
except Exception as e:
|
||||
@@ -443,10 +470,35 @@ def _open_meteo_days(lat: float, lon: float, offsets: list) -> Dict[int, Dict[st
|
||||
ko = WMO_CODES_KO.get(code) if code is not None else None
|
||||
out[off] = {"date": datetime.fromisoformat(date).date(), "am": ko, "pm": ko,
|
||||
"min": at("temperature_2m_min", off), "max": at("temperature_2m_max", off),
|
||||
"pop": at("precipitation_probability_max", off)}
|
||||
"pop": at("precipitation_probability_max", off),
|
||||
"wind_ms": _ms(at("wind_speed_10m_max", off)), "rain_mm": at("precipitation_sum", off)}
|
||||
return out
|
||||
|
||||
|
||||
def _ms(kmh: Optional[float]) -> Optional[float]:
|
||||
return kmh / 3.6 if kmh is not None else None
|
||||
|
||||
|
||||
def _detail_parts(humidity, wind_ms, rain_mm, wind_word: str, rain_word: str) -> list:
|
||||
"""습도 / 바람 / 강수량 for an answer asked in detail; a dry spell's 0 mm is left out."""
|
||||
parts = []
|
||||
if humidity is not None:
|
||||
parts.append(f"습도 {round(float(humidity))}%")
|
||||
if wind_ms is not None:
|
||||
parts.append(f"{wind_word} 초속 {round(float(wind_ms), 1):g}미터")
|
||||
if rain_mm is not None and float(rain_mm) > 0:
|
||||
parts.append(f"{rain_word} {round(float(rain_mm), 1):g}mm")
|
||||
return parts
|
||||
|
||||
|
||||
def _weekday_offsets() -> str:
|
||||
"""The days_ahead of each coming weekday, so the model need not count them (a small model
|
||||
counted 'this weekend' from a Wednesday as 2)."""
|
||||
today = datetime.now()
|
||||
days = ", ".join(f"{(today + timedelta(days=n)).strftime('%A')} {n}" for n in range(1, 8))
|
||||
return f"From today, {today.strftime('%A')}: {days}."
|
||||
|
||||
|
||||
def _day_span(args: Optional[Dict[str, Any]]) -> tuple:
|
||||
"""(first, last) day asked for, counted from today: (0, 0) is the weather now."""
|
||||
def num(name: str, default: int) -> int:
|
||||
@@ -458,7 +510,7 @@ def _day_span(args: Optional[Dict[str, Any]]) -> tuple:
|
||||
return first, min(first + max(num("days", 1), 1) - 1, MAX_DAYS_AHEAD)
|
||||
|
||||
|
||||
def _day_sentence(off: int, day: Dict[str, Any], place: str) -> str:
|
||||
def _day_sentence(off: int, day: Dict[str, Any], place: str, detail: bool = False) -> str:
|
||||
"""'내일(11월 19일 목요일) 서울 날씨는 오전 맑음, 오후 비, 최저 -1도, 최고 4도, 강수확률 60%입니다.'"""
|
||||
d = day["date"]
|
||||
when = f"{d.month}월 {d.day}일 {_WEEKDAYS_KO[d.weekday()]}요일"
|
||||
@@ -472,6 +524,8 @@ def _day_sentence(off: int, day: Dict[str, Any], place: str) -> str:
|
||||
parts.append(f"최고 {round(float(day['max']))}도")
|
||||
if day.get("pop") is not None:
|
||||
parts.append(f"강수확률 {round(float(day['pop']))}%")
|
||||
if detail:
|
||||
parts += _detail_parts(day.get("humidity"), day.get("wind_ms"), day.get("rain_mm"), "최대 바람", "강수량")
|
||||
return f"{when} {place} 날씨는 " + ", ".join(p for p in parts if p) + "입니다."
|
||||
|
||||
|
||||
@@ -504,6 +558,7 @@ def _kma_current(lat: float, lon: float, key: str, now: Optional[datetime] = Non
|
||||
"weather_code": wmo,
|
||||
"condition_ko": ko,
|
||||
"wind_speed_10m": round(float(wind) * 3.6, 1) if wind is not None else None,
|
||||
"precipitation": float(obs["RN1"]) if obs.get("RN1") is not None else None,
|
||||
}
|
||||
except Exception as e:
|
||||
why = str(e) if isinstance(e, (ValueError, KeyError)) else type(e).__name__
|
||||
@@ -546,11 +601,15 @@ class WeatherTool(Tool):
|
||||
},
|
||||
"days_ahead": {
|
||||
"type": "integer",
|
||||
"description": "Days from today's date in the context to the day asked about: omit or 0 for now, 1 for tomorrow, 2 for the day after, up to 10. For a weekday count from today's weekday (on a Wednesday the coming Saturday is 3)."
|
||||
"description": "Days from today to the day asked about: omit or 0 for now, 1 for tomorrow, 2 for the day after, up to 10. " + _weekday_offsets()
|
||||
},
|
||||
"days": {
|
||||
"type": "integer",
|
||||
"description": "How many days from days_ahead on (default 1): 2 for a weekend (Saturday and Sunday), 7 for a week."
|
||||
},
|
||||
"detail": {
|
||||
"type": "boolean",
|
||||
"description": "true only when the user asks for more detail: the answer then also has the humidity, the wind and the rain amount."
|
||||
}
|
||||
},
|
||||
"required": []
|
||||
@@ -603,7 +662,7 @@ class WeatherTool(Tool):
|
||||
|
||||
@staticmethod
|
||||
def _forecast_lines(lat: float, lon: float, country_code: Optional[str], first: int, last: int,
|
||||
location_display: str) -> list:
|
||||
location_display: str, detail: bool = False) -> list:
|
||||
"""A sentence for each day from first to last that a forecast has: KMA inside Korea with the
|
||||
app's key, open-meteo for the days KMA does not give."""
|
||||
offsets = list(range(first, last + 1))
|
||||
@@ -618,7 +677,7 @@ class WeatherTool(Tool):
|
||||
debug_log(f" 🌤️ forecast days {first}-{last}: {from_kma} from KMA, "
|
||||
f"{len(days) - from_kma} from open-meteo", "tools")
|
||||
place = location_display.split(",")[0].strip() or location_display
|
||||
return [_day_sentence(off, days[off], place) for off in offsets if off in days]
|
||||
return [_day_sentence(off, days[off], place, detail) for off in offsets if off in days]
|
||||
|
||||
def run(self, args: Optional[Dict[str, Any]], context: ToolContext) -> ToolExecutionResult:
|
||||
"""Get the weather now, or the forecast for the days asked about, for a location."""
|
||||
@@ -708,13 +767,24 @@ class WeatherTool(Tool):
|
||||
"format": "json"
|
||||
}
|
||||
|
||||
geo_response = requests.get(geocode_url, params=geocode_params, timeout=10)
|
||||
geo_response.raise_for_status()
|
||||
geo_data = geo_response.json()
|
||||
# Open-Meteo knows cities only, in Latin spellings, and matches a
|
||||
# non-Latin name loosely (live 2026-11-18: "부산" gave a village
|
||||
# called Pusan 140 km away). A non-Latin name, and a Latin one
|
||||
# open-meteo does not know (a district), is looked up on
|
||||
# OpenStreetMap in the words the user used.
|
||||
geo_data: Dict[str, Any] = {}
|
||||
if location_str.isascii():
|
||||
geo_response = requests.get(geocode_url, params=geocode_params, timeout=10)
|
||||
geo_response.raise_for_status()
|
||||
geo_data = geo_response.json()
|
||||
osm = None if geo_data.get("results") else _osm_place(location_str)
|
||||
if osm:
|
||||
debug_log(" 📍 found on OpenStreetMap", "tools")
|
||||
geo_data = {"results": [{"latitude": osm["lat"], "longitude": osm["lon"],
|
||||
"name": location_str, "country_code": osm["country_code"]}]}
|
||||
|
||||
# Open-Meteo only matches Latin spellings, so a non-Latin name
|
||||
# (e.g. Korean "서울") returns nothing. Retry once with an
|
||||
# LLM-romanised name before giving up.
|
||||
# Not on OpenStreetMap either (or it failed): retry open-meteo
|
||||
# once with an LLM-romanised name before giving up.
|
||||
if not geo_data.get("results"):
|
||||
romanised = _romanise_place(location_str, getattr(context, "cfg", None))
|
||||
if romanised:
|
||||
@@ -767,8 +837,9 @@ class WeatherTool(Tool):
|
||||
debug_log(f" 📍 resolved to {location_display} ({lat}, {lon})", "tools")
|
||||
|
||||
first, last = _day_span(args)
|
||||
detail = (args or {}).get("detail") is True or str((args or {}).get("detail")).lower() == "true"
|
||||
if first > 0:
|
||||
lines = self._forecast_lines(lat, lon, country_code, first, last, location_display)
|
||||
lines = self._forecast_lines(lat, lon, country_code, first, last, location_display, detail)
|
||||
if not lines:
|
||||
return ToolExecutionResult(
|
||||
success=False,
|
||||
@@ -782,7 +853,7 @@ class WeatherTool(Tool):
|
||||
weather_params = {
|
||||
"latitude": lat,
|
||||
"longitude": lon,
|
||||
"current": "temperature_2m,relative_humidity_2m,apparent_temperature,weather_code,wind_speed_10m,wind_gusts_10m",
|
||||
"current": "temperature_2m,relative_humidity_2m,apparent_temperature,weather_code,wind_speed_10m,wind_gusts_10m,precipitation",
|
||||
"hourly": "temperature_2m,weather_code",
|
||||
"daily": "weather_code,temperature_2m_max,temperature_2m_min",
|
||||
"forecast_days": 7,
|
||||
@@ -840,6 +911,9 @@ class WeatherTool(Tool):
|
||||
if feels_like_c is not None and round(feels_like_c) != round(temp_c):
|
||||
_t += f"(체감 {round(feels_like_c)}도)"
|
||||
_ko_parts.append(_t)
|
||||
if detail:
|
||||
_ko_parts += _detail_parts(humidity, _ms(wind_speed), current.get("precipitation"),
|
||||
"바람", "지난 1시간 강수량")
|
||||
ko_sentence = ", ".join(_ko_parts) + "입니다."
|
||||
|
||||
# The reply is the clean Korean sentence ONLY — no English/°C source
|
||||
@@ -847,7 +921,7 @@ class WeatherTool(Tool):
|
||||
# ramble over. The model just echoes this one sentence.
|
||||
lines = [ko_sentence]
|
||||
if last > 0: # "this week": now, then each day
|
||||
lines += self._forecast_lines(lat, lon, country_code, 0, last, location_display)
|
||||
lines += self._forecast_lines(lat, lon, country_code, 0, last, location_display, detail)
|
||||
|
||||
reply_text = "\n".join(lines)
|
||||
|
||||
|
||||
@@ -292,12 +292,20 @@ which carry Discord's own time.
|
||||
point; the weather tool keeps it and uses it only for the weather inside Korea (geocoded or
|
||||
detected country `KR`). Now: KMA's 초단기실황 (temperature, humidity, wind, precipitation) and
|
||||
초단기예보 (the coming hour's sky). A later day (`getWeather` `days_ahead`, 1 to 10, and `days`
|
||||
for a span such as a weekend): 단기예보 for today to 3 days ahead (the morning's and the
|
||||
afternoon's commonest precipitation or sky, the day's lowest and highest, the highest chance of
|
||||
rain), then 중기예보 for the nearest of the KMA cities in `weather.py` and its region (중기기온,
|
||||
for a span such as a weekend; the schema lists each coming weekday's `days_ahead` from today
|
||||
so the model need not count): 단기예보 for today to 3 days ahead (the morning's and the
|
||||
afternoon's commonest precipitation, 소나기 included, or sky, the day's lowest and highest, the
|
||||
highest chance of rain), then 중기예보 for the nearest of the KMA cities in `weather.py` and its region (중기기온,
|
||||
중기육상). Days KMA does not give, and every KMA failure, come from open-meteo (now: then
|
||||
met.no; later days: open-meteo's daily forecast only). The key is in KMA's URLs, so a failure is
|
||||
logged by its kind only.
|
||||
logged by its kind only. `detail` (only when the user asks for more detail) adds the
|
||||
humidity, the wind in m/s and the rain amount: now the last hour's rain (KMA 초단기실황 RN1,
|
||||
open-meteo `precipitation`; none from met.no), a 단기예보 day its mean humidity and strongest
|
||||
wind, an open-meteo day its strongest wind and rain total; 중기예보 has none of these. A dry
|
||||
0 mm is not said. The place is found by open-meteo's geocoder (cities, Latin spellings)
|
||||
or OpenStreetMap's Nominatim (any language, down to districts such as 부산 연제구; a non-Latin
|
||||
name goes there first, since open-meteo matches it loosely); only the place name is sent, with
|
||||
the app's User-Agent, and the answer names the place in the user's own words.
|
||||
- `prepare` tells the brain that `user` is saying a call whose partial transcript is `text` (the app
|
||||
sends it while the speaker is still talking, `app/src/conversation.spec.md`). The brain runs the
|
||||
intent judge's tool pick for it on its own thread, with the asker's dialogue memory and the tool
|
||||
|
||||
@@ -107,16 +107,13 @@ class TestWeatherTool:
|
||||
def test_run_non_latin_location_romanises_and_retries(self, mock_get, mock_romanise):
|
||||
"""A Korean city name Open-Meteo can't geocode is romanised and retried.
|
||||
|
||||
Open-Meteo's geocoder only matches Latin spellings, so ``서울`` returns
|
||||
no results. The tool must romanise to ``Seoul`` and retry rather than
|
||||
Open-Meteo's geocoder only matches Latin spellings, so ``서울`` is first
|
||||
looked up on OpenStreetMap (any language). When that finds nothing,
|
||||
the tool must romanise to ``Seoul`` and retry rather than
|
||||
dead-ending with "could not find location" (the failure the Korean-
|
||||
locked deployment hit on every weather request)."""
|
||||
mock_romanise.return_value = "Seoul"
|
||||
|
||||
geo_empty = Mock()
|
||||
geo_empty.raise_for_status = Mock()
|
||||
geo_empty.json.return_value = {} # no "results"
|
||||
|
||||
geo_seoul = Mock()
|
||||
geo_seoul.raise_for_status = Mock()
|
||||
geo_seoul.json.return_value = {
|
||||
@@ -154,14 +151,16 @@ class TestWeatherTool:
|
||||
},
|
||||
}
|
||||
|
||||
mock_get.side_effect = [geo_empty, geo_seoul, weather_response]
|
||||
osm_empty = Mock(raise_for_status=Mock())
|
||||
osm_empty.json.return_value = []
|
||||
mock_get.side_effect = [osm_empty, geo_seoul, weather_response]
|
||||
|
||||
result = self.tool.run({"location": "서울"}, self.context)
|
||||
|
||||
assert result.success is True
|
||||
assert "Seoul" in result.reply_text
|
||||
mock_romanise.assert_called_once()
|
||||
# The romanised name must be what the second geocode actually queried.
|
||||
# The romanised name must be what the geocode actually queried.
|
||||
assert mock_get.call_args_list[1].kwargs["params"]["name"] == "Seoul"
|
||||
|
||||
@patch('requests.get')
|
||||
@@ -427,7 +426,7 @@ class TestWeatherTool:
|
||||
return met
|
||||
mock_get.side_effect = get
|
||||
|
||||
result = self.tool.run({"location": "서울"}, self.context)
|
||||
result = self.tool.run({"location": "Seoul"}, self.context)
|
||||
|
||||
assert result.success is True
|
||||
assert "서울" in result.reply_text
|
||||
@@ -454,7 +453,7 @@ class TestWeatherTool:
|
||||
raise requests.exceptions.Timeout("timed out")
|
||||
mock_get.side_effect = get
|
||||
|
||||
result = self.tool.run({"location": "서울"}, self.context)
|
||||
result = self.tool.run({"location": "Seoul"}, self.context)
|
||||
|
||||
assert result.success is False
|
||||
assert "unavailable" in result.reply_text.lower()
|
||||
@@ -679,9 +678,9 @@ class TestKmaWeather:
|
||||
"body": {"items": {"item": items}}}}
|
||||
return r
|
||||
|
||||
def _obs(self, pty="0", t1h="4.9"):
|
||||
def _obs(self, pty="0", t1h="4.9", rn1="0"):
|
||||
return self._kma([{"category": c, "obsrValue": v} for c, v in
|
||||
[("PTY", pty), ("REH", "72"), ("RN1", "0"), ("T1H", t1h), ("WSD", "2.5")]])
|
||||
[("PTY", pty), ("REH", "72"), ("RN1", rn1), ("T1H", t1h), ("WSD", "2.5")]])
|
||||
|
||||
def _sky(self, first="3"):
|
||||
# The coming hours, out of order: the earliest one is the sky now.
|
||||
@@ -779,6 +778,48 @@ class TestKmaWeather:
|
||||
assert result.success is True and "기온 11도" in result.reply_text
|
||||
assert not any(self.KEY in str(c) for c in log.call_args_list)
|
||||
|
||||
@patch('requests.get')
|
||||
def test_asked_in_detail_kma_gives_humidity_wind_and_the_last_hours_rain(self, mock_get, monkeypatch):
|
||||
monkeypatch.setenv("JARVIS_KMA_API_KEY", self.KEY)
|
||||
mock_get.side_effect = self._routes(obs=self._obs(pty="1", rn1="1.5"))
|
||||
|
||||
result = self.tool.run({"location": "Seoul", "detail": True}, self.context)
|
||||
|
||||
text = result.reply_text
|
||||
assert "습도 72%" in text and "바람 초속 2.5미터" in text and "지난 1시간 강수량 1.5mm" in text
|
||||
|
||||
@patch('requests.get')
|
||||
def test_not_asked_in_detail_the_answer_stays_short(self, mock_get, monkeypatch):
|
||||
monkeypatch.setenv("JARVIS_KMA_API_KEY", self.KEY)
|
||||
mock_get.side_effect = self._routes(obs=self._obs(pty="1", rn1="1.5"))
|
||||
|
||||
result = self.tool.run({"location": "Seoul"}, self.context)
|
||||
|
||||
assert "습도" not in result.reply_text and "바람" not in result.reply_text
|
||||
|
||||
@patch('requests.get')
|
||||
def test_asked_in_detail_open_meteo_gives_humidity_and_wind_without_a_dry_hours_rain(
|
||||
self, mock_get, monkeypatch):
|
||||
monkeypatch.delenv("JARVIS_KMA_API_KEY", raising=False)
|
||||
calls = []
|
||||
base = self._routes(calls=calls)
|
||||
weather = Mock(status_code=200, raise_for_status=Mock())
|
||||
weather.json.return_value = {"current": {"temperature_2m": 11.0, "weather_code": 0,
|
||||
"relative_humidity_2m": 55, "wind_speed_10m": 10.8,
|
||||
"precipitation": 0.0}}
|
||||
|
||||
def get(url, *a, **k):
|
||||
r = base(url, *a, **k)
|
||||
return weather if "api.open-meteo.com/v1/forecast" in url else r
|
||||
mock_get.side_effect = get
|
||||
|
||||
result = self.tool.run({"location": "Seoul", "detail": True}, self.context)
|
||||
|
||||
assert "습도 55%" in result.reply_text and "바람 초속 3미터" in result.reply_text
|
||||
assert "강수량" not in result.reply_text
|
||||
(p,) = [p for u, p in calls if "api.open-meteo.com/v1/forecast" in u]
|
||||
assert "precipitation" in p["current"].split(",")
|
||||
|
||||
@pytest.mark.parametrize("place,lat,lon,grid", [
|
||||
("서울", 37.5665, 126.9780, (60, 127)),
|
||||
("부산", 35.1796, 129.0756, (98, 76)),
|
||||
@@ -868,6 +909,8 @@ class TestForecast:
|
||||
{"category": "PTY", "fcstDate": date, "fcstTime": t, "fcstValue": "0" if am else pty_pm},
|
||||
{"category": "POP", "fcstDate": date, "fcstTime": t, "fcstValue": pops[0] if am else pops[1]},
|
||||
{"category": "TMP", "fcstDate": date, "fcstTime": t, "fcstValue": str(hour % 7)},
|
||||
{"category": "REH", "fcstDate": date, "fcstTime": t, "fcstValue": "60" if am else "80"},
|
||||
{"category": "WSD", "fcstDate": date, "fcstTime": t, "fcstValue": str(1 + hour % 4)},
|
||||
]
|
||||
items += [{"category": "TMN", "fcstDate": date, "fcstTime": "0600", "fcstValue": "-1.0"},
|
||||
{"category": "TMX", "fcstDate": date, "fcstTime": "1500", "fcstValue": "4.0"}]
|
||||
@@ -901,6 +944,8 @@ class TestForecast:
|
||||
"temperature_2m_min": [1.2, 2.6, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
"temperature_2m_max": [9.0, 11.4, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
"precipitation_probability_max": [0, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
"wind_speed_10m_max": [9.0, 18.0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
"precipitation_sum": [0.0, 12.5, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
}})
|
||||
return get
|
||||
|
||||
@@ -1042,3 +1087,152 @@ class TestForecast:
|
||||
result = self.tool.run({"location": "X", "days_ahead": 2}, self.context)
|
||||
|
||||
assert result.success is False and "forecast" in result.reply_text.lower()
|
||||
|
||||
# 단기예보's 소나기 (PTY 4) and the detail a person asks for on a later day.
|
||||
|
||||
def test_short_term_showers_are_said_not_dropped_for_a_clear_sky(self, monkeypatch):
|
||||
items = [{"category": c, "fcstDate": "20261119", "fcstTime": f"{h:02d}00", "fcstValue": v}
|
||||
for h in range(24) for c, v in
|
||||
[("SKY", "1"), ("PTY", "4" if h >= 12 else "0"), ("POP", "60" if h >= 12 else "0"),
|
||||
("TMP", "5")]]
|
||||
items += [{"category": "TMN", "fcstDate": "20261119", "fcstTime": "0600", "fcstValue": "-1.0"},
|
||||
{"category": "TMX", "fcstDate": "20261119", "fcstTime": "1500", "fcstValue": "4.0"}]
|
||||
with patch.object(TestForecast, "_vilage_items", staticmethod(lambda: items)):
|
||||
result, _ = self._run({"days_ahead": 1}, monkeypatch)
|
||||
|
||||
assert "오전 맑음, 오후 소나기" in result.reply_text, result.reply_text
|
||||
|
||||
def test_asked_in_detail_the_short_term_day_has_humidity_and_the_strongest_wind(self, monkeypatch):
|
||||
result, _ = self._run({"days_ahead": 1, "detail": True}, monkeypatch)
|
||||
|
||||
assert "습도 70%" in result.reply_text and "최대 바람 초속 4미터" in result.reply_text
|
||||
|
||||
def test_asked_in_detail_open_meteos_day_has_the_strongest_wind_and_the_rain(self, monkeypatch):
|
||||
result, calls = self._run({"days_ahead": 1, "detail": True}, monkeypatch, country_code="JP")
|
||||
|
||||
(p,) = [p for u, p in calls if "open-meteo.com/v1/forecast" in u]
|
||||
assert {"wind_speed_10m_max", "precipitation_sum"} <= set(p["daily"].split(","))
|
||||
assert "최대 바람 초속 5미터" in result.reply_text and "강수량 12.5mm" in result.reply_text
|
||||
|
||||
def test_the_schema_offers_detail(self):
|
||||
assert self.tool.inputSchema["properties"]["detail"]["type"] == "boolean"
|
||||
|
||||
|
||||
class TestDistrictPlaces:
|
||||
"""A district such as 부산 연제구 is found by OpenStreetMap's search (any language) when
|
||||
open-meteo's geocoder, which knows cities only, does not find it; the weather is for that spot."""
|
||||
|
||||
KEY = "kma-test-key-123"
|
||||
|
||||
def setup_method(self):
|
||||
self.tool = WeatherTool()
|
||||
self.context = Mock(spec=ToolContext)
|
||||
self.context.user_print = Mock()
|
||||
self.context.cfg = Mock()
|
||||
self.context.cfg.location_name = None
|
||||
self.context.redacted_text = ""
|
||||
|
||||
@staticmethod
|
||||
def _ok(payload):
|
||||
r = Mock(status_code=200, raise_for_status=Mock())
|
||||
r.json.return_value = payload
|
||||
return r
|
||||
|
||||
def _routes(self, calls, osm=None, osm_fails=False):
|
||||
def get(url, *a, **k):
|
||||
params = k.get("params") or {}
|
||||
calls.append((url, params, k.get("headers") or {}))
|
||||
if "geocoding-api.open-meteo.com" in url:
|
||||
return self._ok({})
|
||||
if "nominatim.openstreetmap.org" in url:
|
||||
if osm_fails:
|
||||
raise requests.exceptions.Timeout("timed out")
|
||||
return self._ok(osm if osm is not None else [{
|
||||
"lat": "35.1762", "lon": "129.0797", "name": "연제구", "addresstype": "borough",
|
||||
"address": {"borough": "연제구", "city": "부산광역시", "country_code": "kr"}}])
|
||||
if "getUltraSrtNcst" in url:
|
||||
return self._ok({"response": {"header": {"resultCode": "00"}, "body": {"items": {"item": [
|
||||
{"category": c, "obsrValue": v} for c, v in
|
||||
[("PTY", "0"), ("REH", "60"), ("T1H", "8.2"), ("WSD", "3.1")]]}}}})
|
||||
if "getUltraSrtFcst" in url:
|
||||
return self._ok({"response": {"header": {"resultCode": "00"}, "body": {"items": {"item": [
|
||||
{"category": "SKY", "fcstDate": "20261118", "fcstTime": "1200", "fcstValue": "1"}]}}}})
|
||||
assert "api.open-meteo.com/v1/forecast" in url, url
|
||||
return self._ok({"current": {"temperature_2m": 11.0, "weather_code": 0}})
|
||||
return get
|
||||
|
||||
@patch('src.jarvis.tools.builtin.weather._romanise_place')
|
||||
def test_a_district_gets_its_own_spots_weather_from_kma(self, mock_romanise, monkeypatch):
|
||||
from src.jarvis.tools.builtin.weather import _kma_grid
|
||||
monkeypatch.setenv("JARVIS_KMA_API_KEY", self.KEY)
|
||||
calls = []
|
||||
with patch('requests.get', side_effect=self._routes(calls)):
|
||||
result = self.tool.run({"location": "부산 연제구"}, self.context)
|
||||
|
||||
assert result.success is True
|
||||
assert result.reply_text.startswith("지금 부산 연제구 날씨는 맑음") and "기온 8도" in result.reply_text
|
||||
kma = [p for u, p, _ in calls if "apihub.kma.go.kr" in u]
|
||||
assert kma and all((p["nx"], p["ny"]) == _kma_grid(35.1762, 129.0797) for p in kma)
|
||||
mock_romanise.assert_not_called()
|
||||
|
||||
def test_the_place_search_asks_for_one_place_with_its_country_and_names_the_app(self, monkeypatch):
|
||||
monkeypatch.delenv("JARVIS_KMA_API_KEY", raising=False)
|
||||
calls = []
|
||||
with patch('requests.get', side_effect=self._routes(calls)):
|
||||
self.tool.run({"location": "부산 연제구"}, self.context)
|
||||
|
||||
((_, params, headers),) = [c for c in calls if "nominatim.openstreetmap.org" in c[0]]
|
||||
assert params["q"] == "부산 연제구" and params["limit"] == 1 and params["addressdetails"] == 1
|
||||
assert "jarvis" in headers.get("User-Agent", "").lower()
|
||||
|
||||
@pytest.mark.parametrize("osm,osm_fails", [([], False), (None, True), ({"error": "x"}, False)])
|
||||
@patch('src.jarvis.tools.builtin.weather._romanise_place', return_value=None)
|
||||
def test_when_the_place_search_finds_nothing_or_fails_the_place_is_not_found(
|
||||
self, _rom, osm, osm_fails, monkeypatch):
|
||||
monkeypatch.delenv("JARVIS_KMA_API_KEY", raising=False)
|
||||
calls = []
|
||||
with patch('requests.get', side_effect=self._routes(calls, osm=osm, osm_fails=osm_fails)):
|
||||
result = self.tool.run({"location": "없는 동네"}, self.context)
|
||||
|
||||
assert result.success is False and "could not find" in result.reply_text.lower()
|
||||
|
||||
@patch('src.jarvis.tools.builtin.weather._romanise_place')
|
||||
def test_a_non_latin_city_name_is_not_matched_loosely_by_open_meteo(self, mock_romanise, monkeypatch):
|
||||
"""Live 2026-11-18: open-meteo matched "부산" to a village called Pusan 140 km from Busan."""
|
||||
monkeypatch.delenv("JARVIS_KMA_API_KEY", raising=False)
|
||||
calls = []
|
||||
osm = [{"lat": "35.1799", "lon": "129.0752", "name": "부산광역시", "address": {"country_code": "kr"}}]
|
||||
with patch('requests.get', side_effect=self._routes(calls, osm=osm)):
|
||||
result = self.tool.run({"location": "부산"}, self.context)
|
||||
|
||||
assert result.reply_text.startswith("지금 부산 날씨는")
|
||||
assert not any("geocoding-api.open-meteo.com" in u for u, _, _ in calls)
|
||||
(_, p, _), = [c for c in calls if "api.open-meteo.com/v1/forecast" in c[0]]
|
||||
assert (p["latitude"], p["longitude"]) == (35.1799, 129.0752)
|
||||
mock_romanise.assert_not_called()
|
||||
|
||||
def test_a_latin_name_open_meteo_knows_does_not_ask_openstreetmap(self, monkeypatch):
|
||||
monkeypatch.delenv("JARVIS_KMA_API_KEY", raising=False)
|
||||
calls = []
|
||||
base = self._routes(calls)
|
||||
|
||||
def get(url, *a, **k):
|
||||
if "geocoding-api.open-meteo.com" in url:
|
||||
calls.append((url, k.get("params"), {}))
|
||||
return self._ok({"results": [{"latitude": 51.5, "longitude": -0.12, "name": "London",
|
||||
"country_code": "GB"}]})
|
||||
return base(url, *a, **k)
|
||||
with patch('requests.get', side_effect=get):
|
||||
result = self.tool.run({"location": "London"}, self.context)
|
||||
|
||||
assert result.success and not any("nominatim" in u for u, _, _ in calls)
|
||||
|
||||
|
||||
|
||||
def test_the_day_schema_gives_each_coming_weekdays_days_ahead_from_today():
|
||||
"""The model is handed the count instead of working it out (qwen3:8b counted a Wednesday's weekend as 2)."""
|
||||
today = datetime.now()
|
||||
text = WeatherTool().inputSchema["properties"]["days_ahead"]["description"]
|
||||
saturday = (5 - today.weekday()) % 7 or 7
|
||||
assert f"From today, {today.strftime('%A')}:" in text
|
||||
assert f"{(today + timedelta(days=saturday)).strftime('%A')} {saturday}" in text
|
||||
|
||||
Reference in New Issue
Block a user