Documentation
¶
Overview ¶
Package usage provides functionality for tracking and calculating usage statistics for LLM conversations including token counts, conversation metrics, and time-based analytics for monitoring system performance.
Index ¶
- func FormatCost(cost float64) string
- func FormatNumber(n int) string
- func LogLLMUsage(ctx context.Context, usage llmtypes.Usage, model string, startTime time.Time, ...)
- type ConversationSummary
- type ConversationUsageStats
- type DailyProviderBreakdownStats
- type DailyProviderUsage
- type DailyUsage
- type ProviderBreakdownStats
- type ProviderUsageStats
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatCost ¶
FormatCost formats a cost value as a currency string with 4 decimal places
func FormatNumber ¶
FormatNumber formats large numbers with commas for readability
Types ¶
type ConversationSummary ¶
type ConversationSummary interface {
GetID() string
GetCreatedAt() time.Time
GetUpdatedAt() time.Time
GetMessageCount() int
GetUsage() llmtypes.Usage
GetProvider() string
}
ConversationSummary provides access to conversation metadata and usage statistics
type ConversationUsageStats ¶
type ConversationUsageStats struct {
TotalConversations int `json:"totalConversations"`
TotalMessages int `json:"totalMessages"`
TotalTokens int `json:"totalTokens"`
TotalCost float64 `json:"totalCost"`
InputTokens int `json:"inputTokens"`
OutputTokens int `json:"outputTokens"`
CacheReadTokens int `json:"cacheReadTokens"`
CacheWriteTokens int `json:"cacheWriteTokens"`
InputCost float64 `json:"inputCost"`
OutputCost float64 `json:"outputCost"`
CacheReadCost float64 `json:"cacheReadCost"`
CacheWriteCost float64 `json:"cacheWriteCost"`
}
ConversationUsageStats represents usage statistics for the conversation list
func CalculateConversationUsageStats ¶
func CalculateConversationUsageStats(summaries []ConversationSummary) *ConversationUsageStats
CalculateConversationUsageStats calculates usage statistics for the conversation list UI
type DailyProviderBreakdownStats ¶
type DailyProviderBreakdownStats struct {
Daily []DailyProviderUsage
Total llmtypes.Usage
TotalConversations int
}
DailyProviderBreakdownStats represents usage statistics with daily breakdown and provider breakdown
func CalculateDailyProviderBreakdownStats ¶
func CalculateDailyProviderBreakdownStats(summaries []ConversationSummary, startTime, endTime time.Time) *DailyProviderBreakdownStats
CalculateDailyProviderBreakdownStats calculates usage statistics with both daily and provider breakdown within the specified time range, sorted newest first
type DailyProviderUsage ¶
type DailyProviderUsage struct {
Date time.Time
ProviderUsage map[string]*ProviderUsageStats // provider -> usage stats
TotalUsage llmtypes.Usage
TotalConversations int
}
DailyProviderUsage represents usage statistics for a single day with provider breakdown
type DailyUsage ¶
DailyUsage represents usage statistics for a single day
type ProviderBreakdownStats ¶
type ProviderBreakdownStats struct {
ProviderStats map[string]*ProviderUsageStats
Total llmtypes.Usage
TotalConversations int
}
ProviderBreakdownStats represents aggregated usage statistics broken down by provider
func CalculateProviderBreakdownStats ¶
func CalculateProviderBreakdownStats(summaries []ConversationSummary, startTime, endTime time.Time) *ProviderBreakdownStats
CalculateProviderBreakdownStats calculates usage statistics broken down by provider (accumulated totals)
type ProviderUsageStats ¶
ProviderUsageStats represents usage statistics for a single provider
type Stats ¶
type Stats struct {
Daily []DailyUsage
Total llmtypes.Usage
}
Stats represents aggregated usage statistics with daily breakdown and totals
func CalculateUsageStats ¶
func CalculateUsageStats(summaries []ConversationSummary, startTime, endTime time.Time) *Stats
CalculateUsageStats calculates aggregated usage statistics from conversation summaries within the specified time range, with daily breakdown sorted newest first