Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions gui/src/pages/use-dashboard-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ type CachedOverview = {

type MaMode = "v1" | "default" | "v2";

export function groupDashboardModels(models: ModelInfo[]): Array<[string, ModelInfo[]]> {
const groups = new Map<string, ModelInfo[]>();
for (const model of models) {
const rows = groups.get(model.provider);
if (rows) rows.push(model);
else groups.set(model.provider, [model]);
}
return [...groups.entries()].sort(([a], [b]) => a.localeCompare(b));
}

function controlsCacheKey(apiBase: string): string {
return `${CONTROLS_CACHE_PREFIX}${apiBase}`;
}
Expand Down Expand Up @@ -436,11 +446,7 @@ export function useDashboardData(apiBase: string) {
}, [updatePoll.data]);
/* eslint-enable react-hooks/set-state-in-effect */

const grouped = useMemo(() => {
const g: Record<string, ModelInfo[]> = {};
for (const m of models) (g[m.provider] ??= []).push(m);
return Object.entries(g).sort(([a], [b]) => a.localeCompare(b));
}, [models]);
const grouped = useMemo(() => groupDashboardModels(models), [models]);
const filteredGroups = useMemo(() => {
const q = modelQuery.trim().toLowerCase();
if (!q) return grouped;
Expand Down
17 changes: 17 additions & 0 deletions gui/tests/dashboard-model-grouping.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from "bun:test";
import { groupDashboardModels } from "../src/pages/use-dashboard-data";

test("Dashboard groups models whose provider names match object prototype properties", () => {
const models = [
{ id: "proto-model", provider: "__proto__" },
{ id: "constructor-model", provider: "constructor" },
{ id: "string-model", provider: "toString" },
{ id: "second-proto-model", provider: "__proto__" },
];

expect(groupDashboardModels(models)).toEqual([
["__proto__", [models[0], models[3]]],
["constructor", [models[1]]],
["toString", [models[2]]],
]);
});
Loading