mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
feat(admin): expose model vision capability in admin meta view
This commit is contained in:
@@ -566,6 +566,7 @@ type adminModelMetaView struct {
|
||||
ContextTokens *int `json:"contextTokens,omitempty"`
|
||||
InputPerMTokUSD *float64 `json:"inputPerMTokUsd,omitempty"`
|
||||
OutputPerMTokUSD *float64 `json:"outputPerMTokUsd,omitempty"`
|
||||
Vision *bool `json:"vision,omitempty"`
|
||||
}
|
||||
|
||||
// buildAdminModelMetaView converts resolveModelMeta's result into the
|
||||
@@ -574,6 +575,7 @@ type adminModelMetaView struct {
|
||||
// do this).
|
||||
func buildAdminModelMetaView(meta resolvedModelMeta) adminModelMetaView {
|
||||
var v adminModelMetaView
|
||||
v.Vision = meta.Vision
|
||||
if meta.ContextKnown {
|
||||
ctx := meta.ContextTokens
|
||||
v.ContextTokens = &ctx
|
||||
|
||||
+18
-5
@@ -34,6 +34,8 @@ const freeTierSuffix = ":free"
|
||||
// field, since a free model's cost fields are legitimately zero AND
|
||||
// known (ModelMetaConfig.Free).
|
||||
type resolvedModelMeta struct {
|
||||
// Vision is the operator's explicit modelMeta.vision; nil means unset.
|
||||
Vision *bool
|
||||
ContextTokens int
|
||||
InputCostPerMTokMicroUSD int64
|
||||
OutputCostPerMTokMicroUSD int64
|
||||
@@ -71,6 +73,7 @@ type resolvedModelMeta struct {
|
||||
// entry.
|
||||
func resolveModelMeta(provider, model string, cfg map[string]*ModelMetaConfig, discoveredContext int, discoveredKnown bool) resolvedModelMeta {
|
||||
var out resolvedModelMeta
|
||||
out.Vision = configuredVision(provider, model, cfg)
|
||||
override := lookupModelMetaConfig(provider, model, cfg)
|
||||
builtin, builtinOK := builtinModelMetaTable[model]
|
||||
|
||||
@@ -190,15 +193,25 @@ func lookupModelMetaConfig(provider, model string, cfg map[string]*ModelMetaConf
|
||||
// deployments keep today's behaviour. The exact "provider/model" key wins
|
||||
// over the bare key only when it sets Vision itself.
|
||||
func modelVisionCapable(provider, model string, cfg map[string]*ModelMetaConfig) bool {
|
||||
if v, ok := cfg[provider+"/"+model]; ok && v != nil && v.Vision != nil {
|
||||
return *v.Vision
|
||||
}
|
||||
if v, ok := cfg[model]; ok && v != nil && v.Vision != nil {
|
||||
return *v.Vision
|
||||
if v := configuredVision(provider, model, cfg); v != nil {
|
||||
return *v
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// configuredVision returns the explicitly configured Vision value, or nil
|
||||
// when no applicable modelMeta entry sets it. Exact "provider/model" wins
|
||||
// over the bare key only when it sets Vision itself.
|
||||
func configuredVision(provider, model string, cfg map[string]*ModelMetaConfig) *bool {
|
||||
if v, ok := cfg[provider+"/"+model]; ok && v != nil && v.Vision != nil {
|
||||
return v.Vision
|
||||
}
|
||||
if v, ok := cfg[model]; ok && v != nil && v.Vision != nil {
|
||||
return v.Vision
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// resolveAliasModelMeta applies modelMeta's alias-inheritance rule
|
||||
// (feature v0.23): an alias inherits its target's fully resolved
|
||||
// metadata (resolveModelMeta against the alias's resolved provider/
|
||||
|
||||
@@ -509,3 +509,36 @@ func TestModelMetaConfig_VisionJSONRoundTrip(t *testing.T) {
|
||||
t.Errorf("unset vision must be omitted from JSON, got %s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminModelMetaView_Vision(t *testing.T) {
|
||||
t.Parallel()
|
||||
yes, no := true, false
|
||||
cfg := map[string]*ModelMetaConfig{
|
||||
"p/seen": {Vision: &yes},
|
||||
"p/blind": {Vision: &no},
|
||||
"p/other": {ContextTokens: 1000},
|
||||
}
|
||||
cases := []struct {
|
||||
want *bool
|
||||
model string
|
||||
wantJSON bool
|
||||
}{
|
||||
{&yes, "seen", true},
|
||||
{&no, "blind", true},
|
||||
{nil, "other", false},
|
||||
{nil, "absent", false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
view := buildAdminModelMetaView(resolveModelMeta("p", c.model, cfg, 0, false))
|
||||
if (view.Vision == nil) != (c.want == nil) || (c.want != nil && *view.Vision != *c.want) {
|
||||
t.Fatalf("%s: Vision = %v, want %v", c.model, view.Vision, c.want)
|
||||
}
|
||||
raw, err := json.Marshal(view)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := strings.Contains(string(raw), `"vision"`); got != c.wantJSON {
|
||||
t.Fatalf("%s: json %s, vision present = %v, want %v", c.model, raw, got, c.wantJSON)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user