Spaces:
Build error
Build error
| """ | |
| Health check and system info endpoints. | |
| Responsabilidad: Verificar el estado de la API y servicios. | |
| """ | |
| from fastapi import APIRouter, Depends | |
| from typing import Dict, Any | |
| from app.api.dependencies import get_forecast_model | |
| from app.domain.interfaces.forecast_model import IForecastModel | |
| from app.infrastructure.config.settings import get_settings | |
| from app.utils.logger import setup_logger | |
| logger = setup_logger(__name__) | |
| settings = get_settings() | |
| router = APIRouter(prefix="/health", tags=["Health"]) | |
| async def health_check( | |
| model: IForecastModel = Depends(get_forecast_model) | |
| ): | |
| """ | |
| Health check endpoint. | |
| Verifica que la API est茅 funcionando y el modelo est茅 cargado. | |
| Returns: | |
| Estado de la API y informaci贸n del modelo | |
| """ | |
| try: | |
| model_info = model.get_model_info() | |
| return { | |
| "status": "ok", | |
| "version": settings.api_version, | |
| "model": model_info, | |
| "message": "Chronos-2 API is running" | |
| } | |
| except Exception as e: | |
| logger.error(f"Health check failed: {e}") | |
| return { | |
| "status": "error", | |
| "version": settings.api_version, | |
| "error": str(e), | |
| "message": "API is running but model is not available" | |
| } | |
| async def system_info(): | |
| """ | |
| System information endpoint. | |
| Returns: | |
| Informaci贸n sobre la arquitectura y configuraci贸n | |
| """ | |
| return { | |
| "api": { | |
| "title": settings.api_title, | |
| "version": settings.api_version, | |
| "description": settings.api_description | |
| }, | |
| "architecture": { | |
| "style": "Clean Architecture", | |
| "principles": "SOLID", | |
| "layers": [ | |
| "Presentation (API)", | |
| "Application (Use Cases)", | |
| "Domain (Business Logic)", | |
| "Infrastructure (External Services)" | |
| ] | |
| }, | |
| "model": { | |
| "id": settings.model_id, | |
| "device": settings.device_map | |
| }, | |
| "endpoints": { | |
| "docs": "/docs", | |
| "health": "/health", | |
| "forecast": "/forecast", | |
| "anomaly": "/anomaly", | |
| "backtest": "/backtest" | |
| } | |
| } | |