| 206 | } |
| 207 | |
| 208 | func ListModels(c *gin.Context, modelType int) { |
| 209 | acceptUnsetRatioModel := operation_setting.SelfUseModeEnabled |
| 210 | if !acceptUnsetRatioModel { |
| 211 | userId := c.GetInt("id") |
| 212 | if userId > 0 { |
| 213 | userSettings, _ := model.GetUserSetting(userId, false) |
| 214 | if userSettings.AcceptUnsetRatioModel { |
| 215 | acceptUnsetRatioModel = true |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | userModelNames := make([]string, 0) |
| 221 | groups, err := getModelListGroups(c) |
| 222 | if err != nil { |
| 223 | c.JSON(http.StatusOK, gin.H{ |
| 224 | "success": false, |
| 225 | "message": "get user group failed", |
| 226 | }) |
| 227 | return |
| 228 | } |
| 229 | ownerGroups := groups.ownerGroups |
| 230 | modelLimitEnable := common.GetContextKeyBool(c, constant.ContextKeyTokenModelLimitEnabled) |
| 231 | if modelLimitEnable { |
| 232 | s, ok := common.GetContextKey(c, constant.ContextKeyTokenModelLimit) |
| 233 | var tokenModelLimit map[string]bool |
| 234 | if ok { |
| 235 | tokenModelLimit = s.(map[string]bool) |
| 236 | } else { |
| 237 | tokenModelLimit = map[string]bool{} |
| 238 | } |
| 239 | for allowModel, _ := range tokenModelLimit { |
| 240 | if !acceptUnsetRatioModel { |
| 241 | if !helper.HasModelBillingConfig(allowModel) { |
| 242 | continue |
| 243 | } |
| 244 | } |
| 245 | userModelNames = append(userModelNames, allowModel) |
| 246 | } |
| 247 | } else { |
| 248 | var models []string |
| 249 | if groups.tokenGroup == "auto" { |
| 250 | for _, autoGroup := range ownerGroups { |
| 251 | groupModels := model.GetGroupEnabledModels(autoGroup) |
| 252 | for _, g := range groupModels { |
| 253 | if !common.StringsContains(models, g) { |
| 254 | models = append(models, g) |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | } else { |
| 259 | models = model.GetGroupEnabledModels(ownerGroups[0]) |
| 260 | } |
| 261 | for _, modelName := range models { |
| 262 | if !acceptUnsetRatioModel { |
| 263 | if !helper.HasModelBillingConfig(modelName) { |
| 264 | continue |
| 265 | } |