From 06cd774c1043fa29443fde825986dad4470c67be Mon Sep 17 00:00:00 2001 From: Xyfacai Date: Thu, 13 Nov 2025 18:44:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9C=AA=E8=AE=BE=E7=BD=AE=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E6=A8=A1=E5=9E=8B=E4=B8=8D=E4=BC=9A=E8=A2=AB=E6=8B=89?= =?UTF-8?q?=E5=8F=96=EF=BC=8C=E9=99=A4=E9=9D=9E=E8=AE=BE=E7=BD=AE=E8=87=AA?= =?UTF-8?q?=E7=94=A8=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/model.go | 26 ++++++++++++++++++++++++++ setting/ratio_setting/model_ratio.go | 13 +++++++++++++ 2 files changed, 39 insertions(+) diff --git a/controller/model.go b/controller/model.go index a1aa84259..c2409fc00 100644 --- a/controller/model.go +++ b/controller/model.go @@ -16,6 +16,8 @@ import ( "github.com/QuantumNous/new-api/relay/channel/moonshot" relaycommon "github.com/QuantumNous/new-api/relay/common" "github.com/QuantumNous/new-api/service" + "github.com/QuantumNous/new-api/setting/operation_setting" + "github.com/QuantumNous/new-api/setting/ratio_setting" "github.com/gin-gonic/gin" "github.com/samber/lo" ) @@ -109,6 +111,17 @@ func init() { func ListModels(c *gin.Context, modelType int) { userOpenAiModels := make([]dto.OpenAIModels, 0) + acceptUnsetRatioModel := operation_setting.SelfUseModeEnabled + if !acceptUnsetRatioModel { + userId := c.GetInt("id") + if userId > 0 { + userSettings, _ := model.GetUserSetting(userId, false) + if userSettings.AcceptUnsetRatioModel { + acceptUnsetRatioModel = true + } + } + } + modelLimitEnable := common.GetContextKeyBool(c, constant.ContextKeyTokenModelLimitEnabled) if modelLimitEnable { s, ok := common.GetContextKey(c, constant.ContextKeyTokenModelLimit) @@ -119,6 +132,12 @@ func ListModels(c *gin.Context, modelType int) { tokenModelLimit = map[string]bool{} } for allowModel, _ := range tokenModelLimit { + if !acceptUnsetRatioModel { + _, _, exist := ratio_setting.GetModelRatioOrPrice(allowModel) + if !exist { + continue + } + } if oaiModel, ok := openAIModelsMap[allowModel]; ok { oaiModel.SupportedEndpointTypes = model.GetModelSupportEndpointTypes(allowModel) userOpenAiModels = append(userOpenAiModels, oaiModel) @@ -161,6 +180,12 @@ func ListModels(c *gin.Context, modelType int) { models = model.GetGroupEnabledModels(group) } for _, modelName := range models { + if !acceptUnsetRatioModel { + _, _, exist := ratio_setting.GetModelRatioOrPrice(modelName) + if !exist { + continue + } + } if oaiModel, ok := openAIModelsMap[modelName]; ok { oaiModel.SupportedEndpointTypes = model.GetModelSupportEndpointTypes(modelName) userOpenAiModels = append(userOpenAiModels, oaiModel) @@ -175,6 +200,7 @@ func ListModels(c *gin.Context, modelType int) { } } } + switch modelType { case constant.ChannelTypeAnthropic: useranthropicModels := make([]dto.AnthropicModel, len(userOpenAiModels)) diff --git a/setting/ratio_setting/model_ratio.go b/setting/ratio_setting/model_ratio.go index 416822393..30b857cb2 100644 --- a/setting/ratio_setting/model_ratio.go +++ b/setting/ratio_setting/model_ratio.go @@ -823,3 +823,16 @@ func FormatMatchingModelName(name string) string { } return name } + +// result: 倍率or价格, usePrice, exist +func GetModelRatioOrPrice(model string) (float64, bool, bool) { // price or ratio + price, usePrice := GetModelPrice(model, false) + if usePrice { + return price, true, true + } + modelRatio, success, _ := GetModelRatio(model) + if success { + return modelRatio, false, true + } + return 37.5, false, false +}