Format a token count into a human-readable short string. Args: count: Number of tokens. Returns: Formatted string like `'12.5K'`, `'1.2M'`, or `'500'`.
(count: int)
| 137 | |
| 138 | |
| 139 | def format_token_count(count: int) -> str: |
| 140 | """Format a token count into a human-readable short string. |
| 141 | |
| 142 | Args: |
| 143 | count: Number of tokens. |
| 144 | |
| 145 | Returns: |
| 146 | Formatted string like `'12.5K'`, `'1.2M'`, or `'500'`. |
| 147 | """ |
| 148 | if count >= 1_000_000: # noqa: PLR2004 |
| 149 | return f"{count / 1_000_000:.1f}M" |
| 150 | if count >= 1000: # noqa: PLR2004 |
| 151 | return f"{count / 1000:.1f}K" |
| 152 | return str(count) |
no outgoing calls
searching dependent graphs…