Output Ollama PS
+Caricamento modelli residenti...
+diff --git a/app/api/models.py b/app/api/models.py index 5991017..3830831 100644 --- a/app/api/models.py +++ b/app/api/models.py @@ -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): """ diff --git a/app/web/static/js/models-running.js b/app/web/static/js/models-running.js new file mode 100644 index 0000000..f5cf950 --- /dev/null +++ b/app/web/static/js/models-running.js @@ -0,0 +1,160 @@ +class RunningModelsPage { + constructor() { + this.init(); + } + + init() { + document.getElementById("refresh-btn")?.addEventListener("click", () => { + this.loadRunningModels(); + }); + + this.loadRunningModels(); + } + + async loadRunningModels() { + const container = document.getElementById("running-models"); + if (!container) { + return; + } + + container.innerHTML = ` +
Aggiornamento in corso...
+Errore nel caricamento di ollama ps
+Nessun modello residente in memoria al momento.
+${modelId}
+Dimensione modello
+${size}
+VRAM usata
+${sizeVram}
+Processor
+${processor}
+Scarico previsto
+${expiresAt}
+Vista dedicata all'output di ollama ps
+Caricamento modelli residenti...
+