RayMelius commited on
Commit
b17b9e6
·
1 Parent(s): 7c55124

Add /ai/debug endpoint for live LLM diagnostics

Browse files
Files changed (1) hide show
  1. dashboard/dashboard.py +34 -0
dashboard/dashboard.py CHANGED
@@ -577,6 +577,40 @@ def trigger_ai_insight():
577
  return jsonify({"status": "ok", "message": "Insight generation started"})
578
 
579
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
580
  @app.route("/session/mode", methods=["POST"])
581
  def session_mode():
582
  try:
 
577
  return jsonify({"status": "ok", "message": "Insight generation started"})
578
 
579
 
580
+ @app.route("/ai/debug")
581
+ def ai_debug():
582
+ """Synchronous LLM test — returns raw API result for debugging."""
583
+ result = {
584
+ "hf_token_set": bool(HF_TOKEN),
585
+ "hf_token_prefix": HF_TOKEN[:8] + "…" if HF_TOKEN else None,
586
+ "hf_model": HF_MODEL,
587
+ "hf_url": HF_URL,
588
+ "ollama_host": OLLAMA_HOST,
589
+ }
590
+ if not HF_TOKEN:
591
+ result["error"] = "HF_TOKEN not set"
592
+ return jsonify(result)
593
+ try:
594
+ r = requests.post(
595
+ HF_URL,
596
+ headers={"Authorization": f"Bearer {HF_TOKEN}",
597
+ "Content-Type": "application/json"},
598
+ json={"model": HF_MODEL,
599
+ "messages": [{"role": "user", "content": "Reply with exactly: OK"}],
600
+ "max_tokens": 10},
601
+ timeout=30,
602
+ )
603
+ result["http_status"] = r.status_code
604
+ result["response_body"] = r.text[:500]
605
+ try:
606
+ result["response_json"] = r.json()
607
+ except Exception:
608
+ pass
609
+ except Exception as e:
610
+ result["exception"] = str(e)
611
+ return jsonify(result)
612
+
613
+
614
  @app.route("/session/mode", methods=["POST"])
615
  def session_mode():
616
  try: