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,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { formatBucketLabel, formatCompactCount, formatContextWindow, formatCostAxis, formatCostDisplay, formatElapsedAgo, formatLatencyMs, formatModelCostHover, formatPercentAxis, formatUntil, refreshDetailLabel, refreshLabel, ZERO_TIME } from './format'
|
||||
import { formatBucketLabel, formatCompactCount, formatContextWindow, formatCostAxis, formatCostDisplay, formatElapsedAgo, formatLimits, formatLatencyMs, formatModelCostHover, formatPercentAxis, formatUntil, refreshDetailLabel, refreshLabel, ZERO_TIME } from './format'
|
||||
|
||||
describe('refreshLabel', () => {
|
||||
it('reads "discovery off" when discovery is disabled, regardless of lastRefresh', () => {
|
||||
@@ -300,3 +300,29 @@ describe('formatPercentAxis', () => {
|
||||
expect(formatPercentAxis(rate)).toBe(want)
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatLimits', () => {
|
||||
it('returns none when unset or empty', () => {
|
||||
expect(formatLimits(undefined)).toBe('none')
|
||||
expect(formatLimits({})).toBe('none')
|
||||
})
|
||||
|
||||
it('renders tokens per minute', () => {
|
||||
expect(formatLimits({ tokensPerMinute: 500 })).toBe('tok/min 500')
|
||||
})
|
||||
|
||||
it('renders pacing with its source', () => {
|
||||
expect(formatLimits({ pacing: { startPct: 80, maxDelay: '10s' } }, { pacing: 'memberLimits:friends' })).toBe(
|
||||
'pace from 80% up to 10s (memberLimits:friends)',
|
||||
)
|
||||
})
|
||||
|
||||
it('appends each field source when given', () => {
|
||||
expect(
|
||||
formatLimits(
|
||||
{ requestsPerMinute: 9, tokensPerMinute: 100 },
|
||||
{ requestsPerMinute: 'user', tokensPerMinute: 'memberLimits:friends' },
|
||||
),
|
||||
).toBe('req/min 9 (user), tok/min 100 (memberLimits:friends)')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user