Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

contextWindow.ts

15 lines442 Bytes

1export function formatContextWindowTokens(value: number | null): string {
2 if (value === null || !Number.isFinite(value)) {
3 return "0";
4 }
5 if (value < 1_000) {
6 return `${Math.round(value)}`;
7 }
8 if (value < 10_000) {
9 return `${(value / 1_000).toFixed(1).replace(/\.0$/, "")}k`;
10 }
11 if (value < 999_500) {
12 return `${Math.round(value / 1_000)}k`;
13 }
14 return `${(value / 1_000_000).toFixed(1).replace(/\.0$/, "")}m`;