Skip to content

Commit

Permalink
Fix AI settings (#12158)
Browse files Browse the repository at this point in the history
  • Loading branch information
InAnYan authored Nov 5, 2024
1 parent d77dcbd commit a83cdaa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/main/java/org/jabref/gui/preferences/ai/AiTabViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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 -> {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/logic/ai/AiPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public StringProperty gpt4AllChatModelProperty() {
}

public String getGpt4AllChatModel() {
return huggingFaceChatModel.get();
return gpt4AllChatModel.get();
}

public void setGpt4AllChatModel(String gpt4AllChatModel) {
Expand Down

0 comments on commit a83cdaa

Please sign in to comment.