Add overall metrics to the hallucination detector
This commit is contained in:
@@ -12,6 +12,7 @@ from collections import defaultdict
|
||||
from loguru import logger
|
||||
from dotenv import load_dotenv
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
from middleware.monitoring_middleware import monitoring_middleware
|
||||
|
||||
# Load environment variables
|
||||
@@ -175,6 +176,62 @@ async def health():
|
||||
"""Health check endpoint."""
|
||||
return health_check()
|
||||
|
||||
@app.get("/health/database")
|
||||
async def database_health_check():
|
||||
"""Database health check endpoint including persona tables verification."""
|
||||
try:
|
||||
from services.database import get_db_session
|
||||
from models.persona_models import WritingPersona, PlatformPersona, PersonaAnalysisResult, PersonaValidationResult
|
||||
|
||||
session = get_db_session()
|
||||
if not session:
|
||||
return {"status": "error", "message": "Could not get database session"}
|
||||
|
||||
# Test all persona tables
|
||||
tables_status = {}
|
||||
try:
|
||||
session.query(WritingPersona).first()
|
||||
tables_status["writing_personas"] = "ok"
|
||||
except Exception as e:
|
||||
tables_status["writing_personas"] = f"error: {str(e)}"
|
||||
|
||||
try:
|
||||
session.query(PlatformPersona).first()
|
||||
tables_status["platform_personas"] = "ok"
|
||||
except Exception as e:
|
||||
tables_status["platform_personas"] = f"error: {str(e)}"
|
||||
|
||||
try:
|
||||
session.query(PersonaAnalysisResult).first()
|
||||
tables_status["persona_analysis_results"] = "ok"
|
||||
except Exception as e:
|
||||
tables_status["persona_analysis_results"] = f"error: {str(e)}"
|
||||
|
||||
try:
|
||||
session.query(PersonaValidationResult).first()
|
||||
tables_status["persona_validation_results"] = "ok"
|
||||
except Exception as e:
|
||||
tables_status["persona_validation_results"] = f"error: {str(e)}"
|
||||
|
||||
session.close()
|
||||
|
||||
# Check if all tables are ok
|
||||
all_ok = all(status == "ok" for status in tables_status.values())
|
||||
|
||||
return {
|
||||
"status": "healthy" if all_ok else "warning",
|
||||
"message": "Database connection successful" if all_ok else "Some persona tables may have issues",
|
||||
"persona_tables": tables_status,
|
||||
"timestamp": datetime.utcnow().isoformat()
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": f"Database health check failed: {str(e)}",
|
||||
"timestamp": datetime.utcnow().isoformat()
|
||||
}
|
||||
|
||||
# Onboarding status endpoints
|
||||
@app.get("/api/onboarding/status")
|
||||
async def onboarding_status():
|
||||
|
||||
Reference in New Issue
Block a user