mirror of
https://github.com/Warky-Devs/vecna.git
synced 2026-05-05 01:26:58 +00:00
feat: 🎉 Vectors na Vectors, the begining
Translate 1536 <-> 768 , 3072 <-> 2048
This commit is contained in:
37
pkg/server/trace.go
Normal file
37
pkg/server/trace.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type contextKey int
|
||||
|
||||
const traceKey contextKey = iota
|
||||
|
||||
// RequestTrace holds per-request timing data populated by handlers and middleware.
|
||||
type RequestTrace struct {
|
||||
Start time.Time
|
||||
ForwardDuration time.Duration
|
||||
TranslateDuration time.Duration
|
||||
ForwardTarget string
|
||||
ForwardURL string
|
||||
ForwardModel string
|
||||
AdapterType string
|
||||
PromptTokens int
|
||||
TotalTokens int
|
||||
}
|
||||
|
||||
// WithTrace injects a new *RequestTrace into ctx.
|
||||
func WithTrace(ctx context.Context) context.Context {
|
||||
return context.WithValue(ctx, traceKey, &RequestTrace{Start: time.Now()})
|
||||
}
|
||||
|
||||
// TraceFromContext retrieves the *RequestTrace from ctx.
|
||||
// Returns a zero-value trace (non-nil) if none was set.
|
||||
func TraceFromContext(ctx context.Context) *RequestTrace {
|
||||
if t, ok := ctx.Value(traceKey).(*RequestTrace); ok && t != nil {
|
||||
return t
|
||||
}
|
||||
return &RequestTrace{Start: time.Now()}
|
||||
}
|
||||
Reference in New Issue
Block a user