feat: pricing stat.

This commit is contained in:
2026-04-30 16:33:30 +08:00
parent bbe6dea436
commit e43a034e28
5 changed files with 88 additions and 6 deletions
+5 -1
View File
@@ -1,6 +1,8 @@
package models
import "gorm.io/gorm"
import (
"gorm.io/gorm"
)
type AIAnalysisRecord struct {
gorm.Model
@@ -8,6 +10,8 @@ type AIAnalysisRecord struct {
SourceType string `gorm:"size:32" json:"sourceType"`
AnalysisType string `gorm:"size:32" json:"analysisType"`
AnalysisResult string `gorm:"type:text" json:"analysisResult"`
CostJSON string `gorm:"type:jsonb" json:"costJson"`
TotalCost float64 `json:"totalCost"`
InputTokens int `json:"inputTokens"`
OutputTokens int `json:"outputTokens"`
InputSizeBytes int `json:"inputSizeBytes"`
+29
View File
@@ -0,0 +1,29 @@
package models
import (
"gorm.io/gorm"
)
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"`
}
func EnsureDefaultAIPricing(db *gorm.DB) error {
var count int64
if err := db.Model(&AIPricingConfig{}).Count(&count).Error; err != nil {
return err
}
if count > 0 {
return nil
}
return db.Create(&AIPricingConfig{
Name: "deepseek-v4-flash",
Provider: "tencentmaas",
InputPricePerMillion: 1,
OutputPricePerMillion: 2,
}).Error
}