This commit is contained in:
Dobromir Popov
2026-07-08 21:19:20 +03:00
parent 0ffd195fec
commit 52629d7762
2 changed files with 45 additions and 11 deletions

View File

@@ -277,7 +277,7 @@ const esc = s => String(s).replace(/[&<>"]/g,
const usdt = v => (Math.round(v * 1e6) / 1e6).toFixed(6); const usdt = v => (Math.round(v * 1e6) / 1e6).toFixed(6);
const tps = v => (v === null || v === undefined) ? "?" : (Math.round(v * 10) / 10).toFixed(1); const tps = v => (v === null || v === undefined) ? "?" : (Math.round(v * 10) / 10).toFixed(1);
const copies = v => (v === null || v === undefined) ? "?" : Number(v).toFixed(2); const copies = v => (v === null || v === undefined) ? "?" : Number(v).toFixed(2);
const hp = v => (v === null || v === undefined) ? "?HP" : `${Number(v).toFixed(1)}HP`; const hp = v => (v === null || v === undefined) ? "?HP" : `${copies(v)}HP`;
const short = (s, n=14) => { s = String(s); return s.length > n ? s.slice(0, 6) + "…" + s.slice(-5) : s; }; const short = (s, n=14) => { s = String(s); return s.length > n ? s.slice(0, 6) + "…" + s.slice(-5) : s; };
function modelAliasKey(value) { function modelAliasKey(value) {
@@ -317,6 +317,33 @@ function resolveModelGroup(node, aliasMap) {
return aliasMap.get(key) || key || "?"; return aliasMap.get(key) || key || "?";
} }
function modelLookupKeys(model) {
const keys = new Set();
for (const value of [model.id, model.name, model.hf_repo, ...(model.aliases || [])]) {
if (!value) continue;
keys.add(String(value));
keys.add(modelAliasKey(value));
}
return keys;
}
function modelServedCopiesFromMap(map, model) {
const nodes = (map && map.nodes) || [];
if (!nodes.length) return model.servedCopies ?? 0;
const aliasMap = buildModelAliasMap(map);
const targetKeys = modelLookupKeys(model);
let best = model.servedCopies ?? 0;
for (const node of nodes) {
const nodeKeys = [resolveModelGroup(node, aliasMap), node.hf_repo, node.model]
.filter(Boolean)
.flatMap(value => [String(value), modelAliasKey(value)]);
if (!nodeKeys.some(key => targetKeys.has(key))) continue;
const served = node.model_supply && node.model_supply.served_model_copies;
if (served !== null && served !== undefined) best = Math.max(best, served);
}
return best;
}
async function fetchJson(path) { async function fetchJson(path) {
try { try {
const headers = {}; const headers = {};
@@ -833,6 +860,7 @@ let accountApiKeys = [];
let accountUsageRecords = []; let accountUsageRecords = [];
let lastStats = null; let lastStats = null;
let lastRouting = null; let lastRouting = null;
let lastNetworkMap = null;
let availableModels = []; let availableModels = [];
let chatHistory = []; let chatHistory = [];
let chatBusy = false; let chatBusy = false;
@@ -1634,15 +1662,20 @@ async function refresh() {
const [summary, settlements, wallets] = adminData; const [summary, settlements, wallets] = adminData;
lastStats = stats; lastStats = stats;
lastRouting = routing; lastRouting = routing;
availableModels = ((models && models.data) || []).map(model => ({ lastNetworkMap = map;
id: model.id, availableModels = ((models && models.data) || []).map(model => {
name: model.name || model.id, const entry = {
hf_repo: model.hf_repo, id: model.id,
recommended: Boolean(model.recommended), name: model.name || model.id,
aliases: model.aliases || [], hf_repo: model.hf_repo,
coverage: model.shard_coverage_percentage, recommended: Boolean(model.recommended),
servedCopies: model.served_model_copies, aliases: model.aliases || [],
})).filter(model => model.id); coverage: model.shard_coverage_percentage,
servedCopies: model.served_model_copies,
};
entry.servedCopies = modelServedCopiesFromMap(map, entry);
return entry;
}).filter(model => model.id);
renderHive(raft); renderHive(raft);
renderNodes(map); renderNodes(map);
renderBilling(summary); renderBilling(summary);

View File

@@ -63,11 +63,12 @@ def test_dashboard_chat_model_selector_shows_health_and_speed():
tracker.stop() tracker.stop()
assert "chatModelHealthHp" in html assert "chatModelHealthHp" in html
assert "modelServedCopiesFromMap" in html
assert "chatModelTypicalTps" in html assert "chatModelTypicalTps" in html
assert "chatModelOptionLabel" in html assert "chatModelOptionLabel" in html
assert "findRoutingForModel" in html assert "findRoutingForModel" in html
assert "tok/s" in html assert "tok/s" in html
assert "0.0HP" in html or "toFixed(1)}HP" in html assert "toFixed(2)}HP" in html or '${copies(v)}HP' in html
def test_dashboard_chat_sessions_use_delegated_handlers(): def test_dashboard_chat_sessions_use_delegated_handlers():