From 526dd866ba2409d91265c8da545e1f7a718116ce Mon Sep 17 00:00:00 2001 From: Luis Pater Date: Fri, 16 Jan 2026 10:39:16 +0800 Subject: [PATCH] refactor(gemini): replace static model handling with dynamic model registry lookup --- sdk/api/handlers/gemini/gemini_handlers.go | 115 +++++---------------- 1 file changed, 28 insertions(+), 87 deletions(-) diff --git a/sdk/api/handlers/gemini/gemini_handlers.go b/sdk/api/handlers/gemini/gemini_handlers.go index f2bdb058..c4a04c85 100644 --- a/sdk/api/handlers/gemini/gemini_handlers.go +++ b/sdk/api/handlers/gemini/gemini_handlers.go @@ -85,94 +85,35 @@ func (h *GeminiAPIHandler) GeminiGetHandler(c *gin.Context) { return } action := strings.TrimPrefix(request.Action, "/") - switch action { - case "gemini-3-pro-preview": - c.JSON(http.StatusOK, gin.H{ - "name": "models/gemini-3-pro-preview", - "version": "3", - "displayName": "Gemini 3 Pro Preview", - "description": "Gemini 3 Pro Preview", - "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-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", - }, - }) + + // Get dynamic models from the global registry and find the matching one + availableModels := h.Models() + var targetModel map[string]any + + for _, model := range availableModels { + name, _ := model["name"].(string) + // Match name with or without 'models/' prefix + if name == action || name == "models/"+action { + targetModel = model + break + } } + + 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.