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:
+10
@@ -170,6 +170,7 @@ type watchdogBody struct {
|
||||
// convention (admin.go) for the same reasoning spelled out once.
|
||||
latencyStart time.Time
|
||||
rc io.ReadCloser
|
||||
fb *firstByteGuard
|
||||
cancel context.CancelFunc
|
||||
timer *time.Timer
|
||||
onTimeout attemptRecorder
|
||||
@@ -190,6 +191,9 @@ type watchdogBody struct {
|
||||
// cleanly.
|
||||
done int32
|
||||
streaming bool
|
||||
// sse feeds the first-byte guard for a stream, where a keep-alive comment is not a first byte.
|
||||
sse sseDataDetector
|
||||
fbDone bool
|
||||
}
|
||||
|
||||
// newWatchdogBody returns a watchdogBody wrapping rc, arming its watchdog
|
||||
@@ -352,6 +356,12 @@ func (wb *watchdogBody) timeoutError() error {
|
||||
// firing the instant before this branch runs.
|
||||
func (wb *watchdogBody) Read(p []byte) (int, error) {
|
||||
n, err := wb.rc.Read(p)
|
||||
if wb.fb != nil && !wb.fbDone && n > 0 && (!wb.streaming || wb.sse.feed(p[:n])) {
|
||||
wb.fbDone = true
|
||||
if !wb.fb.satisfy() {
|
||||
return 0, errFirstByteTimeout
|
||||
}
|
||||
}
|
||||
if n > 0 && wb.onLatency != nil && atomic.LoadInt32(&wb.ttfbRecorded) == 0 {
|
||||
wb.ttfb = time.Since(wb.latencyStart)
|
||||
atomic.StoreInt32(&wb.ttfbRecorded, 1)
|
||||
|
||||
Reference in New Issue
Block a user