|
@@ -11,6 +11,7 @@ import (
|
|
|
"github.com/QuantumNous/new-api/constant"
|
|
"github.com/QuantumNous/new-api/constant"
|
|
|
"github.com/QuantumNous/new-api/dto"
|
|
"github.com/QuantumNous/new-api/dto"
|
|
|
"github.com/QuantumNous/new-api/model"
|
|
"github.com/QuantumNous/new-api/model"
|
|
|
|
|
+ "github.com/QuantumNous/new-api/relay/channel/gemini"
|
|
|
"github.com/QuantumNous/new-api/relay/channel/ollama"
|
|
"github.com/QuantumNous/new-api/relay/channel/ollama"
|
|
|
"github.com/QuantumNous/new-api/service"
|
|
"github.com/QuantumNous/new-api/service"
|
|
|
|
|
|
|
@@ -260,11 +261,37 @@ func FetchUpstreamModels(c *gin.Context) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 对于 Gemini 渠道,使用特殊处理
|
|
|
|
|
+ if channel.Type == constant.ChannelTypeGemini {
|
|
|
|
|
+ // 获取用于请求的可用密钥(多密钥渠道优先使用启用状态的密钥)
|
|
|
|
|
+ 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)
|
|
|
|
|
+ models, err := gemini.FetchGeminiModels(baseURL, key, channel.GetSetting().Proxy)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
+ "success": false,
|
|
|
|
|
+ "message": fmt.Sprintf("获取Gemini模型失败: %s", err.Error()),
|
|
|
|
|
+ })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
+ "success": true,
|
|
|
|
|
+ "message": "",
|
|
|
|
|
+ "data": models,
|
|
|
|
|
+ })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
var url string
|
|
var url string
|
|
|
switch channel.Type {
|
|
switch channel.Type {
|
|
|
- case constant.ChannelTypeGemini:
|
|
|
|
|
- // curl https://example.com/v1beta/models?key=$GEMINI_API_KEY
|
|
|
|
|
- url = fmt.Sprintf("%s/v1beta/openai/models", baseURL) // Remove key in url since we need to use AuthHeader
|
|
|
|
|
case constant.ChannelTypeAli:
|
|
case constant.ChannelTypeAli:
|
|
|
url = fmt.Sprintf("%s/compatible-mode/v1/models", baseURL)
|
|
url = fmt.Sprintf("%s/compatible-mode/v1/models", baseURL)
|
|
|
case constant.ChannelTypeZhipu_v4:
|
|
case constant.ChannelTypeZhipu_v4:
|
|
@@ -1072,6 +1099,23 @@ func FetchModels(c *gin.Context) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if req.Type == constant.ChannelTypeGemini {
|
|
|
|
|
+ models, err := gemini.FetchGeminiModels(baseURL, key, "")
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
+ "success": false,
|
|
|
|
|
+ "message": fmt.Sprintf("获取Gemini模型失败: %s", err.Error()),
|
|
|
|
|
+ })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
+ "success": true,
|
|
|
|
|
+ "data": models,
|
|
|
|
|
+ })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
client := &http.Client{}
|
|
client := &http.Client{}
|
|
|
url := fmt.Sprintf("%s/v1/models", baseURL)
|
|
url := fmt.Sprintf("%s/v1/models", baseURL)
|
|
|
|
|
|