Explorar el Código

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

Tom hace 7 meses
padre
commit
88b58fd6a0
Se han modificado 1 ficheros con 4 adiciones y 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)
 		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 {
 	if isSubscriptionModel {
 		return fmt.Sprintf(
 		return fmt.Sprintf(