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:
+15
-8
@@ -1,4 +1,4 @@
|
||||
import type { HistoryWindow, LimitsConfig } from '@/types/api'
|
||||
import type { HistoryWindow, LimitSources, LimitsConfig } from '@/types/api'
|
||||
|
||||
/** ZERO_TIME is Go's zero time.Time value in its default JSON (RFC 3339) encoding — the unset-timestamp sentinel every admin API "never happened yet" field marshals as, and every formatter/test below treats as absent. */
|
||||
export const ZERO_TIME = '0001-01-01T00:00:00Z'
|
||||
@@ -368,15 +368,22 @@ export function refreshDetailLabel(discoveryEnabled: boolean, lastRefresh: strin
|
||||
}
|
||||
|
||||
/** formatLimits renders a LimitsConfig as a short comma-joined summary, or "none" when unset. */
|
||||
export function formatLimits(limits: LimitsConfig | undefined): string {
|
||||
export function formatLimits(limits: LimitsConfig | undefined, sources?: LimitSources): string {
|
||||
if (!limits) return 'none'
|
||||
const parts: string[] = []
|
||||
if (limits.requestsPerMinute) parts.push(`req/min ${limits.requestsPerMinute}`)
|
||||
if (limits.requestsPerDay) parts.push(`req/day ${limits.requestsPerDay}`)
|
||||
if (limits.tokensPerDay) parts.push(`tok/day ${limits.tokensPerDay}`)
|
||||
if (limits.tokensPerMonth) parts.push(`tok/month ${limits.tokensPerMonth}`)
|
||||
if (limits.costPerDayUSD) parts.push(`cost/day $${limits.costPerDayUSD}`)
|
||||
if (limits.costPerMonthUSD) parts.push(`cost/month $${limits.costPerMonthUSD}`)
|
||||
const add = (key: keyof LimitsConfig, text: string) => {
|
||||
if (!limits[key]) return
|
||||
const source = sources?.[key]
|
||||
parts.push(source ? `${text} (${source})` : text)
|
||||
}
|
||||
add('requestsPerMinute', `req/min ${limits.requestsPerMinute}`)
|
||||
add('requestsPerDay', `req/day ${limits.requestsPerDay}`)
|
||||
add('tokensPerMinute', `tok/min ${limits.tokensPerMinute}`)
|
||||
add('tokensPerDay', `tok/day ${limits.tokensPerDay}`)
|
||||
add('tokensPerMonth', `tok/month ${limits.tokensPerMonth}`)
|
||||
add('costPerDayUSD', `cost/day $${limits.costPerDayUSD}`)
|
||||
add('costPerMonthUSD', `cost/month $${limits.costPerMonthUSD}`)
|
||||
if (limits.pacing) add('pacing', `pace from ${limits.pacing.startPct}% up to ${limits.pacing.maxDelay}`)
|
||||
return parts.length ? parts.join(', ') : 'none'
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user