mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
feat(admin): group catalog models by kind
Add a display-only kinds map to the provider config. Each pathBaseUrls key now appears in the admin catalog as an endpoint row. The Models page splits a provider into one sub-section per kind.
This commit is contained in:
@@ -1632,6 +1632,9 @@ providers:
|
||||
text-embedding-bge-reranker-v2: http://rerank-bge-v2.llm.svc.cluster.local:8000
|
||||
pathBaseUrls:
|
||||
/v1/decide: http://thx02.llm.svc.cluster.local:8200
|
||||
kinds:
|
||||
text-embedding-bge-reranker-v2: reranking
|
||||
/v1/decide: decision
|
||||
```
|
||||
|
||||
- **Unified routes** (chat, embeddings, images, audio): a request for
|
||||
@@ -1643,6 +1646,11 @@ providers:
|
||||
`pathBaseUrls` prefix; otherwise `baseUrl`. Only providers that set
|
||||
`modelBaseUrls` read the body for this purpose.
|
||||
- **Discovery** polls `baseUrl` only. `modelBaseUrls` ids are static.
|
||||
- **Admin catalog**: each `pathBaseUrls` key appears as a pseudo-model row
|
||||
(`gx10//v1/decide`). It is display only and never routable as a model.
|
||||
`kinds` labels a model id or a path key. The Models page then groups the
|
||||
provider's rows into one sub-section per kind. Without `kinds`, the table
|
||||
stays flat.
|
||||
- **Auth** reuses the provider's `apiKey` for every upstream.
|
||||
- **Failover health** is tracked per provider, not per upstream. One failing
|
||||
upstream marks the whole provider unhealthy, so with failover enabled its
|
||||
|
||||
+136
-136
File diff suppressed because one or more lines are too long
+24
-1
@@ -49,9 +49,13 @@ type adminCatalogModel struct {
|
||||
OutputPerMTokUSD *float64 `json:"outputPerMTokUsd,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Model string `json:"model"`
|
||||
Kind string `json:"kind,omitempty"`
|
||||
PriceSource string `json:"priceSource"`
|
||||
Aliases []string `json:"aliases,omitempty"`
|
||||
DisplayFree bool `json:"displayFree,omitempty"`
|
||||
// Endpoint marks a pseudo-model row for a pathBaseUrls key: shown in
|
||||
// the catalog, but never routable as a model and never priced.
|
||||
Endpoint bool `json:"endpoint,omitempty"`
|
||||
}
|
||||
|
||||
// adminCatalogProvider is one configured provider's catalog row in GET
|
||||
@@ -102,7 +106,11 @@ func (g *Gateway) buildAdminCatalog() adminCatalogResponse {
|
||||
|
||||
providers := make([]adminCatalogProvider, len(snaps))
|
||||
for i, s := range snaps {
|
||||
models := make([]adminCatalogModel, len(s.models))
|
||||
var kinds, pathBases map[string]string
|
||||
if pc := g.cfg.Providers[s.name]; pc != nil {
|
||||
kinds, pathBases = pc.Kinds, pc.PathBaseURLs
|
||||
}
|
||||
models := make([]adminCatalogModel, len(s.models), len(s.models)+len(pathBases))
|
||||
for j, model := range s.models {
|
||||
canonical := providerModelScopeID(s.name, model)
|
||||
metaView := buildAdminModelMetaView(g.registry.resolveMetaFor(s.name, model))
|
||||
@@ -143,8 +151,23 @@ func (g *Gateway) buildAdminCatalog() adminCatalogResponse {
|
||||
PriceSource: source,
|
||||
DisplayFree: displayFree,
|
||||
Aliases: aliases,
|
||||
Kind: kinds[model],
|
||||
}
|
||||
}
|
||||
paths := make([]string, 0, len(pathBases))
|
||||
for path := range pathBases {
|
||||
paths = append(paths, path)
|
||||
}
|
||||
sort.Strings(paths)
|
||||
for _, path := range paths {
|
||||
models = append(models, adminCatalogModel{
|
||||
ID: providerModelScopeID(s.name, path),
|
||||
Model: path,
|
||||
Kind: kinds[path],
|
||||
PriceSource: priceSourceUnpriced,
|
||||
Endpoint: true,
|
||||
})
|
||||
}
|
||||
providers[i] = adminCatalogProvider{
|
||||
Name: s.name,
|
||||
Type: s.typeName,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package traefikllmgateway
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -335,3 +336,66 @@ func TestAdminConsumers_UsersFilePathOnly(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminCatalog_KindsAndEndpointRows(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := newAdminTestConfig()
|
||||
cfg.Providers["zeta"].ModelBaseURLs = map[string]string{"bge-reranker": "http://rerank.invalid"}
|
||||
cfg.Providers["zeta"].PathBaseURLs = map[string]string{"/v1/decide": "http://thx.invalid", "/v1/other": "http://o.invalid"}
|
||||
cfg.Providers["zeta"].Kinds = map[string]string{"bge-reranker": "reranking", "/v1/decide": "decision"}
|
||||
h, _ := newAdminGatewayHandle(t, cfg)
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
h.ServeHTTP(rec, adminRequest(http.MethodGet, adminCatalogPath, "sk-admin1"))
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
var got adminCatalogResponse
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &got); err != nil {
|
||||
t.Fatalf("decode: %v", err)
|
||||
}
|
||||
byID := map[string]adminCatalogModel{}
|
||||
for _, p := range got.Providers {
|
||||
if p.Name != "zeta" {
|
||||
for _, m := range p.Models {
|
||||
if m.Kind != "" || m.Endpoint {
|
||||
t.Errorf("provider %s model %s carries kind/endpoint without config", p.Name, m.ID)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
for _, m := range p.Models {
|
||||
byID[m.ID] = m
|
||||
}
|
||||
}
|
||||
cases := []struct {
|
||||
id string
|
||||
kind string
|
||||
endpoint bool
|
||||
}{
|
||||
{"zeta/z-model", "", false},
|
||||
{"zeta/bge-reranker", "reranking", false},
|
||||
{"zeta//v1/decide", "decision", true},
|
||||
{"zeta//v1/other", "", true},
|
||||
}
|
||||
for _, c := range cases {
|
||||
m, ok := byID[c.id]
|
||||
if !ok {
|
||||
t.Errorf("%s missing from catalog", c.id)
|
||||
continue
|
||||
}
|
||||
if m.Kind != c.kind || m.Endpoint != c.endpoint {
|
||||
t.Errorf("%s: kind=%q endpoint=%v, want %q %v", c.id, m.Kind, m.Endpoint, c.kind, c.endpoint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestKindsValidation(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := newAdminTestConfig()
|
||||
cfg.Providers["zeta"].Kinds = map[string]string{"z-model": ""}
|
||||
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
|
||||
if _, err := New(context.Background(), next, cfg, "llmgw"); err == nil {
|
||||
t.Fatal("empty kind accepted")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ var nonSecretConfigKeys = map[string]bool{
|
||||
"agents": true, "allowedCIDRs": true, "backoff": true, "cacheTTL": true,
|
||||
"card": true, "discoveryInterval": true, "file": true, "group": true,
|
||||
"groups": true, "maxOpenDuration": true, "mcpServers": true,
|
||||
"metadataPath": true, "modelAliases": true, "modelBaseUrls": true, "models": true, "name": true,
|
||||
"kinds": true, "metadataPath": true, "modelAliases": true, "modelBaseUrls": true, "models": true, "name": true,
|
||||
"openDuration": true, "passthroughPaths": true, "path": true, "pathBaseUrls": true,
|
||||
"probeInterval": true, "providers": true, "requestTimeout": true,
|
||||
"ttl": true, "type": true,
|
||||
|
||||
@@ -240,6 +240,12 @@ type ProviderConfig struct {
|
||||
// to a base URL for requests that name no model in ModelBaseURLs. Longest
|
||||
// prefix wins; no match uses BaseURL. openai-type providers only.
|
||||
PathBaseURLs map[string]string `json:"pathBaseUrls,omitempty"`
|
||||
// Kinds labels a model id or a PathBaseURLs key with a free-form kind
|
||||
// (for example "reranking", "decision") for the admin catalog, which
|
||||
// groups a provider's rows by kind. Display only: routing, auth and
|
||||
// billing never read it. Each PathBaseURLs key also appears in the
|
||||
// catalog as an endpoint row.
|
||||
Kinds map[string]string `json:"kinds,omitempty"`
|
||||
// MetadataPath is an optional second discovery endpoint (feature
|
||||
// v0.23), fetched alongside the provider's normal listModels call
|
||||
// when set: a path such as "/api/v0/models" (LM Studio's own,
|
||||
|
||||
@@ -670,6 +670,11 @@ func buildAdapters(cfg *Config) (map[string]providerAdapter, error) {
|
||||
if baseErr != nil {
|
||||
return nil, baseErr
|
||||
}
|
||||
for key, kind := range pc.Kinds {
|
||||
if !isValidModelID(key) || !isValidModelID(kind) {
|
||||
return nil, fmt.Errorf("llmgateway: provider %q: kinds[%q] needs a non-empty key and kind without control characters", name, key)
|
||||
}
|
||||
}
|
||||
if pc.Type != providerTypeOpenAI && (len(modelBases) > 0 || len(pathBases) > 0) {
|
||||
return nil, fmt.Errorf("llmgateway: provider %q: modelBaseUrls and pathBaseUrls are supported for type %q only", name, providerTypeOpenAI)
|
||||
}
|
||||
|
||||
@@ -43,6 +43,41 @@ const filtered = computed<ModelCatalogRow[]>(() => filterModelRows(props.rows, p
|
||||
|
||||
const columns = modelCatalogColumns()
|
||||
|
||||
interface CatalogSection {
|
||||
key: string
|
||||
/** '' for the ungrouped (no-kind) rows. */
|
||||
title: string
|
||||
rows: ModelCatalogRow[]
|
||||
}
|
||||
|
||||
/**
|
||||
* sections splits the filtered rows into one table per (provider, kind): a
|
||||
* provider's plain models first, then one sub-section per kind, sorted.
|
||||
* With no kind set anywhere this is a single untitled section, so an
|
||||
* unconfigured catalog renders exactly as the flat table did.
|
||||
*/
|
||||
const sections = computed<CatalogSection[]>(() => {
|
||||
if (!filtered.value.some((r) => r.kind)) return [{ key: 'all', title: '', rows: filtered.value }]
|
||||
const providers: string[] = []
|
||||
const byKey = new Map<string, CatalogSection>()
|
||||
for (const r of filtered.value) {
|
||||
if (!providers.includes(r.providerName)) providers.push(r.providerName)
|
||||
const key = `${r.providerName}\u0000${r.kind}`
|
||||
let sec = byKey.get(key)
|
||||
if (!sec) {
|
||||
sec = { key, title: r.kind ? `${r.providerName} · ${r.kind}` : r.providerName, rows: [] }
|
||||
byKey.set(key, sec)
|
||||
}
|
||||
sec.rows.push(r)
|
||||
}
|
||||
const kindsOf = (provider: string): string[] =>
|
||||
[...byKey.values()]
|
||||
.filter((sec) => sec.rows[0].providerName === provider)
|
||||
.map((sec) => sec.rows[0].kind)
|
||||
.sort((a, b) => (a === '' ? -1 : b === '' ? 1 : a.localeCompare(b)))
|
||||
return providers.flatMap((p) => kindsOf(p).map((k) => byKey.get(`${p}\u0000${k}`) as CatalogSection))
|
||||
})
|
||||
|
||||
/**
|
||||
* catalogLoadState (lib/load-state.ts, verify-ui-states.md #3 fix) now
|
||||
* reads the REAL `error` prop, not a hardcoded ''. A not-yet-loaded (or
|
||||
@@ -87,7 +122,12 @@ const emptyMessage = computed<string>(() => {
|
||||
<SkeletonTable v-if="catalogLoadState === 'skeleton'" :rows="5" :cols="columns.length" />
|
||||
<ErrorState v-else-if="catalogLoadState === 'error'" :message="error ?? ''" :on-retry="onRetry" />
|
||||
<EmptyState v-else-if="catalogLoadState === 'empty'" title="No models configured." />
|
||||
<DataTable v-else label="Model catalog" :columns="columns" :data="filtered" :empty-message="emptyMessage" />
|
||||
<template v-else>
|
||||
<section v-for="sec in sections" :key="sec.key" class="flex flex-col gap-2">
|
||||
<h3 v-if="sec.title" class="text-sm font-medium text-muted-foreground">{{ sec.title }}</h3>
|
||||
<DataTable :label="sec.title ? `Model catalog: ${sec.title}` : 'Model catalog'" :columns="columns" :data="sec.rows" :empty-message="emptyMessage" />
|
||||
</section>
|
||||
</template>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
@@ -8,6 +8,8 @@ function row(overrides: Partial<ModelCatalogRow> = {}): ModelCatalogRow {
|
||||
id: 'openai/gpt-5',
|
||||
model: 'gpt-5',
|
||||
providerName: 'openai',
|
||||
kind: '',
|
||||
endpoint: false,
|
||||
priceSource: 'builtin',
|
||||
aliases: [],
|
||||
requests: 0,
|
||||
|
||||
@@ -13,6 +13,8 @@ function testRow(overrides: Partial<ModelCatalogRow> = {}): ModelCatalogRow {
|
||||
id: 'openai/gpt-5',
|
||||
model: 'gpt-5',
|
||||
providerName: 'openai',
|
||||
kind: '',
|
||||
endpoint: false,
|
||||
priceSource: 'builtin',
|
||||
aliases: [],
|
||||
requests: 0,
|
||||
|
||||
@@ -32,6 +32,10 @@ export interface ModelCatalogRow {
|
||||
/** The bare upstream model id, without the provider prefix (AdminCatalogModel.model). */
|
||||
model: string
|
||||
providerName: string
|
||||
/** AdminCatalogModel.kind — '' when the model has none. */
|
||||
kind: string
|
||||
/** AdminCatalogModel.endpoint — a pathBaseUrls pseudo-model: no price, no context. */
|
||||
endpoint: boolean
|
||||
contextTokens?: number
|
||||
inputPerMTokUsd?: number
|
||||
outputPerMTokUsd?: number
|
||||
@@ -71,6 +75,8 @@ export function buildModelCatalogRows(
|
||||
id: m.id,
|
||||
model: m.model,
|
||||
providerName: provider.name,
|
||||
kind: m.kind ?? '',
|
||||
endpoint: m.endpoint ?? false,
|
||||
contextTokens: m.contextTokens,
|
||||
inputPerMTokUsd: m.inputPerMTokUsd,
|
||||
outputPerMTokUsd: m.outputPerMTokUsd,
|
||||
@@ -101,6 +107,7 @@ const PRICE_SOURCE_LABEL: Record<Extract<PriceSource, 'override' | 'builtin' | '
|
||||
const FREE_SUFFIX_TITLE = "':free' suffix model — display-only, billing follows the price source"
|
||||
|
||||
function priceCell(row: ModelCatalogRow) {
|
||||
if (row.endpoint) return h('span', { class: 'text-muted-foreground' }, EMPTY_CELL)
|
||||
if (row.priceSource === 'unpriced') {
|
||||
return h(
|
||||
Badge,
|
||||
@@ -136,6 +143,7 @@ function priceCell(row: ModelCatalogRow) {
|
||||
* on.
|
||||
*/
|
||||
function priceSortValue(row: ModelCatalogRow): number {
|
||||
if (row.endpoint) return 0
|
||||
if (row.priceSource === 'unpriced') return -1
|
||||
return row.inputPerMTokUsd ?? 0
|
||||
}
|
||||
|
||||
@@ -698,6 +698,10 @@ export interface AdminCatalogModel {
|
||||
priceSource: PriceSource
|
||||
/** True for a ':free' suffix model (routes_unified.go) — display-only relabeling; billing still follows `priceSource` unchanged. */
|
||||
displayFree?: boolean
|
||||
/** Operator label from the provider's `kinds` map (for example 'reranking'); absent for an ordinary model. */
|
||||
kind?: string
|
||||
/** True for a pseudo-model row built from a `pathBaseUrls` key — not a routable model, never priced. */
|
||||
endpoint?: boolean
|
||||
aliases?: string[]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user