Spaces:
Running

sankalphs commited on
Commit
1c2dd4b
·
1 Parent(s): f316f5a

fix: correct LLM model path default, fix chat 'error: format only' leak, surface load errors

Browse files

Root causes of LLM: OFFLINE + chat 'error: format only' on the Space:

1. agents.py defaulted MODEL_PATH to the old filename
'models/retro-alpha-nemotron-q4_k_m.gguf'. The actual GGUF file
is 'NVIDIA-Nemotron-3-Nano-4B.Q4_K_M.gguf'. When the model
download failed on the Space (slow network, token scope, or
timeout), MODEL_PATH stayed as the wrong default and get_llm()
raised FileNotFoundError -> _llm_status='error' -> UI OFFLINE.

2. mock_generate() returned the literal 'error: format only' for
any prompt that didn't match its keyword checks. The chat prompt
matched none, so the sentinel leaked to the UI (chat_reply's
'if not text' fallback never fired because the string was truthy).

Fixes:
- agents.py: correct MODEL_PATH default to the actual filename;
capture _llm_error with the exception type+message; print the
resolved model path and size on load
- mock_generate(): return '' for unknown prompts so per-feature
deterministic fallbacks (chat_reply, generate_insight) take over
instead of leaking a sentinel
- download_model.py: robust download that tries with token, then
anonymously, and ALWAYS returns the expected local path (never
raises) so get_llm() can report a precise 'model not found' error
- app.py /api/health: now returns llm_error, model_exists,
model_size_gb so the UI (and the user) can see exactly why the
LLM failed to load
- static/app.js: topbar shows the resolved model path on hover;
status line reports the error reason ('LLM offline (FileNotFoundError...).
Game still works, features use deterministic fallbacks')
- tests: regression checks that chat/insight never return
'error: format only'

110 tests pass: 12 unit + 42 FastAPI E2E + 56 Playwright.

5 files changed +117 -29
Files changed (5)
agents.py+34-11
app.py+6-1
download_model.py+47-16
static/app.js+16-1
tests/e2e_test.py+14