Files
javis_bot/src/jarvis/utils/time_context.py
javis-bot 46e4e75d05 feat(voice_worker): a short voice prompt and one judgement before each v2 answer
- compact_prompt: the v2 persona in a tenth of v1's words, answers as short as
  possible, the full tool guidance only on turns with a data tool. A greeting's
  reply prompt went from about 4,500 to 1,400 tokens on Strata.
- intent_judge: the tool router judges whether the turn needs tools; the
  planner runs only when it does. prepare_intent runs the pick ahead on a
  partial transcript (worker message prepare), and the reply reuses it.
- Without stream_browser the screen-share tools are not offered.
- The time context carries the 12-hour form (10:37 was read as pm).
- A <tool_call> block written as the reply is parsed as a call, not spoken.

Evals (Qwen3.6 on Strata, EVAL_COMPACT_PROMPT=1 EVAL_INTENT_JUDGE=1):
221 passed, 4 failed (known failures); new evals/test_voice_reply_length.py
(v2 answers 234 chars against v1's 416) and test_reply_language_default.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 12:25:15 +09:00

53 lines
1.8 KiB
Python

"""Format the current time for injection into the LLM system context.
Prefers the user's local timezone (derived from location) so the assistant can
answer "what time is it?" in the form the user expects, instead of UTC.
"""
from datetime import datetime, timezone
from typing import Optional
try:
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
except ImportError: # pragma: no cover - Python < 3.9
ZoneInfo = None # type: ignore[assignment]
ZoneInfoNotFoundError = Exception # type: ignore[assignment,misc]
# The 12-hour form beside the 24-hour one: field run 2026-11-12 (Qwen3.6, Korean) read 10:37 as
# 오후 (pm) 4 times of 4 with the short v2 prompt, and as 오전 (am) every time with it given.
_UTC_FORMAT = "%A, %B %d, %Y at %H:%M (%I:%M %p) UTC"
_LOCAL_FORMAT = "%A, %B %d, %Y at %H:%M (%I:%M %p) %Z"
def format_time_context(
tz_name: Optional[str] = None,
*,
now_utc: Optional[datetime] = None,
) -> str:
"""Return a human-readable string describing the current time.
Resolution order:
1. ``tz_name`` via ``zoneinfo`` (when GeoIP exposes an IANA zone).
2. The OS local timezone (``datetime.astimezone()``).
3. UTC, as a last resort when neither zone can be named.
"""
now = now_utc if now_utc is not None else datetime.now(timezone.utc)
if tz_name and ZoneInfo is not None:
try:
local = now.astimezone(ZoneInfo(tz_name))
if local.tzname():
return local.strftime(_LOCAL_FORMAT)
except (ZoneInfoNotFoundError, KeyError, ValueError):
pass
try:
system_local = now.astimezone()
if system_local.tzname():
return system_local.strftime(_LOCAL_FORMAT)
except (ValueError, OSError):
pass
return now.strftime(_UTC_FORMAT)