refactor: rename and relocate HasModelBillingConfig function for clarity
This commit is contained in:
+3
-2
@@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/QuantumNous/new-api/relay/channel/minimax"
|
"github.com/QuantumNous/new-api/relay/channel/minimax"
|
||||||
"github.com/QuantumNous/new-api/relay/channel/moonshot"
|
"github.com/QuantumNous/new-api/relay/channel/moonshot"
|
||||||
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
||||||
|
"github.com/QuantumNous/new-api/relay/helper"
|
||||||
"github.com/QuantumNous/new-api/service"
|
"github.com/QuantumNous/new-api/service"
|
||||||
"github.com/QuantumNous/new-api/setting/operation_setting"
|
"github.com/QuantumNous/new-api/setting/operation_setting"
|
||||||
"github.com/QuantumNous/new-api/types"
|
"github.com/QuantumNous/new-api/types"
|
||||||
@@ -133,7 +134,7 @@ func ListModels(c *gin.Context, modelType int) {
|
|||||||
}
|
}
|
||||||
for allowModel, _ := range tokenModelLimit {
|
for allowModel, _ := range tokenModelLimit {
|
||||||
if !acceptUnsetRatioModel {
|
if !acceptUnsetRatioModel {
|
||||||
if !model.HasModelBillingConfig(allowModel) {
|
if !helper.HasModelBillingConfig(allowModel) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,7 +181,7 @@ func ListModels(c *gin.Context, modelType int) {
|
|||||||
}
|
}
|
||||||
for _, modelName := range models {
|
for _, modelName := range models {
|
||||||
if !acceptUnsetRatioModel {
|
if !acceptUnsetRatioModel {
|
||||||
if !model.HasModelBillingConfig(modelName) {
|
if !helper.HasModelBillingConfig(modelName) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,20 +86,6 @@ func InvalidatePricingCache() {
|
|||||||
lastGetPricingTime = time.Time{}
|
lastGetPricingTime = time.Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HasModelBillingConfig(modelName string) bool {
|
|
||||||
if _, ok := ratio_setting.GetModelPrice(modelName, false); ok {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if _, ok, _ := ratio_setting.GetModelRatio(modelName); ok {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if billing_setting.GetBillingMode(modelName) != billing_setting.BillingModeTieredExpr {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
expr, ok := billing_setting.GetBillingExpr(modelName)
|
|
||||||
return ok && strings.TrimSpace(expr) != ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetVendors 返回当前定价接口使用到的供应商信息
|
// GetVendors 返回当前定价接口使用到的供应商信息
|
||||||
func GetVendors() []PricingVendor {
|
func GetVendors() []PricingVendor {
|
||||||
if time.Since(lastGetPricingTime) > time.Minute*1 || len(pricingMap) == 0 {
|
if time.Since(lastGetPricingTime) > time.Minute*1 || len(pricingMap) == 0 {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ func GeminiHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *typ
|
|||||||
if !strings.Contains(info.OriginModelName, "-nothinking") {
|
if !strings.Contains(info.OriginModelName, "-nothinking") {
|
||||||
// try to get no thinking model price
|
// try to get no thinking model price
|
||||||
noThinkingModelName := info.OriginModelName + "-nothinking"
|
noThinkingModelName := info.OriginModelName + "-nothinking"
|
||||||
containPrice := helper.ContainPriceOrRatio(noThinkingModelName)
|
containPrice := helper.HasModelBillingConfig(noThinkingModelName)
|
||||||
if containPrice {
|
if containPrice {
|
||||||
info.OriginModelName = noThinkingModelName
|
info.OriginModelName = noThinkingModelName
|
||||||
info.UpstreamModelName = noThinkingModelName
|
info.UpstreamModelName = noThinkingModelName
|
||||||
|
|||||||
+13
-2
@@ -2,6 +2,7 @@ package helper
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/QuantumNous/new-api/common"
|
"github.com/QuantumNous/new-api/common"
|
||||||
"github.com/QuantumNous/new-api/logger"
|
"github.com/QuantumNous/new-api/logger"
|
||||||
@@ -223,8 +224,18 @@ func ModelPriceHelperPerCall(c *gin.Context, info *relaycommon.RelayInfo) (types
|
|||||||
return priceData, nil
|
return priceData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ContainPriceOrRatio(modelName string) bool {
|
func HasModelBillingConfig(modelName string) bool {
|
||||||
return model.HasModelBillingConfig(modelName)
|
if _, ok := ratio_setting.GetModelPrice(modelName, false); ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if _, ok, _ := ratio_setting.GetModelRatio(modelName); ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if billing_setting.GetBillingMode(modelName) != billing_setting.BillingModeTieredExpr {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
expr, ok := billing_setting.GetBillingExpr(modelName)
|
||||||
|
return ok && strings.TrimSpace(expr) != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func modelPriceHelperTiered(c *gin.Context, info *relaycommon.RelayInfo, promptTokens int, meta *types.TokenCountMeta, groupRatioInfo types.GroupRatioInfo) (types.PriceData, error) {
|
func modelPriceHelperTiered(c *gin.Context, info *relaycommon.RelayInfo, promptTokens int, meta *types.TokenCountMeta, groupRatioInfo types.GroupRatioInfo) (types.PriceData, error) {
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
package ratio_setting
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
func TestGetCompletionRatioInfoGPT55UsesOfficialOutputMultiplier(t *testing.T) {
|
|
||||||
info := GetCompletionRatioInfo("gpt-5.5")
|
|
||||||
|
|
||||||
if info.Ratio != 6 {
|
|
||||||
t.Fatalf("gpt-5.5 completion ratio = %v, want 6", info.Ratio)
|
|
||||||
}
|
|
||||||
if !info.Locked {
|
|
||||||
t.Fatal("gpt-5.5 completion ratio should be locked to the official multiplier")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetCompletionRatioGPT55DatedVariant(t *testing.T) {
|
|
||||||
got := GetCompletionRatio("gpt-5.5-2026-04-24")
|
|
||||||
|
|
||||||
if got != 6 {
|
|
||||||
t.Fatalf("gpt-5.5 dated variant completion ratio = %v, want 6", got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user