MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / ListModels

Function ListModels

controller/model.go:105–178  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

103}
104
105func ListModels(c *gin.Context) {
106 userOpenAiModels := make([]dto.OpenAIModels, 0)
107
108 modelLimitEnable := common.GetContextKeyBool(c, constant.ContextKeyTokenModelLimitEnabled)
109 if modelLimitEnable {
110 s, ok := common.GetContextKey(c, constant.ContextKeyTokenModelLimit)
111 var tokenModelLimit map[string]bool
112 if ok {
113 tokenModelLimit = s.(map[string]bool)
114 } else {
115 tokenModelLimit = map[string]bool{}
116 }
117 for allowModel, _ := range tokenModelLimit {
118 if oaiModel, ok := openAIModelsMap[allowModel]; ok {
119 oaiModel.SupportedEndpointTypes = model.GetModelSupportEndpointTypes(allowModel)
120 userOpenAiModels = append(userOpenAiModels, oaiModel)
121 } else {
122 userOpenAiModels = append(userOpenAiModels, dto.OpenAIModels{
123 Id: allowModel,
124 Object: "model",
125 Created: 1626777600,
126 OwnedBy: "custom",
127 SupportedEndpointTypes: model.GetModelSupportEndpointTypes(allowModel),
128 })
129 }
130 }
131 } else {
132 userId := c.GetInt("id")
133 userGroup, err := model.GetUserGroup(userId, false)
134 if err != nil {
135 c.JSON(http.StatusOK, gin.H{
136 "success": false,
137 "message": "get user group failed",
138 })
139 return
140 }
141 group := userGroup
142 tokenGroup := common.GetContextKeyString(c, constant.ContextKeyTokenGroup)
143 if tokenGroup != "" {
144 group = tokenGroup
145 }
146 var models []string
147 if tokenGroup == "auto" {
148 for _, autoGroup := range setting.AutoGroups {
149 groupModels := model.GetGroupEnabledModels(autoGroup)
150 for _, g := range groupModels {
151 if !common.StringsContains(models, g) {
152 models = append(models, g)
153 }
154 }
155 }
156 } else {
157 models = model.GetGroupEnabledModels(group)
158 }
159 for _, modelName := range models {
160 if oaiModel, ok := openAIModelsMap[modelName]; ok {
161 oaiModel.SupportedEndpointTypes = model.GetModelSupportEndpointTypes(modelName)
162 userOpenAiModels = append(userOpenAiModels, oaiModel)

Callers

nothing calls this directly

Calls 3

GetUserGroupFunction · 0.92
GetGroupEnabledModelsFunction · 0.92

Tested by

no test coverage detected