fix: Prevent division by zero in context percentage calculation (#1055)

This commit is contained in:
Tom 2025-07-16 21:35:20 +07:00 committed by GitHub
parent 5d67e13df5
commit 88b58fd6a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -451,7 +451,10 @@ func formatTokensAndCost(
formattedTokens = strings.Replace(formattedTokens, ".0M", "M", 1)
}
percentage := (float64(tokens) / float64(contextWindow)) * 100
percentage := 0.0
if contextWindow > 0 {
percentage = (float64(tokens) / float64(contextWindow)) * 100
}
if isSubscriptionModel {
return fmt.Sprintf(