feat: in progress : add Token Usage Statistics #887
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Token Usage Statistics
The Token Usage Statistics component is a feature that tracks and displays token consumption across different language models and providers in the application. It provides detailed insights into how tokens are being used in conversations, including cost breakdowns and usage patterns.
Features
Components
TokenUsageTab
The main component that displays token usage information. It includes:
Token Usage Hook (
useTokenUsage
)A React hook that calculates token usage statistics by:
Data Structure
TokenUsage Interface
ModelUsage Interface
Usage Tracking
Token usage is tracked automatically for each conversation. The system:
Components Location
/app/components/settings/tokenusagestats/TokenUsageTab.tsx
/app/lib/hooks/useTokenUsage.ts
/app/types/token-usage.ts
/app/components/ui/ModelUsageCard.tsx
/app/components/ui/CostBreakdownCard.tsx
/app/components/ui/TotalCostCard.tsx
Implementation Details
The token usage tracking system works by:
Chat Title Handling
The system maintains consistent chat titles across the interface by:
Settings
Token usage settings can be configured through the TokenUsageSettingsModal, which allows users to:
Integration
The token usage statistics are automatically integrated into the chat interface and can be accessed through:
Upcoming Features
Planned enhancements for the token usage system include:
I have done a complete rework because the old branch had conflicts.
will post a video soon.
Best regards,
Stijnus