Spaces:
Sleeping
Sleeping
| """ | |
| Cache Statistics Endpoint | |
| Provides real-time statistics about the model cache. | |
| """ | |
| from fastapi import APIRouter | |
| from app.core.model_cache import model_cache | |
| router = APIRouter(prefix="/cache", tags=["cache"]) | |
| async def get_cache_stats(): | |
| """Get model cache statistics""" | |
| return model_cache.get_stats() | |
| async def clear_cache(): | |
| """Clear all cached models""" | |
| await model_cache.clear() | |
| return {"message": "Cache cleared successfully"} | |
| async def preload_model(model_name: str): | |
| """Preload a model into cache""" | |
| from app.core.slm_registry import slm_registry | |
| from app.engines.micro_slm import MicroSLMEngine | |
| micro_slm_info = slm_registry.get_model(model_name) | |
| if not micro_slm_info: | |
| return {"error": f"Model {model_name} not found in registry"} | |
| async def load_micro_slm(): | |
| engine = MicroSLMEngine( | |
| name=model_name, | |
| model_path=micro_slm_info.model_path | |
| ) | |
| await engine.initialize() | |
| return engine | |
| await model_cache.preload(model_name, load_micro_slm) | |
| return {"message": f"Model {model_name} preloaded successfully"} | |