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 = `
Failed to load ollama ps output
`;
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("en-US");
}
}
renderRunningModels(models) {
const container = document.getElementById("running-models");
if (!container) {
return;
}
if (models.length === 0) {
container.innerHTML = `
No models are currently loaded in memory.
`;
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 `