fix(ui): guard divide-by-zero display error
Evan Wies
created 3 weeks ago
Otherwise, if contextWindow == 0, then it's a divide-by-zero error
and a wild number % is shown. Now it defaults to 0% in that case.
Signed-off-by: Evan Wies <evan@neomantra.net>
Change summary
internal/ui/common/elements.go | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Detailed changes
@@ -111,7 +111,10 @@ func formatTokensAndCost(t *styles.Styles, tokens, contextWindow int64, cost flo
formattedTokens = strings.Replace(formattedTokens, ".0M", "M", 1)
}
- percentage := (float64(tokens) / float64(contextWindow)) * 100
+ var percentage float64
+ if contextWindow > 0 {
+ percentage = (float64(tokens) / float64(contextWindow)) * 100
+ }
formattedCost := t.ModelInfo.Cost.Render(fmt.Sprintf("$%.2f", cost))