mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
feat(admin,webui): metadata exposure
admin.go: adminProviderView gains ModelMeta (map[string]adminModelMetaView,
keyed by upstream model id) and adminAliasView gains its own ModelMeta —
both built via g.registry.resolveMetaFor/resolveMetaForAliasName
(feature v0.23). adminModelMetaView uses pointer fields
(*int/*float64), not plain zero values: a nil pointer means unknown, a
non-nil pointer (even one pointing at 0) means known, so a free model's
real zero cost never gets confused with an absent one over JSON.
resolveMetaForAliasName resolves an alias's metadata for this
unrestricted admin view via an internal &group{} (GroupConfig's own
documented empty-means-all semantics) — buildAdminOverview already
shows every provider/alias unconditionally, with no group filtering
anywhere else in its response either.
webui/src/types/api.ts: AdminModelMetaView mirrors the Go shape
(optional numbers, undefined means unknown); AdminProviderView.modelMeta
and AdminAliasView.modelMeta wire it through.
webui/src/lib/format.ts: formatContextWindow (binary-K "256k"-style),
formatModelCostHover ("in $X / out $Y per MTok", or "free"), and
their shared formatUsdPerMTok building block.
ModelChip.vue (operator scope refinement): every chip — the accordion's
model chips, the alias table's chips, a group's usage-detail chips —
gains optional contextTokens/inputPerMTokUsd/outputPerMTokUsd props.
When known, they append a resolved-metadata phrase to the existing
copy-state hover text, bound to BOTH title and aria-label (the same
mouse-vs-keyboard/screen-reader parity ProviderRateBadge.vue already
applies); when nothing is known, the hover is unchanged from before this
feature. An alias's chip carries its INHERITED metadata, matching the
alias-inheritance rule the backend already applies.
ProvidersView.vue: the accordion's model list gains a visible, muted
context-only chip ("256k") beside each ModelChip — cost stays
hover-only on the chip itself, per the operator's own "chips +
hover would be redundant on price" resolution.
This commit is contained in:
@@ -22,6 +22,80 @@ export function formatCost(micros: number): string {
|
||||
return `$${(micros / 1_000_000).toFixed(4)}`
|
||||
}
|
||||
|
||||
/** formatExactInt renders a raw integer count with thousands separators ("1,234,567") — the precise value CompactNumber.vue and the usage chart's tooltip carry alongside a compact rendering, never lost. */
|
||||
export function formatExactInt(n: number): string {
|
||||
return n.toLocaleString('en-US')
|
||||
}
|
||||
|
||||
/**
|
||||
* formatCompactCount renders a raw token/request count as a compact,
|
||||
* SI-style label: below 10,000 the exact integer with thousands
|
||||
* separators ("9,999"); at or above that, three significant figures
|
||||
* with a k/M/B suffix ("12.3k", "456k", "1.23M", "45.6M", "1.23B"),
|
||||
* trailing zeros trimmed. Every digit beyond the third significant one
|
||||
* is FLOORED, never rounded — the same honesty rule formatRatePercent
|
||||
* already applies to the success-rate badge (lib/provider-rate.ts): a
|
||||
* count of 999,950 must never display as "1,000k", which would imply a
|
||||
* boundary the raw value has not actually crossed. This is DISPLAY
|
||||
* only — every caller pairs it with the exact value via a title/
|
||||
* aria-label (CompactNumber.vue's own doc comment), and no accessor/sort
|
||||
* key ever calls this; DataTable columns sort on the raw number.
|
||||
*/
|
||||
export function formatCompactCount(n: number): string {
|
||||
const abs = Math.abs(n)
|
||||
if (abs < 10_000) return formatExactInt(n)
|
||||
|
||||
const sign = n < 0 ? '-' : ''
|
||||
const [divisor, suffix] = abs < 1_000_000 ? [1_000, 'k'] : abs < 1_000_000_000 ? [1_000_000, 'M'] : [1_000_000_000, 'B']
|
||||
const scaled = abs / divisor
|
||||
|
||||
// Three significant figures total: the floored integer part's own
|
||||
// digit count (1, 2, or 3) decides how many decimal places are left.
|
||||
const intDigits = Math.floor(scaled) >= 100 ? 3 : Math.floor(scaled) >= 10 ? 2 : 1
|
||||
const decimals = 3 - intDigits
|
||||
|
||||
const factor = 10 ** decimals
|
||||
const floored = Math.floor(scaled * factor) / factor
|
||||
|
||||
let text = floored.toFixed(decimals)
|
||||
if (decimals > 0) {
|
||||
text = text.replace(/0+$/, '').replace(/\.$/, '')
|
||||
}
|
||||
return `${sign}${text}${suffix}`
|
||||
}
|
||||
|
||||
/**
|
||||
* formatContextWindow renders a token count as a compact "256k"-style
|
||||
* label (feature v0.23's context_window/AdminModelMetaView.contextTokens
|
||||
* unit — plain token count, not bytes) — binary-K (÷1024), matching the
|
||||
* task brief's own worked example (262144 tokens -> "256k"). Plain
|
||||
* digits, no suffix, for anything under 1024: a context window that
|
||||
* small is rare (LM Studio's smallest observed embedding models run
|
||||
* 512-8192) but must still render as a real number, not "0k".
|
||||
*/
|
||||
export function formatContextWindow(tokens: number): string {
|
||||
if (tokens < 1024) return `${tokens}`
|
||||
return `${Math.round(tokens / 1024)}k`
|
||||
}
|
||||
|
||||
/** formatUsdPerMTok renders a USD-per-million-tokens float as "$0.19" (2 decimals) — the shared building block for both the visible cost chip and ModelChip's hover detail. */
|
||||
function formatUsdPerMTok(usd: number): string {
|
||||
return `$${usd.toFixed(2)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* formatModelCostHover renders ModelChip's hover-detail cost phrase
|
||||
* (feature v0.23, hover-detail refinement): "in $0.19 / out $0.51 per
|
||||
* MTok" for a priced model, or "free" when both sides are exactly 0 (a
|
||||
* KNOWN zero cost, ModelMetaConfig.Free — distinct from the caller never
|
||||
* passing a cost at all, which ModelChip's own metaDetail computed
|
||||
* handles by omitting the phrase entirely rather than calling this).
|
||||
*/
|
||||
export function formatModelCostHover(inputUsd: number, outputUsd: number): string {
|
||||
if (inputUsd === 0 && outputUsd === 0) return 'free'
|
||||
return `in ${formatUsdPerMTok(inputUsd)} / out ${formatUsdPerMTok(outputUsd)} per MTok`
|
||||
}
|
||||
|
||||
/** formatAgo renders an ISO timestamp as "(Ns ago)", or "" for the unset zero-time sentinel. */
|
||||
export function formatAgo(iso: string | undefined): string {
|
||||
if (!iso || iso === ZERO_TIME) return ''
|
||||
|
||||
Reference in New Issue
Block a user