mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 21:10:51 +08:00
refactor(gemini): replace static model handling with dynamic model registry lookup
This commit is contained in:
@@ -85,94 +85,35 @@ func (h *GeminiAPIHandler) GeminiGetHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
action := strings.TrimPrefix(request.Action, "/")
|
action := strings.TrimPrefix(request.Action, "/")
|
||||||
switch action {
|
|
||||||
case "gemini-3-pro-preview":
|
// Get dynamic models from the global registry and find the matching one
|
||||||
c.JSON(http.StatusOK, gin.H{
|
availableModels := h.Models()
|
||||||
"name": "models/gemini-3-pro-preview",
|
var targetModel map[string]any
|
||||||
"version": "3",
|
|
||||||
"displayName": "Gemini 3 Pro Preview",
|
for _, model := range availableModels {
|
||||||
"description": "Gemini 3 Pro Preview",
|
name, _ := model["name"].(string)
|
||||||
"inputTokenLimit": 1048576,
|
// Match name with or without 'models/' prefix
|
||||||
"outputTokenLimit": 65536,
|
if name == action || name == "models/"+action {
|
||||||
"supportedGenerationMethods": []string{
|
targetModel = model
|
||||||
"generateContent",
|
break
|
||||||
"countTokens",
|
}
|
||||||
"createCachedContent",
|
|
||||||
"batchGenerateContent",
|
|
||||||
},
|
|
||||||
"temperature": 1,
|
|
||||||
"topP": 0.95,
|
|
||||||
"topK": 64,
|
|
||||||
"maxTemperature": 2,
|
|
||||||
"thinking": true,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
case "gemini-2.5-pro":
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
|
||||||
"name": "models/gemini-2.5-pro",
|
|
||||||
"version": "2.5",
|
|
||||||
"displayName": "Gemini 2.5 Pro",
|
|
||||||
"description": "Stable release (June 17th, 2025) of Gemini 2.5 Pro",
|
|
||||||
"inputTokenLimit": 1048576,
|
|
||||||
"outputTokenLimit": 65536,
|
|
||||||
"supportedGenerationMethods": []string{
|
|
||||||
"generateContent",
|
|
||||||
"countTokens",
|
|
||||||
"createCachedContent",
|
|
||||||
"batchGenerateContent",
|
|
||||||
},
|
|
||||||
"temperature": 1,
|
|
||||||
"topP": 0.95,
|
|
||||||
"topK": 64,
|
|
||||||
"maxTemperature": 2,
|
|
||||||
"thinking": true,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
case "gemini-2.5-flash":
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
|
||||||
"name": "models/gemini-2.5-flash",
|
|
||||||
"version": "001",
|
|
||||||
"displayName": "Gemini 2.5 Flash",
|
|
||||||
"description": "Stable version of Gemini 2.5 Flash, our mid-size multimodal model that supports up to 1 million tokens, released in June of 2025.",
|
|
||||||
"inputTokenLimit": 1048576,
|
|
||||||
"outputTokenLimit": 65536,
|
|
||||||
"supportedGenerationMethods": []string{
|
|
||||||
"generateContent",
|
|
||||||
"countTokens",
|
|
||||||
"createCachedContent",
|
|
||||||
"batchGenerateContent",
|
|
||||||
},
|
|
||||||
"temperature": 1,
|
|
||||||
"topP": 0.95,
|
|
||||||
"topK": 64,
|
|
||||||
"maxTemperature": 2,
|
|
||||||
"thinking": true,
|
|
||||||
})
|
|
||||||
case "gpt-5":
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
|
||||||
"name": "gpt-5",
|
|
||||||
"version": "001",
|
|
||||||
"displayName": "GPT 5",
|
|
||||||
"description": "Stable version of GPT 5, The best model for coding and agentic tasks across domains.",
|
|
||||||
"inputTokenLimit": 400000,
|
|
||||||
"outputTokenLimit": 128000,
|
|
||||||
"supportedGenerationMethods": []string{
|
|
||||||
"generateContent",
|
|
||||||
},
|
|
||||||
"temperature": 1,
|
|
||||||
"topP": 0.95,
|
|
||||||
"topK": 64,
|
|
||||||
"maxTemperature": 2,
|
|
||||||
"thinking": true,
|
|
||||||
})
|
|
||||||
default:
|
|
||||||
c.JSON(http.StatusNotFound, handlers.ErrorResponse{
|
|
||||||
Error: handlers.ErrorDetail{
|
|
||||||
Message: "Not Found",
|
|
||||||
Type: "not_found",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if targetModel != nil {
|
||||||
|
// Ensure the name has 'models/' prefix in the output if it's a Gemini model
|
||||||
|
if name, ok := targetModel["name"].(string); ok && name != "" && !strings.HasPrefix(name, "models/") {
|
||||||
|
targetModel["name"] = "models/" + name
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, targetModel)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusNotFound, handlers.ErrorResponse{
|
||||||
|
Error: handlers.ErrorDetail{
|
||||||
|
Message: "Not Found",
|
||||||
|
Type: "not_found",
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// GeminiHandler handles POST requests for Gemini API operations.
|
// GeminiHandler handles POST requests for Gemini API operations.
|
||||||
|
|||||||
Reference in New Issue
Block a user