(c *gin.Context)
| 152 | } |
| 153 | |
| 154 | func 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 | |
| 209 | func FixChannelsAbilities(c *gin.Context) { |
| 210 | success, fails, err := model.FixAbility() |
nothing calls this directly
no test coverage detected