feat: causal lab — debug endpoint + error display in UI
This commit is contained in:
@@ -320,6 +320,27 @@ class AnalyzeRequest(BaseModel):
|
||||
|
||||
# ── Endpoints ─────────────────────────────────────────────────────────────────
|
||||
|
||||
@router.get("/api/causal-lab/debug")
|
||||
def debug_causal():
|
||||
"""Endpoint de diagnostic — vérifie que causal_graphs est bien chargé."""
|
||||
try:
|
||||
from services.database import get_conn
|
||||
from services.causal_graphs import BUILT_IN_TEMPLATES, init_tables, seed_templates
|
||||
conn = get_conn()
|
||||
init_tables(conn)
|
||||
seed_templates(conn)
|
||||
count = conn.execute("SELECT COUNT(*) FROM causal_graph_templates").fetchone()[0]
|
||||
conn.close()
|
||||
return {
|
||||
"built_in_templates": len(BUILT_IN_TEMPLATES),
|
||||
"db_templates": count,
|
||||
"status": "ok",
|
||||
}
|
||||
except Exception as e:
|
||||
import traceback
|
||||
return {"status": "error", "error": str(e), "trace": traceback.format_exc()}
|
||||
|
||||
|
||||
@router.get("/api/causal-lab/templates")
|
||||
def list_templates(category: str = Query("")):
|
||||
try:
|
||||
@@ -329,8 +350,11 @@ def list_templates(category: str = Query("")):
|
||||
_init(conn)
|
||||
data = get_templates(conn, category)
|
||||
conn.close()
|
||||
print(f"[causal_lab] list_templates → {len(data)} templates (category={category!r})", flush=True)
|
||||
return data
|
||||
except Exception as e:
|
||||
import traceback
|
||||
print(f"[causal_lab] list_templates ERROR: {e}\n{traceback.format_exc()}", flush=True)
|
||||
logger.error(f"[causal_lab] list_templates: {e}")
|
||||
raise HTTPException(500, str(e))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user