Skip to content

Commit

Permalink
Fix issue #103
Browse files Browse the repository at this point in the history
  • Loading branch information
InAnYan committed Aug 3, 2024
1 parent cb5afca commit 89d7f77
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 16 deletions.
55 changes: 48 additions & 7 deletions src/main/java/org/jabref/gui/preferences/ai/AiTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,67 @@ public void initialize() {
temperatureTextField.valueProperty().bindBidirectional(viewModel.temperatureProperty().asObject());
temperatureTextField.disableProperty().bind(viewModel.disableExpertSettingsProperty());

// bindBidirectional doesn't work with contextWindowSizeTextField. Thus, it is written manually..
// bindBidirectional doesn't work well with number input fields ({@link IntegerInputField}, {@link DoubleInputField}),
// so they are expanded into `addListener` calls.

contextWindowSizeTextField.valueProperty().addListener((observable, oldValue, newValue) -> {
viewModel.contextWindowSizeProperty().set(newValue);
viewModel.contextWindowSizeProperty().set(newValue == null ? 0 : newValue);
});

viewModel.contextWindowSizeProperty().addListener((observable, oldValue, newValue) -> {
contextWindowSizeTextField.valueProperty().set(newValue.intValue());
contextWindowSizeTextField.valueProperty().set(newValue == null ? 0 : newValue.intValue());
});

temperatureTextField.valueProperty().addListener((observable, oldValue, newValue) -> {
viewModel.temperatureProperty().set(newValue == null ? 0 : newValue);
});

viewModel.temperatureProperty().addListener((observable, oldValue, newValue) -> {
temperatureTextField.valueProperty().set(newValue == null ? 0 : newValue.doubleValue());
});

temperatureTextField.disableProperty().bind(viewModel.disableExpertSettingsProperty());

contextWindowSizeTextField.disableProperty().bind(viewModel.disableExpertSettingsProperty());

documentSplitterChunkSizeTextField.valueProperty().bindBidirectional(viewModel.documentSplitterChunkSizeProperty().asObject());
documentSplitterChunkSizeTextField.valueProperty().addListener((observable, oldValue, newValue) -> {
viewModel.documentSplitterChunkSizeProperty().set(newValue == null ? 0 : newValue);
});

viewModel.documentSplitterChunkSizeProperty().addListener((observable, oldValue, newValue) -> {
documentSplitterChunkSizeTextField.valueProperty().set(newValue == null ? 0 : newValue.intValue());
});

documentSplitterChunkSizeTextField.disableProperty().bind(viewModel.disableExpertSettingsProperty());

documentSplitterOverlapSizeTextField.valueProperty().bindBidirectional(viewModel.documentSplitterOverlapSizeProperty().asObject());
documentSplitterOverlapSizeTextField.valueProperty().addListener((observable, oldValue, newValue) -> {
viewModel.documentSplitterOverlapSizeProperty().set(newValue == null ? 0 : newValue);
});

viewModel.documentSplitterOverlapSizeProperty().addListener((observable, oldValue, newValue) -> {
documentSplitterOverlapSizeTextField.valueProperty().set(newValue == null ? 0 : newValue.intValue());
});

documentSplitterOverlapSizeTextField.disableProperty().bind(viewModel.disableExpertSettingsProperty());

ragMaxResultsCountTextField.valueProperty().bindBidirectional(viewModel.ragMaxResultsCountProperty().asObject());
ragMaxResultsCountTextField.valueProperty().addListener((observable, oldValue, newValue) -> {
viewModel.ragMaxResultsCountProperty().set(newValue == null ? 0 : newValue);
});

viewModel.ragMaxResultsCountProperty().addListener((observable, oldValue, newValue) -> {
ragMaxResultsCountTextField.valueProperty().set(newValue == null ? 0 : newValue.intValue());
});

ragMaxResultsCountTextField.disableProperty().bind(viewModel.disableExpertSettingsProperty());

ragMinScoreTextField.valueProperty().bindBidirectional(viewModel.ragMinScoreProperty().asObject());
ragMinScoreTextField.valueProperty().addListener((observable, oldValue, newValue) -> {
viewModel.ragMinScoreProperty().set(newValue == null ? 0.0 : newValue);
});

viewModel.ragMinScoreProperty().addListener((observable, oldValue, newValue) -> {
ragMinScoreTextField.valueProperty().set(newValue == null ? 0.0 : newValue.doubleValue());
});

ragMinScoreTextField.disableProperty().bind(viewModel.disableExpertSettingsProperty());

Platform.runLater(() -> {
Expand Down
14 changes: 10 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 @@ -2,6 +2,7 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
Expand Down Expand Up @@ -209,14 +210,19 @@ public void storeSettings() {
}

public void resetExpertSettings() {
aiPreferences.setApiBaseUrl(AiDefaultPreferences.API_BASE_URL);
apiBaseUrl.setValue(AiDefaultPreferences.API_BASE_URL);
String resetApiBaseUrl = AiPreferences.PROVIDERS_API_URLS.get(selectedAiProvider.get());
aiPreferences.setApiBaseUrl(resetApiBaseUrl);
apiBaseUrl.setValue(resetApiBaseUrl);

aiPreferences.setInstruction(AiDefaultPreferences.SYSTEM_MESSAGE);
instruction.set(AiDefaultPreferences.SYSTEM_MESSAGE);

aiPreferences.setContextWindowSize(AiDefaultPreferences.CONTEXT_WINDOW_SIZE);
contextWindowSize.set(AiDefaultPreferences.CONTEXT_WINDOW_SIZE);
int resetContextWindowSize = Optional.ofNullable(AiPreferences.CONTEXT_WINDOW_SIZES.get(selectedAiProvider.get()).get(selectedChatModel.get())).orElse(0);
aiPreferences.setContextWindowSize(resetContextWindowSize);
contextWindowSize.set(resetContextWindowSize);

aiPreferences.setTemperature(AiDefaultPreferences.TEMPERATURE);
temperature.set(AiDefaultPreferences.TEMPERATURE);

aiPreferences.setDocumentSplitterChunkSize(AiDefaultPreferences.DOCUMENT_SPLITTER_CHUNK_SIZE);
documentSplitterChunkSize.set(AiDefaultPreferences.DOCUMENT_SPLITTER_CHUNK_SIZE);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/jabref/logic/ai/AiDefaultPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ public class AiDefaultPreferences {
public static final boolean CUSTOMIZE_SETTINGS = false;

public static final AiPreferences.EmbeddingModel EMBEDDING_MODEL = AiPreferences.EmbeddingModel.ALL_MINILM_L6_V2;
public static final String API_BASE_URL = "https://api.openai.com/v1/";
public static final String SYSTEM_MESSAGE = "You are an AI assistant that analyses research papers.";
public static final double TEMPERATURE = 0.7;
public static final int CONTEXT_WINDOW_SIZE = 4096;
public static final int DOCUMENT_SPLITTER_CHUNK_SIZE = 300;
public static final int DOCUMENT_SPLITTER_OVERLAP = 100;
public static final int RAG_MAX_RESULTS_COUNT = 10;
public static final double RAG_MIN_SCORE = 0.3;

// These parameters should be inferred from {@link AiPreferences.AiProvider} and {@link AiPreferences.getChatModel()}
// public static final String API_BASE_URL = "https://api.openai.com/v1/";
// public static final int CONTEXT_WINDOW_SIZE = 4096;
}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/preferences/AiPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public String toString() {
),
AiProvider.MISTRAL_AI, Map.of(
"mistral-large-latest", 128000,
"open-mistral-nemo", 1280000,
"open-mistral-nemo", 128000,
"open-mistral-7b", 32000,
"open-mixtral-8x7b", 32000,
"open-mixtral-8x22b", 64000
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -886,10 +886,10 @@ private JabRefPreferences() {
defaults.put(AI_CHAT_MODEL, AiDefaultPreferences.CHAT_MODEL);
defaults.put(AI_CUSTOMIZE_SETTINGS, AiDefaultPreferences.CUSTOMIZE_SETTINGS);
defaults.put(AI_EMBEDDING_MODEL, AiDefaultPreferences.EMBEDDING_MODEL.name());
defaults.put(AI_API_BASE_URL, AiDefaultPreferences.API_BASE_URL);
defaults.put(AI_API_BASE_URL, AiPreferences.PROVIDERS_API_URLS.get(AiDefaultPreferences.PROVIDER));
defaults.put(AI_SYSTEM_MESSAGE, AiDefaultPreferences.SYSTEM_MESSAGE);
defaults.put(AI_TEMPERATURE, AiDefaultPreferences.TEMPERATURE);
defaults.put(AI_CONTEXT_WINDOW_SIZE, AiDefaultPreferences.CONTEXT_WINDOW_SIZE);
defaults.put(AI_CONTEXT_WINDOW_SIZE, AiPreferences.CONTEXT_WINDOW_SIZES.get(AiDefaultPreferences.PROVIDER).get(AiDefaultPreferences.CHAT_MODEL));
defaults.put(AI_DOCUMENT_SPLITTER_CHUNK_SIZE, AiDefaultPreferences.DOCUMENT_SPLITTER_CHUNK_SIZE);
defaults.put(AI_DOCUMENT_SPLITTER_OVERLAP_SIZE, AiDefaultPreferences.DOCUMENT_SPLITTER_OVERLAP);
defaults.put(AI_RAG_MAX_RESULTS_COUNT, AiDefaultPreferences.RAG_MAX_RESULTS_COUNT);
Expand Down

0 comments on commit 89d7f77

Please sign in to comment.