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...
`;
try {
const response = await fetch("/api/v1/models/running");
if (!response.ok) {
throw new Error("Errore nel caricamento dei modelli residenti");
}
const data = await response.json();
const models = data.models || [];
this.renderStats(models);
this.renderRunningModels(models);
} catch (error) {
container.innerHTML = `
Errore nel caricamento di ollama ps
`;
this.renderStats([]);
console.error(error);
}
}
renderStats(models) {
const runningCountEl = document.getElementById("running-count");
const vramTotalEl = document.getElementById("vram-total");
const lastRefreshEl = document.getElementById("last-refresh");
const totalVram = models.reduce((sum, model) => sum + (model.size_vram || 0), 0);
if (runningCountEl) {
runningCountEl.textContent = String(models.length);
}
if (vramTotalEl) {
vramTotalEl.textContent = this.formatBytes(totalVram);
}
if (lastRefreshEl) {
lastRefreshEl.textContent = new Date().toLocaleString("it-IT");
}
}
renderRunningModels(models) {
const container = document.getElementById("running-models");
if (!container) {
return;
}
if (models.length === 0) {
container.innerHTML = `
Nessun modello residente in memoria al momento.
`;
return;
}
container.innerHTML = models
.map((model) => this.renderModelCard(model))
.join("");
}
renderModelCard(model) {
const name = this.escapeHtml(model.name || "unknown");
const modelId = this.escapeHtml(model.model || "-");
const size = this.formatBytes(model.size || 0);
const sizeVram = this.formatBytes(model.size_vram || 0);
const processor = this.escapeHtml(model.details?.processor || "-");
const expiresAt = model.expires_at ? this.formatDateTime(model.expires_at) : "-";
return `