mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
feat(router): smart routers and per-member rate limits (#9)
Add smart routers: virtual models that score each request and route it to admin-defined model tiers. A retryable failure moves the request to a higher tier. The classifier v2 extracts prose, finds the original ask in long tool loops, adds an uncertainty margin and reads tool-output failures. Sessions, outcome signals, bounded calibration, adaptive selection within a tier, gated saturation downgrade, a first-byte timeout and an opt-in timeout fallback are included. Every new feature is off by default. Add per-member group limits, a tokensPerMinute window that counts uncached input and output, rate-limit headers in three dialects, soft pacing before the hard limit, and a limitExemptKinds list so embedding and reranking traffic never counts toward or hits a limit. Fix yaegi named-result state that made smartContentSize grow between calls.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package traefikllmgateway
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -456,3 +457,55 @@ func TestPriceKnown(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestModelVisionCapable(t *testing.T) {
|
||||
t.Parallel()
|
||||
yes, no := true, false
|
||||
tests := []struct {
|
||||
cfg map[string]*ModelMetaConfig
|
||||
name string
|
||||
want bool
|
||||
}{
|
||||
{nil, "nil cfg is capable", true},
|
||||
{map[string]*ModelMetaConfig{"other": {Vision: &no}}, "no entry is capable", true},
|
||||
{map[string]*ModelMetaConfig{"m": nil}, "nil entry is capable", true},
|
||||
{map[string]*ModelMetaConfig{"m": {ContextTokens: 5}}, "unset vision is capable", true},
|
||||
{map[string]*ModelMetaConfig{"m": {Vision: &no}}, "bare false", false},
|
||||
{map[string]*ModelMetaConfig{"m": {Vision: &yes}}, "bare true", true},
|
||||
{map[string]*ModelMetaConfig{"p/m": {Vision: &no}, "m": {Vision: &yes}}, "exact false beats bare true", false},
|
||||
{map[string]*ModelMetaConfig{"p/m": {Vision: &yes}, "m": {Vision: &no}}, "exact true beats bare false", true},
|
||||
{map[string]*ModelMetaConfig{"p/m": {ContextTokens: 9}, "m": {Vision: &no}}, "exact without vision falls through to bare false", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if got := modelVisionCapable("p", "m", tt.cfg); got != tt.want {
|
||||
t.Errorf("modelVisionCapable = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelMetaConfig_VisionJSONRoundTrip(t *testing.T) {
|
||||
t.Parallel()
|
||||
var unset, set ModelMetaConfig
|
||||
if err := json.Unmarshal([]byte(`{"contextTokens":1}`), &unset); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if unset.Vision != nil {
|
||||
t.Errorf("absent vision decoded to %v, want nil", *unset.Vision)
|
||||
}
|
||||
if err := json.Unmarshal([]byte(`{"vision":false}`), &set); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if set.Vision == nil || *set.Vision {
|
||||
t.Errorf("vision:false decoded to %v, want pointer to false", set.Vision)
|
||||
}
|
||||
out, err := json.Marshal(&unset)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(out), "vision") {
|
||||
t.Errorf("unset vision must be omitted from JSON, got %s", out)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user