MCPcopy Create free account
hub / github.com/QuantumNous/new-api / FetchModels

Function FetchModels

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

Source from the content-addressed store, hash-verified

1272}
1273
1274func FetchModels(c *gin.Context) {
1275 var req fetchModelsRequest
1276
1277 if err := c.ShouldBindJSON(&req); err != nil {
1278 c.JSON(http.StatusBadRequest, gin.H{
1279 "success": false,
1280 "message": "Invalid request",
1281 })
1282 return
1283 }
1284
1285 var channel *model.Channel
1286 if req.Type == constant.ChannelTypeAdvancedCustom || req.ChannelID > 0 {
1287 var err error
1288 channel, err = buildAdvancedCustomModelPreviewChannel(req)
1289 if err != nil {
1290 c.JSON(http.StatusOK, gin.H{
1291 "success": false,
1292 "message": err.Error(),
1293 })
1294 return
1295 }
1296 } else {
1297 baseURL := ""
1298 if req.BaseURL != nil {
1299 baseURL = strings.TrimSpace(*req.BaseURL)
1300 }
1301 if baseURL == "" {
1302 baseURL = constant.ChannelBaseURLs[req.Type]
1303 }
1304
1305 key := strings.TrimSpace(req.Key)
1306 if req.Type != constant.ChannelTypeCodex {
1307 key = strings.Split(key, "\n")[0]
1308 }
1309 channel = &model.Channel{
1310 Type: req.Type,
1311 Key: key,
1312 BaseURL: &baseURL,
1313 }
1314 }
1315
1316 models, err := fetchChannelUpstreamModelIDs(channel)
1317 if err != nil {
1318 c.JSON(http.StatusOK, gin.H{
1319 "success": false,
1320 "message": fmt.Sprintf("获取模型列表失败: %s", err.Error()),
1321 })
1322 return
1323 }
1324 c.JSON(http.StatusOK, gin.H{
1325 "success": true,
1326 "message": "",
1327 "data": models,
1328 })
1329}
1330
1331func BatchSetChannelTag(c *gin.Context) {

Calls 3

ErrorMethod · 0.45