wrolpi/modules/ai
Roland ced78e181f
ai: ground answers in a live library map, budget the context
Response-quality work, all aimed at giving the model enough context to
answer accurately:

- Every chat's system prompt now carries a live library map (today's
  date, counts, and the exact names of channels, domains, zims, and
  inventories, capped and cached 60s).  Exact spellings are in context
  before the first token, and the list_collections round-trip — minutes
  on slow hardware — is usually unnecessary.
- The request is budgeted against the model's real context: oldest
  turns are trimmed first, the current question is never dropped, and
  an over-budget turn gets a clear "start a new conversation" error
  instead of a silently truncated prompt.  cache_prompt reuses the KV
  cache for the stable prefix, which is most of the latency on a Pi.
- context_size plumbing fixed: selecting a model adopts its catalog
  default (the 4B was running at 8k instead of 16k), and llama-server
  runs --parallel 1 so the single user gets the whole context.
- temperature is configurable in ai.yaml (default 0.3 — small models
  call tools far more reliably near 0.2-0.3 than at server defaults).
- One worked tool-use example per mode is prepended to every
  conversation; small models imitate far better than they obey.
- scripts/ai_eval.py scores the assistant against a live WROLPi on
  mechanical checks (finished, called the right tool first, included a
  WROLPi link, no external URLs) so prompt changes stop being validated
  by anecdote.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-24 14:09:55 -06:00
..
test ai: ground answers in a live library map, budget the context 2026-09-24 14:09:55 -06:00
__init__.py ai: package llama-server for all three deployments, with idle unload 2026-09-24 14:09:54 -06:00
agent.py ai: the /api/chat agent loop — SSE streaming, modes, tool execution 2026-09-24 14:09:54 -06:00
api.py ai: ground answers in a live library map, budget the context 2026-09-24 14:09:55 -06:00
catalog.py ai: ground answers in a live library map, budget the context 2026-09-24 14:09:55 -06:00
chat.py ai: ground answers in a live library map, budget the context 2026-09-24 14:09:55 -06:00
config.py ai: ground answers in a live library map, budget the context 2026-09-24 14:09:55 -06:00
conftest.py ai: ai.yaml config, model catalog, and the GGUF downloader 2026-09-24 14:09:53 -06:00
context.py ai: ground answers in a live library map, budget the context 2026-09-24 14:09:55 -06:00
controller_client.py ai: package llama-server for all three deployments, with idle unload 2026-09-24 14:09:54 -06:00
downloader.py ai: ai.yaml config, model catalog, and the GGUF downloader 2026-09-24 14:09:53 -06:00
errors.py ai: system endpoints — aggregate status, services, logs, disks 2026-09-24 14:09:53 -06:00
help_docs.py ai: live-chat fixes from first real-model run 2026-09-24 14:09:55 -06:00
lib.py ai: ground the librarian — collection links, retry hints, no source URLs 2026-09-24 14:09:55 -06:00
modes.py ai: ground answers in a live library map, budget the context 2026-09-24 14:09:55 -06:00
schema.py ai: the /api/chat agent loop — SSE streaming, modes, tool execution 2026-09-24 14:09:54 -06:00
service.py ai: package llama-server for all three deployments, with idle unload 2026-09-24 14:09:54 -06:00