Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions ui/desktop/src/components/sessions/SessionsInsights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => (
<div className="bg-background-muted flex flex-col h-full">
Expand Down Expand Up @@ -262,9 +278,7 @@ export function SessionInsights() {
<CardContent className="page-transition flex flex-col justify-end h-full p-0">
<div className="flex flex-col justify-end">
<p className="text-4xl font-mono font-light flex items-end">
{insights?.totalTokens && insights.totalTokens > 0
? `${(insights.totalTokens / 1000000).toFixed(2)}M`
: '0.00M'}
{formatTokens(insights?.totalTokens)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just use:

Intl.NumberFormat('en', { notation: 'compact', maximumFractionDigits: 2 }).format(insights?.totalTokens)

(possibly with || 0)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duh, thanks, this is obviously the way! 😄
#6466

</p>
<span className="text-xs text-text-muted">Total tokens</span>
</div>
Expand Down