feat: improve model rate limit tracking
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/easyai/easyai-ai-gateway/apps/api/internal/auth"
|
||||
"github.com/easyai/easyai-ai-gateway/apps/api/internal/clients"
|
||||
"github.com/easyai/easyai-ai-gateway/apps/api/internal/store"
|
||||
)
|
||||
|
||||
@@ -108,3 +109,21 @@ func estimateRequestTokens(body map[string]any) int {
|
||||
}
|
||||
return len([]rune(text))/4 + 1
|
||||
}
|
||||
|
||||
func tokenUsageAmounts(usage clients.Usage) map[string]float64 {
|
||||
out := map[string]float64{}
|
||||
if usage.InputTokens > 0 {
|
||||
out["tpm_input"] = float64(usage.InputTokens)
|
||||
}
|
||||
if usage.OutputTokens > 0 {
|
||||
out["tpm_output"] = float64(usage.OutputTokens)
|
||||
}
|
||||
total := usage.TotalTokens
|
||||
if total <= 0 {
|
||||
total = usage.InputTokens + usage.OutputTokens
|
||||
}
|
||||
if total > 0 {
|
||||
out["tpm_total"] = float64(total)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user