Documentation
¶
Index ¶
- Variables
- type DailyStats
- type DailyTrend
- type HourlyUsage
- type Insights
- type Manager
- func (m *Manager) ExportJSON() ([]byte, error)
- func (m *Manager) FormatInsightsText(days int) (string, error)
- func (m *Manager) GetAllRecords(limit, offset int) []UsageRecord
- func (m *Manager) GetBudget() *MonthlyBudget
- func (m *Manager) GetDailyStats(date string) (*DailyStats, error)
- func (m *Manager) GetInsights(days int) (*Insights, error)
- func (m *Manager) GetInsightsJSON(days int) (string, error)
- func (m *Manager) GetMonthlyStats() (*DailyStats, error)
- func (m *Manager) GetTodayStats() (*DailyStats, error)
- func (m *Manager) GetWeeklyStats() (*DailyStats, error)
- func (m *Manager) IsBudgetExceeded() bool
- func (m *Manager) IsBudgetWarning() bool
- func (m *Manager) Record(inputTokens, outputTokens int, model, provider, sessionID string) error
- func (m *Manager) SetBudget(limit, alertThreshold float64) error
- type ModelPrice
- type ModelStats
- type ModelUsage
- type MonthlyBudget
- type ProviderUsage
- type UsageRecord
Constants ¶
This section is empty.
Variables ¶
var ModelPricing = map[string]ModelPrice{
"gpt-4o": {Input: 5.00, Output: 15.00, Unit: "1M tokens"},
"gpt-4o-mini": {Input: 0.15, Output: 0.60, Unit: "1M tokens"},
"gpt-4-turbo": {Input: 10.00, Output: 30.00, Unit: "1M tokens"},
"gpt-4": {Input: 30.00, Output: 60.00, Unit: "1M tokens"},
"gpt-3.5-turbo": {Input: 0.50, Output: 1.50, Unit: "1M tokens"},
"claude-3-5-sonnet-20241022": {Input: 3.00, Output: 15.00, Unit: "1M tokens"},
"claude-3-5-haiku-20241022": {Input: 0.80, Output: 4.00, Unit: "1M tokens"},
"claude-3-opus-20240229": {Input: 15.00, Output: 75.00, Unit: "1M tokens"},
"claude-3-sonnet-20240229": {Input: 3.00, Output: 15.00, Unit: "1M tokens"},
"deepseek-chat": {Input: 0.27, Output: 1.10, Unit: "1M tokens"},
"deepseek-coder": {Input: 0.27, Output: 1.10, Unit: "1M tokens"},
"llama3.2": {Input: 0, Output: 0, Unit: "local"},
"mistral": {Input: 0, Output: 0, Unit: "local"},
"codellama": {Input: 0, Output: 0, Unit: "local"},
"openrouter/anthropic/claude-3.5-sonnet": {Input: 3.00, Output: 15.00, Unit: "1M tokens"},
"openrouter/openai/gpt-4o": {Input: 5.00, Output: 15.00, Unit: "1M tokens"},
"openrouter/deepseek/deepseek-chat-v3": {Input: 0.27, Output: 1.10, Unit: "1M tokens"},
}
ModelPricing 定义各模型的定价
Functions ¶
This section is empty.
Types ¶
type DailyStats ¶
type DailyStats struct {
Date string `json:"date"`
TotalRequests int `json:"total_requests"`
TotalInput int `json:"total_input_tokens"`
TotalOutput int `json:"total_output_tokens"`
TotalCost float64 `json:"total_cost"`
ByModel map[string]ModelStats `json:"by_model"`
}
DailyStats 每日统计
type DailyTrend ¶
type DailyTrend struct {
Date string `json:"date"`
Requests int `json:"requests"`
Tokens int `json:"tokens"`
Cost float64 `json:"cost"`
}
DailyTrend represents daily usage trend
type HourlyUsage ¶
type HourlyUsage struct {
Hour int `json:"hour"`
Requests int `json:"requests"`
Tokens int `json:"tokens"`
}
HourlyUsage represents hourly usage pattern
type Insights ¶
type Insights struct {
Period string `json:"period"`
TotalRequests int `json:"total_requests"`
TotalTokens int `json:"total_tokens"`
TotalCost float64 `json:"total_cost"`
AvgTokensPerReq float64 `json:"avg_tokens_per_request"`
AvgCostPerReq float64 `json:"avg_cost_per_request"`
TopModels []ModelUsage `json:"top_models"`
TopProviders []ProviderUsage `json:"top_providers"`
DailyTrend []DailyTrend `json:"daily_trend"`
PeakHours []HourlyUsage `json:"peak_hours"`
CostBreakdown map[string]float64 `json:"cost_breakdown"`
Recommendations []string `json:"recommendations"`
GeneratedAt int64 `json:"generated_at"`
}
Insights provides detailed usage analysis
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 使用量管理器
func (*Manager) FormatInsightsText ¶
FormatInsightsText formats insights as human-readable text
func (*Manager) GetAllRecords ¶
func (m *Manager) GetAllRecords(limit, offset int) []UsageRecord
GetAllRecords 获取所有记录(可分页)
func (*Manager) GetDailyStats ¶
func (m *Manager) GetDailyStats(date string) (*DailyStats, error)
GetDailyStats 获取指定日期的统计
func (*Manager) GetInsights ¶
GetInsights generates detailed usage insights for the specified period
func (*Manager) GetInsightsJSON ¶
GetInsightsJSON generates insights and returns as JSON string
func (*Manager) GetMonthlyStats ¶
func (m *Manager) GetMonthlyStats() (*DailyStats, error)
GetMonthlyStats 获取本月统计
func (*Manager) GetTodayStats ¶
func (m *Manager) GetTodayStats() (*DailyStats, error)
GetTodayStats 获取今日统计
func (*Manager) GetWeeklyStats ¶
func (m *Manager) GetWeeklyStats() (*DailyStats, error)
GetWeeklyStats 获取本周统计
func (*Manager) IsBudgetExceeded ¶
IsBudgetExceeded 检查是否超过预算
type ModelPrice ¶
type ModelPrice struct {
Input float64 // 每百万输入 token 成本
Output float64 // 每百万输出 token 成本
Unit string // 计量单位
}
ModelPrice 模型定价结构
type ModelStats ¶
type ModelStats struct {
Requests int `json:"requests"`
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
Cost float64 `json:"cost"`
}
ModelStats 模型统计
type ModelUsage ¶
type ModelUsage struct {
Model string `json:"model"`
Requests int `json:"requests"`
Tokens int `json:"tokens"`
Cost float64 `json:"cost"`
Percentage float64 `json:"percentage"`
}
ModelUsage represents usage by model
type MonthlyBudget ¶
type MonthlyBudget struct {
Month string `json:"month"`
Limit float64 `json:"limit"` // 预算上限(美元)
Current float64 `json:"current"` // 当前花费
AlertThreshold float64 `json:"alert_threshold"` // 告警阈值(百分比)
}
MonthlyBudget 月度预算
type ProviderUsage ¶
type ProviderUsage struct {
Provider string `json:"provider"`
Requests int `json:"requests"`
Tokens int `json:"tokens"`
Cost float64 `json:"cost"`
Percentage float64 `json:"percentage"`
}
ProviderUsage represents usage by provider
type UsageRecord ¶
type UsageRecord struct {
ID string `json:"id"`
Timestamp time.Time `json:"timestamp"`
Model string `json:"model"`
Provider string `json:"provider"`
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
Cost float64 `json:"cost"`
SessionID string `json:"session_id,omitempty"`
RequestType string `json:"request_type,omitempty"` // chat, completion, embedding, etc.
}
UsageRecord 单次使用记录