| 32 | } |
| 33 | |
| 34 | func FormatContextWindowStatus(model string, usedTokens, limitTokens int, width int) string { |
| 35 | if width <= 0 { |
| 36 | width = 20 |
| 37 | } |
| 38 | if model == "" && limitTokens <= 0 { |
| 39 | return "" |
| 40 | } |
| 41 | label := "Model: " + firstNonEmpty(model, "unknown") |
| 42 | if limitTokens <= 0 { |
| 43 | return label + " | Context: n/a" |
| 44 | } |
| 45 | if usedTokens < 0 { |
| 46 | usedTokens = 0 |
| 47 | } |
| 48 | ratio := float64(usedTokens) / float64(limitTokens) |
| 49 | percent := int(math.Round(ratio * 100)) |
| 50 | if percent < 0 { |
| 51 | percent = 0 |
| 52 | } |
| 53 | bar := FormatContextProgressBar(usedTokens, limitTokens, width) |
| 54 | return fmt.Sprintf("%s | Context %s %d%% %s/%s", label, bar, percent, formatTokenCount(usedTokens), formatTokenCount(limitTokens)) |
| 55 | } |
| 56 | |
| 57 | func FormatContextProgressBar(usedTokens, limitTokens int, width int) string { |
| 58 | if width <= 0 { |