@@ -16,6 +16,8 @@ import (
1616 "github.com/QuantumNous/new-api/relay/channel/moonshot"
1717 relaycommon "github.com/QuantumNous/new-api/relay/common"
1818 "github.com/QuantumNous/new-api/service"
19+ "github.com/QuantumNous/new-api/setting/operation_setting"
20+ "github.com/QuantumNous/new-api/setting/ratio_setting"
1921 "github.com/gin-gonic/gin"
2022 "github.com/samber/lo"
2123)
@@ -109,6 +111,17 @@ func init() {
109111func ListModels (c * gin.Context , modelType int ) {
110112 userOpenAiModels := make ([]dto.OpenAIModels , 0 )
111113
114+ acceptUnsetRatioModel := operation_setting .SelfUseModeEnabled
115+ if ! acceptUnsetRatioModel {
116+ userId := c .GetInt ("id" )
117+ if userId > 0 {
118+ userSettings , _ := model .GetUserSetting (userId , false )
119+ if userSettings .AcceptUnsetRatioModel {
120+ acceptUnsetRatioModel = true
121+ }
122+ }
123+ }
124+
112125 modelLimitEnable := common .GetContextKeyBool (c , constant .ContextKeyTokenModelLimitEnabled )
113126 if modelLimitEnable {
114127 s , ok := common .GetContextKey (c , constant .ContextKeyTokenModelLimit )
@@ -119,6 +132,12 @@ func ListModels(c *gin.Context, modelType int) {
119132 tokenModelLimit = map [string ]bool {}
120133 }
121134 for allowModel , _ := range tokenModelLimit {
135+ if ! acceptUnsetRatioModel {
136+ _ , _ , exist := ratio_setting .GetModelRatioOrPrice (allowModel )
137+ if ! exist {
138+ continue
139+ }
140+ }
122141 if oaiModel , ok := openAIModelsMap [allowModel ]; ok {
123142 oaiModel .SupportedEndpointTypes = model .GetModelSupportEndpointTypes (allowModel )
124143 userOpenAiModels = append (userOpenAiModels , oaiModel )
@@ -161,6 +180,12 @@ func ListModels(c *gin.Context, modelType int) {
161180 models = model .GetGroupEnabledModels (group )
162181 }
163182 for _ , modelName := range models {
183+ if ! acceptUnsetRatioModel {
184+ _ , _ , exist := ratio_setting .GetModelRatioOrPrice (modelName )
185+ if ! exist {
186+ continue
187+ }
188+ }
164189 if oaiModel , ok := openAIModelsMap [modelName ]; ok {
165190 oaiModel .SupportedEndpointTypes = model .GetModelSupportEndpointTypes (modelName )
166191 userOpenAiModels = append (userOpenAiModels , oaiModel )
@@ -175,6 +200,7 @@ func ListModels(c *gin.Context, modelType int) {
175200 }
176201 }
177202 }
203+
178204 switch modelType {
179205 case constant .ChannelTypeAnthropic :
180206 useranthropicModels := make ([]dto.AnthropicModel , len (userOpenAiModels ))
0 commit comments