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:
@@ -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)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user