From a83cdaa2524b7e24aadf70f97a0700b6abcbacf4 Mon Sep 17 00:00:00 2001 From: Ruslan Date: Tue, 5 Nov 2024 11:34:51 +0200 Subject: [PATCH] Fix AI settings (#12158) --- .../jabref/gui/preferences/ai/AiTabViewModel.java | 12 ++++++++---- src/main/java/org/jabref/logic/ai/AiPreferences.java | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/ai/AiTabViewModel.java b/src/main/java/org/jabref/gui/preferences/ai/AiTabViewModel.java index 2cb019cf968..c47da76d38b 100644 --- a/src/main/java/org/jabref/gui/preferences/ai/AiTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/ai/AiTabViewModel.java @@ -125,20 +125,20 @@ public AiTabViewModel(CliPreferences preferences) { }); this.customizeExpertSettings.addListener((observableValue, oldValue, newValue) -> - disableExpertSettings.set(!newValue || !enableAi.get()) + disableExpertSettings.set(!newValue || !enableAi.get()) ); this.selectedAiProvider.addListener((observable, oldValue, newValue) -> { List models = AiDefaultPreferences.getAvailableModels(newValue); + disableApiBaseUrl.set(newValue == AiProvider.HUGGING_FACE || newValue == AiProvider.GEMINI); + // When we setAll on Hugging Face, models are empty, and currentChatModel become null. - // It becomes null beause currentChatModel is binded to combobox, and this combobox becomes empty. + // It becomes null because currentChatModel is bound to combobox, and this combobox becomes empty. // For some reason, custom edited value in the combobox will be erased, so we need to store the old value. String oldChatModel = currentChatModel.get(); chatModelsList.setAll(models); - disableApiBaseUrl.set(newValue == AiProvider.HUGGING_FACE || newValue == AiProvider.GEMINI); - if (oldValue != null) { switch (oldValue) { case OPEN_AI -> { @@ -199,6 +199,10 @@ public AiTabViewModel(CliPreferences preferences) { }); this.currentChatModel.addListener((observable, oldValue, newValue) -> { + if (newValue == null) { + return; + } + switch (selectedAiProvider.get()) { case OPEN_AI -> openAiChatModel.set(newValue); case MISTRAL_AI -> mistralAiChatModel.set(newValue); diff --git a/src/main/java/org/jabref/logic/ai/AiPreferences.java b/src/main/java/org/jabref/logic/ai/AiPreferences.java index de1025e72d7..9b6787e2d4d 100644 --- a/src/main/java/org/jabref/logic/ai/AiPreferences.java +++ b/src/main/java/org/jabref/logic/ai/AiPreferences.java @@ -256,7 +256,7 @@ public StringProperty gpt4AllChatModelProperty() { } public String getGpt4AllChatModel() { - return huggingFaceChatModel.get(); + return gpt4AllChatModel.get(); } public void setGpt4AllChatModel(String gpt4AllChatModel) {