From 38b9705e74590831bd46db069aaa43e653aa431b Mon Sep 17 00:00:00 2001 From: Carl-Robert Linnupuu Date: Tue, 23 Sep 2025 23:45:53 +0100 Subject: [PATCH] fix: google model selection (fixes #1111) --- .../chat/ui/textarea/ModelComboBoxAction.java | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/textarea/ModelComboBoxAction.java b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/textarea/ModelComboBoxAction.java index f255d761..45917dfb 100644 --- a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/textarea/ModelComboBoxAction.java +++ b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/textarea/ModelComboBoxAction.java @@ -30,6 +30,7 @@ import com.intellij.openapi.ui.popup.LightweightWindowEvent; import com.intellij.openapi.ui.popup.ListPopup; import ee.carlrobert.codegpt.Icons; import ee.carlrobert.codegpt.completions.llama.LlamaModel; +import ee.carlrobert.codegpt.settings.models.ModelDetailsState; import ee.carlrobert.codegpt.settings.models.ModelRegistry; import ee.carlrobert.codegpt.settings.models.ModelSelection; import ee.carlrobert.codegpt.settings.models.ModelSettings; @@ -51,7 +52,6 @@ import ee.carlrobert.llm.client.openai.completion.OpenAIChatCompletionModel; import java.awt.Color; import java.util.Arrays; import java.util.List; -import java.util.Objects; import java.util.function.Consumer; import javax.swing.Icon; import javax.swing.JComponent; @@ -72,7 +72,8 @@ public class ModelComboBoxAction extends ComboBoxAction { Project project, Consumer onModelChange, ServiceType selectedService) { - this(project, onModelChange, selectedService, Arrays.asList(ServiceType.values()), true, FeatureType.CHAT); + this(project, onModelChange, selectedService, Arrays.asList(ServiceType.values()), true, + FeatureType.CHAT); } public ModelComboBoxAction( @@ -81,7 +82,8 @@ public class ModelComboBoxAction extends ComboBoxAction { ServiceType selectedProvider, List availableProviders, boolean showConfigureModels) { - this(project, onModelChange, selectedProvider, availableProviders, showConfigureModels, FeatureType.CHAT); + this(project, onModelChange, selectedProvider, availableProviders, showConfigureModels, + FeatureType.CHAT); } public ModelComboBoxAction( @@ -349,10 +351,19 @@ public class ModelComboBoxAction extends ComboBoxAction { } private String getGooglePresentationText() { - var model = ApplicationManager.getApplication().getService(GoogleSettings.class) + var chatModel = ApplicationManager.getApplication() + .getService(ModelSettings.class) .getState() - .getModel(); - return ModelRegistry.getInstance().getModelDisplayName(GOOGLE, model); + .getModelSelection(featureType); + return ModelRegistry.getInstance().getModelDisplayName(GOOGLE, getGoogleModelCode(chatModel)); + } + + private String getGoogleModelCode(@Nullable ModelDetailsState chatModel) { + if (chatModel == null || chatModel.getModel() == null || chatModel.getModel().isBlank()) { + return ModelRegistry.GEMINI_PRO_2_5; + } + + return chatModel.getModel(); } private String getLlamaCppPresentationText() { @@ -473,8 +484,22 @@ public class ModelComboBoxAction extends ComboBoxAction { modelName, Icons.Google, comboBoxPresentation, - () -> ApplicationManager.getApplication().getService(ModelSettings.class) - .setModel(featureType, model.getCode(), GOOGLE)); + () -> { + // Persist selection in the unified ModelSettings used across features + ApplicationManager.getApplication() + .getService(ModelSettings.class) + .setModel(featureType, model.getCode(), GOOGLE); + + // Also mirror the selection into GoogleSettings for any legacy UI reads + try { + ApplicationManager.getApplication() + .getService(GoogleSettings.class) + .getState() + .setModel(model.getCode()); + } catch (Exception ignored) { + // Best-effort sync; lack of GoogleSettings should not block selection + } + }); } private AnAction createAnthropicModelAction(