feat: sync upstream pricing from pricing endpoint (#4452)

* feat: sync upstream pricing from pricing endpoint

* feat: sync upstream pricing with expression priority

* fix: add feedback while syncing upstream pricing

* fix: show loading state for empty upstream pricing sync
This commit is contained in:
Seefs
2026-04-26 20:17:35 +08:00
committed by GitHub
parent cc4ad6c39e
commit f424f906d8
7 changed files with 643 additions and 267 deletions
+22
View File
@@ -5,11 +5,14 @@ import (
"github.com/QuantumNous/new-api/pkg/billingexpr"
"github.com/QuantumNous/new-api/setting/config"
"github.com/samber/lo"
)
const (
BillingModeRatio = "ratio"
BillingModeTieredExpr = "tiered_expr"
BillingModeField = "billing_mode"
BillingExprField = "billing_expr"
)
// BillingSetting is managed by config.GlobalConfig.Register.
@@ -44,6 +47,25 @@ func GetBillingExpr(model string) (string, bool) {
return expr, ok
}
func GetBillingModeCopy() map[string]string {
return lo.Assign(billingSetting.BillingMode)
}
func GetBillingExprCopy() map[string]string {
return lo.Assign(billingSetting.BillingExpr)
}
func GetPricingSyncData(base map[string]any) map[string]any {
extra := make(map[string]any, 2)
if modes := GetBillingModeCopy(); len(modes) > 0 {
extra[BillingModeField] = modes
}
if exprs := GetBillingExprCopy(); len(exprs) > 0 {
extra[BillingExprField] = exprs
}
return lo.Assign(base, extra)
}
// ---------------------------------------------------------------------------
// Smoke test (called externally for validation before save)
// ---------------------------------------------------------------------------
+12
View File
@@ -709,6 +709,18 @@ func GetCompletionRatioCopy() map[string]float64 {
return completionRatioMap.ReadAll()
}
func GetImageRatioCopy() map[string]float64 {
return imageRatioMap.ReadAll()
}
func GetAudioRatioCopy() map[string]float64 {
return audioRatioMap.ReadAll()
}
func GetAudioCompletionRatioCopy() map[string]float64 {
return audioCompletionRatioMap.ReadAll()
}
// 转换模型名,减少渠道必须配置各种带参数模型
func FormatMatchingModelName(name string) string {