Spaces:
Running
Running
fahmiaziz98
commited on
Commit
·
65e4649
1
Parent(s):
3ab8523
[DELETED]: router endpoint cache stats
Browse files- src/api/routers/health.py +1 -73
- src/config/settings.py +0 -5
src/api/routers/health.py
CHANGED
|
@@ -11,8 +11,7 @@ from loguru import logger
|
|
| 11 |
|
| 12 |
from src.models.schemas import RootResponse, HealthStatus
|
| 13 |
from src.core.manager import ModelManager
|
| 14 |
-
from src.
|
| 15 |
-
from src.api.dependencies import get_model_manager, get_cache_if_enabled
|
| 16 |
from src.config.settings import get_settings
|
| 17 |
|
| 18 |
|
|
@@ -91,7 +90,6 @@ async def health_check(manager: ModelManager = Depends(get_model_manager)):
|
|
| 91 |
)
|
| 92 |
async def system_info(
|
| 93 |
manager: ModelManager = Depends(get_model_manager),
|
| 94 |
-
cache: EmbeddingCache = Depends(get_cache_if_enabled),
|
| 95 |
settings=Depends(get_settings),
|
| 96 |
) -> Dict[str, Any]:
|
| 97 |
"""
|
|
@@ -100,7 +98,6 @@ async def system_info(
|
|
| 100 |
Returns comprehensive information about:
|
| 101 |
- API configuration
|
| 102 |
- Model statistics
|
| 103 |
-
- Cache statistics (if enabled)
|
| 104 |
- System settings
|
| 105 |
|
| 106 |
Args:
|
|
@@ -132,79 +129,10 @@ async def system_info(
|
|
| 132 |
"max_batch_size": settings.MAX_BATCH_SIZE,
|
| 133 |
"request_timeout": settings.REQUEST_TIMEOUT,
|
| 134 |
},
|
| 135 |
-
"cache": {"enabled": settings.ENABLE_CACHE},
|
| 136 |
}
|
| 137 |
|
| 138 |
-
# Add cache stats if enabled
|
| 139 |
-
if cache is not None:
|
| 140 |
-
info["cache"]["stats"] = cache.stats
|
| 141 |
-
|
| 142 |
return info
|
| 143 |
|
| 144 |
except Exception as e:
|
| 145 |
logger.exception("Failed to get system info")
|
| 146 |
return {"error": "Failed to retrieve system information", "detail": str(e)}
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
@router.get(
|
| 150 |
-
"/cache/stats",
|
| 151 |
-
summary="Cache statistics",
|
| 152 |
-
description="Get detailed cache statistics (if caching is enabled)",
|
| 153 |
-
)
|
| 154 |
-
async def cache_stats(
|
| 155 |
-
cache: EmbeddingCache = Depends(get_cache_if_enabled),
|
| 156 |
-
) -> Dict[str, Any]:
|
| 157 |
-
"""
|
| 158 |
-
Get cache statistics.
|
| 159 |
-
|
| 160 |
-
Returns detailed information about the embedding cache including:
|
| 161 |
-
- Current size
|
| 162 |
-
- Hit/miss counts
|
| 163 |
-
- Hit rate
|
| 164 |
-
- TTL configuration
|
| 165 |
-
|
| 166 |
-
Args:
|
| 167 |
-
cache: Cache dependency (if enabled)
|
| 168 |
-
|
| 169 |
-
Returns:
|
| 170 |
-
Dictionary with cache statistics or disabled message
|
| 171 |
-
"""
|
| 172 |
-
if cache is None:
|
| 173 |
-
return {"enabled": False, "message": "Caching is disabled"}
|
| 174 |
-
|
| 175 |
-
try:
|
| 176 |
-
return {"enabled": True, **cache.stats}
|
| 177 |
-
except Exception as e:
|
| 178 |
-
logger.exception("Failed to get cache stats")
|
| 179 |
-
return {"enabled": True, "error": str(e)}
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
@router.post(
|
| 183 |
-
"/cache/clear",
|
| 184 |
-
summary="Clear cache",
|
| 185 |
-
description="Clear all cached embeddings (if caching is enabled)",
|
| 186 |
-
)
|
| 187 |
-
async def clear_cache(
|
| 188 |
-
cache: EmbeddingCache = Depends(get_cache_if_enabled),
|
| 189 |
-
) -> Dict[str, Any]:
|
| 190 |
-
"""
|
| 191 |
-
Clear all cached embeddings.
|
| 192 |
-
|
| 193 |
-
This endpoint removes all entries from the cache, forcing
|
| 194 |
-
fresh computation for subsequent requests.
|
| 195 |
-
|
| 196 |
-
Args:
|
| 197 |
-
cache: Cache dependency (if enabled)
|
| 198 |
-
|
| 199 |
-
Returns:
|
| 200 |
-
Dictionary with operation status
|
| 201 |
-
"""
|
| 202 |
-
if cache is None:
|
| 203 |
-
return {"success": False, "message": "Caching is disabled"}
|
| 204 |
-
|
| 205 |
-
try:
|
| 206 |
-
cache.clear()
|
| 207 |
-
return {"success": True, "message": "Cache cleared successfully"}
|
| 208 |
-
except Exception as e:
|
| 209 |
-
logger.exception("Failed to clear cache")
|
| 210 |
-
return {"success": False, "error": str(e)}
|
|
|
|
| 11 |
|
| 12 |
from src.models.schemas import RootResponse, HealthStatus
|
| 13 |
from src.core.manager import ModelManager
|
| 14 |
+
from src.api.dependencies import get_model_manager
|
|
|
|
| 15 |
from src.config.settings import get_settings
|
| 16 |
|
| 17 |
|
|
|
|
| 90 |
)
|
| 91 |
async def system_info(
|
| 92 |
manager: ModelManager = Depends(get_model_manager),
|
|
|
|
| 93 |
settings=Depends(get_settings),
|
| 94 |
) -> Dict[str, Any]:
|
| 95 |
"""
|
|
|
|
| 98 |
Returns comprehensive information about:
|
| 99 |
- API configuration
|
| 100 |
- Model statistics
|
|
|
|
| 101 |
- System settings
|
| 102 |
|
| 103 |
Args:
|
|
|
|
| 129 |
"max_batch_size": settings.MAX_BATCH_SIZE,
|
| 130 |
"request_timeout": settings.REQUEST_TIMEOUT,
|
| 131 |
},
|
|
|
|
| 132 |
}
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
return info
|
| 135 |
|
| 136 |
except Exception as e:
|
| 137 |
logger.exception("Failed to get system info")
|
| 138 |
return {"error": "Failed to retrieve system information", "detail": str(e)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/config/settings.py
CHANGED
|
@@ -40,11 +40,6 @@ class Settings(BaseSettings):
|
|
| 40 |
MAX_BATCH_SIZE: int = 100 # Maximum texts per batch request
|
| 41 |
REQUEST_TIMEOUT: int = 30 # Request timeout in seconds
|
| 42 |
|
| 43 |
-
# Cache Configuration
|
| 44 |
-
ENABLE_CACHE: bool = True # Enable response caching (Phase 2)
|
| 45 |
-
CACHE_TTL: int = 3600 # Cache time-to-live in seconds
|
| 46 |
-
CACHE_MAX_SIZE: int = 1000 # Maximum cache entries
|
| 47 |
-
|
| 48 |
# Logging
|
| 49 |
LOG_LEVEL: str = "INFO" # DEBUG, INFO, WARNING, ERROR, CRITICAL
|
| 50 |
LOG_FILE: bool = False # Write logs to file
|
|
|
|
| 40 |
MAX_BATCH_SIZE: int = 100 # Maximum texts per batch request
|
| 41 |
REQUEST_TIMEOUT: int = 30 # Request timeout in seconds
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
# Logging
|
| 44 |
LOG_LEVEL: str = "INFO" # DEBUG, INFO, WARNING, ERROR, CRITICAL
|
| 45 |
LOG_FILE: bool = False # Write logs to file
|