diff --git a/ui/desktop/src/components/sessions/SessionsInsights.tsx b/ui/desktop/src/components/sessions/SessionsInsights.tsx index b9ec0e2cf7dc..27bc358e8a34 100644 --- a/ui/desktop/src/components/sessions/SessionsInsights.tsx +++ b/ui/desktop/src/components/sessions/SessionsInsights.tsx @@ -109,6 +109,22 @@ export function SessionInsights() { .replace(/\//g, '/'); }; + const formatTokens = (tokens: number | undefined): string => { + if (!tokens) { + return '0'; + } + if (tokens >= 1_000_000_000) { + return `${(tokens / 1_000_000_000).toFixed(2)}B`; + } + if (tokens >= 1_000_000) { + return `${(tokens / 1_000_000).toFixed(2)}M`; + } + if (tokens >= 1_000) { + return `${(tokens / 1_000).toFixed(1)}K`; + } + return tokens.toString(); + }; + // Render skeleton loader while data is loading const renderSkeleton = () => (
- {insights?.totalTokens && insights.totalTokens > 0 - ? `${(insights.totalTokens / 1000000).toFixed(2)}M` - : '0.00M'} + {formatTokens(insights?.totalTokens)}
Total tokens