Просмотр исходного кода

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

Tom 7 месяцев назад
Родитель
Сommit
88b58fd6a0
1 измененных файлов с 4 добавлено и 1 удалено
  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(