feat: cache token stat.

This commit is contained in:
2026-05-02 10:13:33 +08:00
parent 6ef84b7488
commit f81ee19bed
4 changed files with 91 additions and 33 deletions
+2
View File
@@ -16,6 +16,8 @@ type AIAnalysisRecord struct {
OutputTokens int `json:"outputTokens"`
InputSizeBytes int `json:"inputSizeBytes"`
OutputSizeBytes int `json:"outputSizeBytes"`
CacheHitTokens int `json:"cacheHitTokens"`
CacheMissTokens int `json:"cacheMissTokens"`
DurationMs int64 `json:"durationMs"`
OriginalFileSize int64 `json:"originalFileSize"`
CompressedContentSize int64 `json:"compressedContentSize"`
+12 -8
View File
@@ -6,10 +6,12 @@ import (
type AIPricingConfig struct {
gorm.Model
Name string `gorm:"size:64;uniqueIndex" json:"name"`
Provider string `gorm:"size:64" json:"provider"`
InputPricePerMillion float64 `json:"inputPricePerMillion"`
OutputPricePerMillion float64 `json:"outputPricePerMillion"`
Name string `gorm:"size:64;uniqueIndex" json:"name"`
Provider string `gorm:"size:64" json:"provider"`
InputPricePerMillion float64 `json:"inputPricePerMillion"`
OutputPricePerMillion float64 `json:"outputPricePerMillion"`
CacheHitPricePerMillion float64 `json:"cacheHitPricePerMillion"`
CacheMissPricePerMillion float64 `json:"cacheMissPricePerMillion"`
}
func EnsureDefaultAIPricing(db *gorm.DB) error {
@@ -21,9 +23,11 @@ func EnsureDefaultAIPricing(db *gorm.DB) error {
return nil
}
return db.Create(&AIPricingConfig{
Name: "deepseek-v4-flash",
Provider: "tencentmaas",
InputPricePerMillion: 1,
OutputPricePerMillion: 2,
Name: "deepseek-v4-flash",
Provider: "tencentmaas",
InputPricePerMillion: 1,
CacheHitPricePerMillion: 1,
CacheMissPricePerMillion: 0.02,
OutputPricePerMillion: 2,
}).Error
}