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

Function FetchUpstreamModels

controller/channel.go:154–207  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

152}
153
154func FetchUpstreamModels(c *gin.Context) {
155 id, err := strconv.Atoi(c.Param("id"))
156 if err != nil {
157 common.ApiError(c, err)
158 return
159 }
160
161 channel, err := model.GetChannelById(id, true)
162 if err != nil {
163 common.ApiError(c, err)
164 return
165 }
166
167 baseURL := constant.ChannelBaseURLs[channel.Type]
168 if channel.GetBaseURL() != "" {
169 baseURL = channel.GetBaseURL()
170 }
171 url := fmt.Sprintf("%s/v1/models", baseURL)
172 switch channel.Type {
173 case constant.ChannelTypeGemini:
174 url = fmt.Sprintf("%s/v1beta/openai/models", baseURL)
175 case constant.ChannelTypeAli:
176 url = fmt.Sprintf("%s/compatible-mode/v1/models", baseURL)
177 }
178 body, err := GetResponseBody("GET", url, channel, GetAuthHeader(channel.Key))
179 if err != nil {
180 common.ApiError(c, err)
181 return
182 }
183
184 var result OpenAIModelsResponse
185 if err = json.Unmarshal(body, &result); err != nil {
186 c.JSON(http.StatusOK, gin.H{
187 "success": false,
188 "message": fmt.Sprintf("解析响应失败: %s", err.Error()),
189 })
190 return
191 }
192
193 var ids []string
194 for _, model := range result.Data {
195 id := model.ID
196 if channel.Type == constant.ChannelTypeGemini {
197 id = strings.TrimPrefix(id, "models/")
198 }
199 ids = append(ids, id)
200 }
201
202 c.JSON(http.StatusOK, gin.H{
203 "success": true,
204 "message": "",
205 "data": ids,
206 })
207}
208
209func FixChannelsAbilities(c *gin.Context) {
210 success, fails, err := model.FixAbility()

Callers

nothing calls this directly

Calls 6

ApiErrorFunction · 0.92
GetChannelByIdFunction · 0.92
GetResponseBodyFunction · 0.85
GetAuthHeaderFunction · 0.85
GetBaseURLMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected