Explorar o código

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

Tom hai 7 meses
pai
achega
88b58fd6a0
Modificáronse 1 ficheiros con 4 adicións e 1 borrados
  1. 4 1
      packages/tui/internal/components/chat/messages.go

+ 4 - 1
packages/tui/internal/components/chat/messages.go

@@ -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(