Merge pull request #2260 from seefs001/fix/multi-key-fetch-models
fix: When retrieving the model list with multiple keys, select the first enabled one.
This commit is contained in:
+11
-1
@@ -203,9 +203,19 @@ func FetchUpstreamModels(c *gin.Context) {
|
|||||||
url = fmt.Sprintf("%s/v1/models", baseURL)
|
url = fmt.Sprintf("%s/v1/models", baseURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取用于请求的可用密钥(多密钥渠道优先使用启用状态的密钥)
|
||||||
|
key, _, apiErr := channel.GetNextEnabledKey()
|
||||||
|
if apiErr != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": fmt.Sprintf("获取渠道密钥失败: %s", apiErr.Error()),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
key = strings.TrimSpace(key)
|
||||||
|
|
||||||
// 获取响应体 - 根据渠道类型决定是否添加 AuthHeader
|
// 获取响应体 - 根据渠道类型决定是否添加 AuthHeader
|
||||||
var body []byte
|
var body []byte
|
||||||
key := strings.Split(channel.Key, "\n")[0]
|
|
||||||
switch channel.Type {
|
switch channel.Type {
|
||||||
case constant.ChannelTypeAnthropic:
|
case constant.ChannelTypeAnthropic:
|
||||||
body, err = GetResponseBody("GET", url, channel, GetClaudeAuthHeader(key))
|
body, err = GetResponseBody("GET", url, channel, GetClaudeAuthHeader(key))
|
||||||
|
|||||||
Reference in New Issue
Block a user