Spaces:
Sleeping
Sleeping
File size: 1,285 Bytes
f9adcbf |
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 |
"""
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"])
@router.get("/stats")
async def get_cache_stats():
"""Get model cache statistics"""
return model_cache.get_stats()
@router.post("/clear")
async def clear_cache():
"""Clear all cached models"""
await model_cache.clear()
return {"message": "Cache cleared successfully"}
@router.post("/preload/{model_name}")
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"}
|