Spaces:
Running
Running
File size: 3,498 Bytes
0231daa 65e4649 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 155ad69 0231daa fa90c98 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 0231daa 3ab8523 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
"""
Health check and system information endpoints.
This module provides routes for monitoring the API health
and getting system information.
"""
from typing import Dict, Any
from fastapi import APIRouter, Depends
from loguru import logger
from src.models.schemas import RootResponse, HealthStatus
from src.core.manager import ModelManager
from src.api.dependencies import get_model_manager
from src.config.settings import get_settings
router = APIRouter(tags=["system"])
@router.get(
"/",
response_model=RootResponse,
summary="API root",
description="Get basic API information",
)
async def root(settings=Depends(get_settings)):
"""
API root endpoint.
Returns basic information about the API including
version and documentation URL.
Args:
settings: Application settings
Returns:
RootResponse with API information
"""
return RootResponse(
message=f"{settings.APP_NAME}",
version=settings.VERSION,
docs_url="https://fahmiaziz-api-embedding.hf.space/docs",
)
@router.get(
"/health",
response_model=HealthStatus,
summary="Health check",
description="Check API health status",
)
async def health_check(manager: ModelManager = Depends(get_model_manager)):
"""
Health check endpoint.
Returns the current health status of the API including:
- Overall status (ok/error)
- Total configured models
- Currently loaded models
- Startup completion status
Args:
manager: Model manager dependency
Returns:
HealthStatus with health information
"""
try:
memory_info = manager.get_memory_usage()
return HealthStatus(
status="ok",
total_models=memory_info["total_available"],
loaded_models=memory_info["loaded_count"],
startup_complete=memory_info["preload_complete"],
)
except Exception:
logger.exception("Health check failed")
return HealthStatus(
status="error", total_models=0, loaded_models=0, startup_complete=False
)
@router.get(
"/info",
summary="System information",
description="Get detailed system and cache information",
)
async def system_info(
manager: ModelManager = Depends(get_model_manager),
settings=Depends(get_settings),
) -> Dict[str, Any]:
"""
Get detailed system information.
Returns comprehensive information about:
- API configuration
- Model statistics
- System settings
Args:
manager: Model manager dependency
cache: Cache dependency (if enabled)
settings: Application settings
Returns:
Dictionary with system information
"""
try:
memory_info = manager.get_memory_usage()
info = {
"api": {
"name": settings.APP_NAME,
"version": settings.VERSION,
"environment": settings.ENVIRONMENT,
"debug": settings.DEBUG,
},
"models": {
"total": memory_info["total_available"],
"loaded": memory_info["loaded_count"],
"preload_complete": memory_info["preload_complete"],
"loaded_models": memory_info["loaded_models"],
},
}
return info
except Exception as e:
logger.exception("Failed to get system info")
return {"error": "Failed to retrieve system information", "detail": str(e)}
|