Add dedicated page for running Ollama models

This commit is contained in:
Luca Sacchi Ricciardi
2026-04-25 11:36:05 +02:00
parent 2f591e55ce
commit 1aee51b0d6
6 changed files with 327 additions and 0 deletions
+48
View File
@@ -119,6 +119,54 @@ async def get_models():
detail="Errore nel recupero dei modelli"
)
@router.get("/models/running")
async def get_running_models() -> Dict[str, Any]:
"""
Recupera i modelli attualmente residenti in memoria, equivalenti a `ollama ps`.
Returns:
Dict[str, Any]: Payload con modelli running e conteggio
"""
try:
response = requests.get(
f"{settings.OLLAMA_HOST}/api/ps",
timeout=settings.OLLAMA_TIMEOUT
)
if response.status_code != 200:
raise HTTPException(
status_code=502,
detail="Ollama non disponibile"
)
data = response.json()
models_data = data.get("models", [])
return {
"models": models_data,
"total": len(models_data)
}
except requests.exceptions.Timeout:
raise HTTPException(
status_code=504,
detail="Timeout: Ollama non ha risposto in tempo"
)
except requests.exceptions.ConnectionError:
raise HTTPException(
status_code=502,
detail="Impossible connettersi a Ollama"
)
except HTTPException:
raise
except Exception as e:
logger.error(f"Error fetching running models: {e}")
raise HTTPException(
status_code=500,
detail="Errore nel recupero dei modelli residenti"
)
@router.get("/models/{model_name}", response_model=ModelInfo)
async def get_model(model_name: str):
"""