( promptTokens: number, contextLength: number | undefined )
| 32 | const formatCount = (value: number): string => value.toLocaleString('en-US'); |
| 33 | |
| 34 | export const formatContextSummary = ( |
| 35 | promptTokens: number, |
| 36 | contextLength: number | undefined |
| 37 | ): string => { |
| 38 | if (contextLength === undefined || contextLength <= 0) { |
| 39 | return `${formatCount(promptTokens)} tokens`; |
| 40 | } |
| 41 | |
| 42 | // Clamp caps the displayed percent at 100% when prompt tokens exceed the context window. |
| 43 | const percent = Math.round(clamp01(promptTokens / contextLength) * 100); |
| 44 | |
| 45 | return `${formatCount(promptTokens)} / ${formatCount(contextLength)} tokens (${percent}%)`; |
| 46 | }; |
no test coverage detected