fix: deterministic weather → one clean Korean sentence (no 'Celsius')

getWeather now returns only the Korean sentence (지금 <곳> 날씨는 <상태>, 기온 N도
(체감 M도)입니다) with no English/°C source. A deterministic weather path in the
engine returns it verbatim, bypassing the 7B which was rephrasing into multiple
sentences and leaking 'Celsius'.
This commit is contained in:
javis-bot
2026-06-14 22:46:03 +09:00
parent 54c3ce7d1b
commit c522e1b285
2 changed files with 43 additions and 11 deletions

View File

@@ -889,6 +889,37 @@ def _maybe_deterministic_site_search(text: str, db, cfg, language) -> Optional[s
return None
_WEATHER_INTENT_WORDS = (
"날씨", "기온", "더워", "더운", "추워", "추운", "비 와", "비와", "비 올",
"눈 와", "눈와", "weather", "temperature", "forecast",
)
def _maybe_deterministic_weather(text: str, db, cfg, language) -> Optional[str]:
"""Run getWeather directly and return its concise Korean sentence, bypassing
the chat model. The 7B otherwise re-synthesises the weather into multiple
sentences and leaks units ("25도 Celsius"); the tool already formats one
clean Korean sentence, so for a plain weather ask we just return it.
Fail-open: any problem returns None and the normal flow continues.
"""
try:
low = (text or "").lower()
if not any(w in low for w in _WEATHER_INTENT_WORDS):
return None
from ..tools.registry import run_tool_with_retries
res = run_tool_with_retries(
db=db, cfg=cfg, tool_name="getWeather", tool_args={},
system_prompt="", original_prompt="", redacted_text=redact(text),
max_retries=1, language=language,
)
if res and getattr(res, "success", False) and res.reply_text:
debug_log("deterministic weather executed", "tools")
return res.reply_text
except Exception as e: # noqa: BLE001
debug_log(f"deterministic weather failed (fail-open): {e}", "tools")
return None
def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
text: str, dialogue_memory: "DialogueMemory",
language: Optional[str] = None) -> Optional[str]:
@@ -920,6 +951,13 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
if _site_search_reply is not None:
return _site_search_reply
# Step 0.6: Deterministic weather — return getWeather's concise Korean
# sentence directly so the chat model can't rephrase it into multiple
# sentences or leak units.
_weather_reply = _maybe_deterministic_weather(text, db, cfg, language)
if _weather_reply is not None:
return _weather_reply
# Step 2: Check for recent dialogue context
recent_messages = []
is_new_conversation = True