mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
feat(admin-ui): fit the Models catalog table without horizontal scroll
The table had 11 columns and scrolled at 1280px, hiding p50, p95 and error rate. It now shows compact price, one token column and a short error header. Context window stays in the model chip hover, and the :free flag moves into the price cell.
This commit is contained in:
@@ -216,6 +216,12 @@ export function formatModelCostHover(inputUsd: number, outputUsd: number): strin
|
||||
return `in ${formatUsdPerMTok(inputUsd)} / out ${formatUsdPerMTok(outputUsd)} per MTok`
|
||||
}
|
||||
|
||||
/** formatModelPriceShort is the table-cell form of formatModelCostHover: "$1.00 / $2.00" (input / output per MTok). */
|
||||
export function formatModelPriceShort(inputUsd: number, outputUsd: number): string {
|
||||
if (inputUsd === 0 && outputUsd === 0) return 'free'
|
||||
return `${formatUsdPerMTok(inputUsd)} / ${formatUsdPerMTok(outputUsd)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* formatLatencyMs renders a millisecond average (admin.go's
|
||||
* adminLatencyView.avgTtfbMs/avgDurationMs — feat: latency panel) as a
|
||||
|
||||
@@ -154,7 +154,7 @@ describe('modelCatalogColumns: price column', () => {
|
||||
row: { original: testRow({ priceSource: 'litellm', inputPerMTokUsd: 1, outputPerMTokUsd: 2 }) },
|
||||
}) as VNode
|
||||
const children = rendered.children as VNode[]
|
||||
expect((children[0] as VNode).children).toBe('in $1.00 / out $2.00 per MTok')
|
||||
expect((children[0] as VNode).children).toBe('$1.00 / $2.00')
|
||||
const badge = children[1] as VNode
|
||||
expect(badge.type).toBe(Badge)
|
||||
expect((badge.children as { default: () => string }).default()).toBe('litellm')
|
||||
@@ -178,18 +178,21 @@ describe('modelCatalogColumns: price column', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('modelCatalogColumns: free column (":free" suffix, distinct from priceSource)', () => {
|
||||
const col = modelCatalogColumns().find((c) => c.id === 'free')
|
||||
describe('modelCatalogColumns: ":free" suffix flag', () => {
|
||||
const col = modelCatalogColumns().find((c) => c.id === 'price')
|
||||
const priced = { priceSource: 'litellm', inputPerMTokUsd: 1, outputPerMTokUsd: 2 } as const
|
||||
|
||||
it('renders a Badge only when displayFree is true', () => {
|
||||
const rendered = cellOf(col)({ row: { original: testRow({ displayFree: true }) } }) as VNode
|
||||
expect(rendered.type).toBe(Badge)
|
||||
it('has no separate free column', () => {
|
||||
expect(modelCatalogColumns().some((c) => c.id === 'free')).toBe(false)
|
||||
})
|
||||
|
||||
it('renders an em dash when displayFree is false/undefined, even for priceSource "free"', () => {
|
||||
const rendered = cellOf(col)({ row: { original: testRow({ priceSource: 'free' }) } })
|
||||
expect(isVNode(rendered) && rendered.type).toBe('span')
|
||||
expect(isVNode(rendered) && rendered.children).toBe('—')
|
||||
it.each([
|
||||
{ displayFree: true, children: 3 },
|
||||
{ displayFree: false, children: 2 },
|
||||
{ displayFree: undefined, children: 2 },
|
||||
])('displayFree=$displayFree renders $children price-cell children', ({ displayFree, children }) => {
|
||||
const rendered = cellOf(col)({ row: { original: testRow({ ...priced, displayFree }) } }) as VNode
|
||||
expect((rendered.children as VNode[]).length).toBe(children)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@ import { h } from 'vue'
|
||||
|
||||
import ModelChip from '@/components/ModelChip.vue'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import CompactNumber from '@/components/CompactNumber.vue'
|
||||
import { EMPTY_CELL, optionalColumn, usageMetricColumns } from '@/lib/columns'
|
||||
import { formatContextWindow, formatCost, formatLatencyMs, formatModelCostHover } from '@/lib/format'
|
||||
import { formatCost, formatLatencyMs, formatModelCostHover, formatModelPriceShort } from '@/lib/format'
|
||||
import { formatErrorRatePercent, providerErrorRate } from '@/lib/provider-rate'
|
||||
import type { AdminCatalogResponse, AdminPerfResponse, AdminUsageModelsResponse, PriceSource } from '@/types/api'
|
||||
|
||||
@@ -97,6 +98,8 @@ const PRICE_SOURCE_LABEL: Record<Extract<PriceSource, 'override' | 'builtin' | '
|
||||
litellm: 'litellm',
|
||||
}
|
||||
|
||||
const FREE_SUFFIX_TITLE = "':free' suffix model — display-only, billing follows the price source"
|
||||
|
||||
function priceCell(row: ModelCatalogRow) {
|
||||
if (row.priceSource === 'unpriced') {
|
||||
return h(
|
||||
@@ -116,8 +119,13 @@ function priceCell(row: ModelCatalogRow) {
|
||||
// captured into its own variable first.
|
||||
const source = row.priceSource as Exclude<PriceSource, 'unpriced' | 'free'>
|
||||
return h('span', { class: 'inline-flex flex-wrap items-center gap-1.5' }, [
|
||||
h('span', {}, known ? formatModelCostHover(row.inputPerMTokUsd as number, row.outputPerMTokUsd as number) : EMPTY_CELL),
|
||||
h(
|
||||
'span',
|
||||
known ? { class: 'tabular-nums', title: formatModelCostHover(row.inputPerMTokUsd as number, row.outputPerMTokUsd as number) } : {},
|
||||
known ? formatModelPriceShort(row.inputPerMTokUsd as number, row.outputPerMTokUsd as number) : EMPTY_CELL,
|
||||
),
|
||||
h(Badge, { as: 'span', variant: 'outline', class: 'font-normal' }, () => PRICE_SOURCE_LABEL[source]),
|
||||
...(row.displayFree ? [h(Badge, { as: 'span', variant: 'secondary', class: 'font-normal', title: FREE_SUFFIX_TITLE }, () => ':free')] : []),
|
||||
])
|
||||
}
|
||||
|
||||
@@ -134,9 +142,8 @@ function priceSortValue(row: ModelCatalogRow): number {
|
||||
|
||||
/**
|
||||
* modelCatalogColumns builds the Models page's catalog table (redesign-
|
||||
* plan.md section 3.4): id, context, price + source badge, free (the
|
||||
* ':free' suffix flag — distinct from the price column's own 'free'
|
||||
* priceSource badge, see ModelCatalogRow's own doc comment), aliases,
|
||||
* plan.md section 3.4): id, context, price + source badge (plus a ':free' badge for
|
||||
* the suffix flag, distinct from the 'free' priceSource badge), aliases,
|
||||
* req/tokens/cost for the current global range, p50/p95, and error rate.
|
||||
* p50/p95 read "—" whenever undefined, regardless of WHY (no observations
|
||||
* yet, or admin.stats.latency off entirely) — ModelCatalogTable.vue itself
|
||||
@@ -158,26 +165,12 @@ export function modelCatalogColumns(): ColumnDef<ModelCatalogRow, unknown>[] {
|
||||
outputPerMTokUsd: row.original.outputPerMTokUsd,
|
||||
}),
|
||||
},
|
||||
optionalColumn<ModelCatalogRow>('context', 'Context', (r) => r.contextTokens, formatContextWindow),
|
||||
{
|
||||
id: 'price',
|
||||
header: 'Price',
|
||||
header: 'Price $/MTok',
|
||||
accessorFn: (r) => priceSortValue(r),
|
||||
cell: ({ row }) => priceCell(row.original),
|
||||
},
|
||||
{
|
||||
id: 'free',
|
||||
header: 'Free',
|
||||
accessorFn: (r) => (r.displayFree ? 1 : 0),
|
||||
cell: ({ row }) =>
|
||||
row.original.displayFree
|
||||
? h(
|
||||
Badge,
|
||||
{ as: 'span', variant: 'secondary', class: 'font-normal', title: "':free' suffix model — display-only, billing follows the Price column's own source" },
|
||||
() => 'free',
|
||||
)
|
||||
: h('span', { class: 'text-muted-foreground' }, EMPTY_CELL),
|
||||
},
|
||||
{
|
||||
id: 'aliases',
|
||||
header: 'Aliases',
|
||||
@@ -199,7 +192,19 @@ export function modelCatalogColumns(): ColumnDef<ModelCatalogRow, unknown>[] {
|
||||
// usageMetricColumns' own plain costColumn does not (and should not —
|
||||
// PricingHealthTable.vue's identical-shaped cost column has no such
|
||||
// badge) carry.
|
||||
...usageMetricColumns<ModelCatalogRow>().filter((c) => c.id !== 'cost'),
|
||||
...usageMetricColumns<ModelCatalogRow>().filter((c) => c.id === 'requests'),
|
||||
{
|
||||
id: 'tokens',
|
||||
header: 'Tokens',
|
||||
meta: { align: 'right' },
|
||||
accessorFn: (r) => r.tokensIn + r.tokensOut,
|
||||
cell: ({ row }) =>
|
||||
h('span', { class: 'inline-flex items-center gap-1 whitespace-nowrap', title: 'input / output tokens' }, [
|
||||
h(CompactNumber, { value: row.original.tokensIn }),
|
||||
h('span', { class: 'text-muted-foreground' }, '/'),
|
||||
h(CompactNumber, { value: row.original.tokensOut }),
|
||||
]),
|
||||
},
|
||||
{
|
||||
id: 'cost',
|
||||
header: 'Cost',
|
||||
@@ -217,7 +222,7 @@ export function modelCatalogColumns(): ColumnDef<ModelCatalogRow, unknown>[] {
|
||||
optionalColumn<ModelCatalogRow>('p95', 'p95', (r) => r.p95Ms, formatLatencyMs, { sortSentinel: -1 }),
|
||||
{
|
||||
id: 'errorRate',
|
||||
header: 'Error rate',
|
||||
header: 'Errors',
|
||||
meta: { align: 'right' },
|
||||
accessorFn: (r) => providerErrorRate(r.attempts, r.failures) ?? -1,
|
||||
cell: ({ row }) => h('span', { class: 'tabular-nums' }, formatErrorRatePercent(providerErrorRate(row.original.attempts, row.original.failures))),
|
||||
|
||||
Reference in New Issue
Block a user