From 08071b138e19575a85b1383fbfcffd6791e84076 Mon Sep 17 00:00:00 2001 From: InAnYan Date: Tue, 5 Nov 2024 11:14:57 +0200 Subject: [PATCH 1/2] Fix AI settings --- .../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) { From 763f4d5e5f5d02d5f8f8583ad3c7e21abd94c4e8 Mon Sep 17 00:00:00 2001 From: InAnYan Date: Mon, 11 Nov 2024 23:19:19 +0200 Subject: [PATCH 2/2] Add `entries` variable to user message template --- src/main/java/org/jabref/logic/ai/chatting/AiChatLogic.java | 2 +- .../java/org/jabref/logic/ai/templates/TemplatesService.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/ai/chatting/AiChatLogic.java b/src/main/java/org/jabref/logic/ai/chatting/AiChatLogic.java index d237afbdd0b..fb6f5656cdf 100644 --- a/src/main/java/org/jabref/logic/ai/chatting/AiChatLogic.java +++ b/src/main/java/org/jabref/logic/ai/chatting/AiChatLogic.java @@ -171,7 +171,7 @@ public AiMessage execute(UserMessage message) { chatMemory.messages().forEach(tempChatMemory::add); - tempChatMemory.add(new UserMessage(templatesService.makeChattingUserMessage(message.singleText(), excerpts))); + tempChatMemory.add(new UserMessage(templatesService.makeChattingUserMessage(entries, message.singleText(), excerpts))); chatMemory.add(message); AiMessage aiMessage = chatLanguageModel.generate(tempChatMemory.messages()).content(); diff --git a/src/main/java/org/jabref/logic/ai/templates/TemplatesService.java b/src/main/java/org/jabref/logic/ai/templates/TemplatesService.java index 79e1634491d..c130670d0bd 100644 --- a/src/main/java/org/jabref/logic/ai/templates/TemplatesService.java +++ b/src/main/java/org/jabref/logic/ai/templates/TemplatesService.java @@ -30,8 +30,9 @@ public String makeChattingSystemMessage(List entries) { return makeTemplate(AiTemplate.CHATTING_SYSTEM_MESSAGE, context); } - public String makeChattingUserMessage(String message, List excerpts) { + public String makeChattingUserMessage(List entries, String message, List excerpts) { VelocityContext context = new VelocityContext(baseContext); + context.put("entries", entries); context.put("message", message); context.put("excerpts", excerpts);