usage

package
v0.3.29-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatCost

func FormatCost(cost float64) string

FormatCost formats a cost value as a currency string with 4 decimal places

func FormatNumber

func FormatNumber(n int) string

FormatNumber formats large numbers with commas for readability

func LogLLMUsage

func LogLLMUsage(ctx context.Context, usage llmtypes.Usage, model string, startTime time.Time, requestOutputTokens int)

LogLLMUsage logs detailed LLM usage statistics including tokens, costs, and performance metrics

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

type DailyUsage struct {
	Date          time.Time
	Usage         llmtypes.Usage
	Conversations int
}

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

type ProviderUsageStats struct {
	Usage         llmtypes.Usage
	Conversations int
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL