feat: pricing stat.
This commit is contained in:
+5
-1
@@ -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"`
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user