RayMelius Claude Sonnet 4.6 commited on
Commit
0dfc2b9
·
1 Parent(s): b17b9e6

Show config error in panel when HF_TOKEN not set

Browse files

- Detect missing token before spawning LLM thread and broadcast
a clear error message to the AI Analyst panel immediately
- Same warning shown on page load via ai_insights_init event
- /ai/debug already exposes hf_token_set flag for diagnostics

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. dashboard/dashboard.py +9 -2
dashboard/dashboard.py CHANGED
@@ -131,6 +131,11 @@ def _call_llm(prompt):
131
 
132
  def _generate_and_broadcast():
133
  """Background thread: call LLM, publish result via SSE + Kafka."""
 
 
 
 
 
134
  prompt = _build_market_prompt()
135
  text, source = _call_llm(prompt)
136
  if text:
@@ -145,7 +150,6 @@ def _generate_and_broadcast():
145
  pass
146
  print(f"[Dashboard/LLM] Insight published ({len(text)} chars, src={source})")
147
  else:
148
- # Surface the error in the panel
149
  err_insight = {"text": f"⚠️ LLM error: {source}", "source": "error", "timestamp": time.time()}
150
  broadcast_event("ai_insight", err_insight)
151
  print(f"[Dashboard/LLM] LLM failed: {source}")
@@ -682,7 +686,10 @@ def stream():
682
  f"event: init\ndata: "
683
  f"{json.dumps({'orders': list(orders), 'bbos': dict(bbos), 'trades': list(trades_cache)})}\n\n"
684
  )
685
- yield f"event: ai_insights_init\ndata: {json.dumps(list(ai_insights_cache))}\n\n"
 
 
 
686
  # Also send current session state
687
  if not session_state["active"]:
688
  _sess_status = "ended"
 
131
 
132
  def _generate_and_broadcast():
133
  """Background thread: call LLM, publish result via SSE + Kafka."""
134
+ if not HF_TOKEN and not OLLAMA_HOST:
135
+ err = {"text": "⚠️ No LLM configured. Set HF_TOKEN in Space Settings → Secrets.", "source": "config", "timestamp": time.time()}
136
+ broadcast_event("ai_insight", err)
137
+ return
138
+
139
  prompt = _build_market_prompt()
140
  text, source = _call_llm(prompt)
141
  if text:
 
150
  pass
151
  print(f"[Dashboard/LLM] Insight published ({len(text)} chars, src={source})")
152
  else:
 
153
  err_insight = {"text": f"⚠️ LLM error: {source}", "source": "error", "timestamp": time.time()}
154
  broadcast_event("ai_insight", err_insight)
155
  print(f"[Dashboard/LLM] LLM failed: {source}")
 
686
  f"event: init\ndata: "
687
  f"{json.dumps({'orders': list(orders), 'bbos': dict(bbos), 'trades': list(trades_cache)})}\n\n"
688
  )
689
+ init_insights = list(ai_insights_cache)
690
+ if not init_insights and not HF_TOKEN and not OLLAMA_HOST:
691
+ init_insights = [{"text": "⚠️ No LLM configured. Go to Space Settings → Secrets and add HF_TOKEN.", "source": "config", "timestamp": time.time()}]
692
+ yield f"event: ai_insights_init\ndata: {json.dumps(init_insights)}\n\n"
693
  # Also send current session state
694
  if not session_state["active"]:
695
  _sess_status = "ended"