Skip to content

Commit 72caef0

Browse files
ganesh-vkcalixtus
andauthored
Offer Additional AI preferences and update to the latest Gemini models (#15400)
* - Add preference to allow user to choose if they want to store API key for AI models - Add preference to allow user to view API key for AI models - Move to latest gemini models and remove deprecated models * Add missing localization keys * Change test to fit new model name * Fix casing * trigger CI * Address review comments - Remove view api key toggle and place toggle inside the checkbox - Rename "Remember API key" to "Persist API key across sessions" - Change default persist api key preference to true * Replace Custom Password field with EnhancedPasswordField from GemsFX * Fix conflict * trigger CI * Address review comments * Remove the preference to persist API key across restarts and revert to original behaviour. Add a delete button in the API key field to improve UX. --------- Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
1 parent 5f3b65e commit 72caef0

File tree

8 files changed

+168
-114
lines changed

8 files changed

+168
-114
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
2727

2828
### Changed
2929

30+
- We replaced deprecated Gemini Models from the AI chat model selection and with current ones. [#15398](https://github.com/JabRef/jabref/issues/15398)
3031
- We changed CSL reference format by adding citation type at the end. [#15370](https://github.com/JabRef/jabref/issues/15370) [#15434](https://github.com/JabRef/jabref/issues/15434)
3132
- We changed the groups filter field to use a filter icon. [#15402](https://github.com/JabRef/jabref/issues/15402)
3233
- We improved the MultiMergeEntries dialog to automatically select the most plausible field value when merging entries (e.g. a more specific date). [#15027](https://github.com/JabRef/jabref/issues/15027)

jabgui/src/main/java/org/jabref/gui/preferences/ai/AiTab.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
import javafx.scene.control.TabPane;
1616
import javafx.scene.control.TextArea;
1717
import javafx.scene.control.TextField;
18+
import javafx.scene.layout.HBox;
1819
import javafx.scene.layout.VBox;
1920

2021
import org.jabref.gui.actions.ActionFactory;
2122
import org.jabref.gui.actions.StandardActions;
2223
import org.jabref.gui.help.HelpAction;
24+
import org.jabref.gui.icon.IconTheme;
2325
import org.jabref.gui.preferences.AbstractPreferenceTabView;
2426
import org.jabref.gui.preferences.PreferencesTab;
2527
import org.jabref.gui.util.ViewModelListCellFactory;
@@ -30,14 +32,12 @@
3032
import org.jabref.model.ai.EmbeddingModel;
3133

3234
import com.airhacks.afterburner.views.ViewLoader;
35+
import com.dlsc.gemsfx.EnhancedPasswordField;
3336
import com.dlsc.unitfx.IntegerInputField;
3437
import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer;
3538
import org.controlsfx.control.SearchableComboBox;
36-
import org.controlsfx.control.textfield.CustomPasswordField;
3739

3840
public class AiTab extends AbstractPreferenceTabView<AiTabViewModel> implements PreferencesTab {
39-
private static final String HUGGING_FACE_CHAT_MODEL_PROMPT = "TinyLlama/TinyLlama_v1.1 (or any other model name)";
40-
private static final String GPT_4_ALL_CHAT_MODEL_PROMPT = "Phi-3.1-mini (or any other local model name from GPT4All)";
4141

4242
@FXML private CheckBox enableAi;
4343
@FXML private CheckBox autoGenerateEmbeddings;
@@ -50,7 +50,7 @@ public class AiTab extends AbstractPreferenceTabView<AiTabViewModel> implements
5050

5151
@FXML private ComboBox<AiProvider> aiProviderComboBox;
5252
@FXML private ComboBox<String> chatModelComboBox;
53-
@FXML private CustomPasswordField apiKeyTextField;
53+
@FXML private EnhancedPasswordField apiKeyTextField;
5454

5555
@FXML private CheckBox customizeExpertSettingsCheckbox;
5656
@FXML private VBox expertSettingsPane;
@@ -213,13 +213,27 @@ private void initializeExpertSettings() {
213213

214214
private void initializeApiKey() {
215215
apiKeyTextField.textProperty().bindBidirectional(viewModel.apiKeyProperty());
216+
216217
// Disable if GPT4ALL is selected
217218
apiKeyTextField.disableProperty().bind(
218219
Bindings.or(
219220
viewModel.disableBasicSettingsProperty(),
220221
aiProviderComboBox.valueProperty().isEqualTo(AiProvider.GPT4ALL)
221222
)
222223
);
224+
225+
Button revealApiKeyButton = IconTheme.JabRefIcons.PASSWORD_REVEALED.asButton();
226+
revealApiKeyButton.disableProperty().bind(apiKeyTextField.disableProperty());
227+
revealApiKeyButton.setOnAction(_ -> apiKeyTextField.setShowPassword(!apiKeyTextField.isShowPassword()));
228+
229+
Button clearApiKeyButton = IconTheme.JabRefIcons.DELETE_ENTRY.asButton();
230+
clearApiKeyButton.disableProperty().bind(apiKeyTextField.disableProperty());
231+
clearApiKeyButton.setOnAction(_ -> {
232+
apiKeyTextField.clear();
233+
apiKeyTextField.requestFocus();
234+
});
235+
236+
apiKeyTextField.setRight(new HBox(revealApiKeyButton, clearApiKeyButton));
223237
}
224238

225239
private void initializeChatModel() {
@@ -232,10 +246,10 @@ private void initializeChatModel() {
232246

233247
this.aiProviderComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
234248
if (newValue == AiProvider.HUGGING_FACE) {
235-
chatModelComboBox.setPromptText(HUGGING_FACE_CHAT_MODEL_PROMPT);
249+
chatModelComboBox.setPromptText(Localization.lang("TinyLlama/TinyLlama_v1.1 (or any other model name)"));
236250
}
237251
if (newValue == AiProvider.GPT4ALL) {
238-
chatModelComboBox.setPromptText(GPT_4_ALL_CHAT_MODEL_PROMPT);
252+
chatModelComboBox.setPromptText(Localization.lang("Phi-3.1-mini (or any other local model name from GPT4All)"));
239253
}
240254
});
241255
}

jabgui/src/main/java/org/jabref/gui/preferences/network/NetworkTab.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import org.jabref.logic.l10n.Localization;
2626

2727
import com.airhacks.afterburner.views.ViewLoader;
28+
import com.dlsc.gemsfx.EnhancedPasswordField;
2829
import com.tobiasdiez.easybind.EasyBind;
2930
import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer;
30-
import org.controlsfx.control.textfield.CustomPasswordField;
3131

3232
import static javafx.beans.binding.Bindings.not;
3333

@@ -44,7 +44,7 @@ public class NetworkTab extends AbstractPreferenceTabView<NetworkTabViewModel> i
4444
@FXML private Label proxyUsernameLabel;
4545
@FXML private TextField proxyUsername;
4646
@FXML private Label proxyPasswordLabel;
47-
@FXML private CustomPasswordField proxyPassword;
47+
@FXML private EnhancedPasswordField proxyPassword;
4848
@FXML private CheckBox proxyPersistPassword;
4949
@FXML private SplitPane persistentTooltipWrapper; // The disabled persistPassword control does not show tooltips
5050
@FXML private Button checkConnectionButton;
@@ -54,7 +54,7 @@ public class NetworkTab extends AbstractPreferenceTabView<NetworkTabViewModel> i
5454
// endregion
5555

5656
@FXML private TextField gitUsername;
57-
@FXML private CustomPasswordField gitPat;
57+
@FXML private EnhancedPasswordField gitPat;
5858
@FXML private CheckBox gitPersistPat;
5959
@FXML private SplitPane persistGitPatTooltipWrapper;
6060
private String gitPatText = "";
@@ -118,9 +118,9 @@ public void initialize() {
118118
});
119119

120120
proxyPassword.setRight(IconTheme.JabRefIcons.PASSWORD_REVEALED.getGraphicNode());
121-
proxyPassword.getRight().addEventFilter(MouseEvent.MOUSE_PRESSED, this::proxyPasswordReveal);
122-
proxyPassword.getRight().addEventFilter(MouseEvent.MOUSE_RELEASED, this::proxyPasswordMask);
123-
proxyPassword.getRight().addEventFilter(MouseEvent.MOUSE_EXITED, this::proxyPasswordMask);
121+
proxyPassword.setOnMouseClicked(event -> {
122+
proxyPassword.setShowPassword(!proxyPassword.isShowPassword());
123+
});
124124

125125
validationVisualizer.setDecoration(new IconValidationDecorator());
126126
Platform.runLater(() -> {
@@ -142,9 +142,9 @@ public void initialize() {
142142
});
143143

144144
gitPat.setRight(IconTheme.JabRefIcons.PASSWORD_REVEALED.getGraphicNode());
145-
gitPat.getRight().addEventFilter(MouseEvent.MOUSE_PRESSED, this::gitPatReveal);
146-
gitPat.getRight().addEventFilter(MouseEvent.MOUSE_RELEASED, this::gitPatMask);
147-
gitPat.getRight().addEventFilter(MouseEvent.MOUSE_EXITED, this::gitPatMask);
145+
gitPat.setOnMouseClicked(event -> {
146+
gitPat.setShowPassword(!gitPat.isShowPassword());
147+
});
148148

149149
certSerialNumber.setCellValueFactory(data -> data.getValue().serialNumberProperty());
150150
certIssuer.setCellValueFactory(data -> data.getValue().issuerProperty());
@@ -189,23 +189,6 @@ private void proxyPasswordMask(MouseEvent event) {
189189
}
190190
}
191191

192-
private void gitPatReveal(MouseEvent event) {
193-
gitPatText = gitPat.getText();
194-
gitPatCaretPosition = gitPat.getCaretPosition();
195-
gitPat.clear();
196-
gitPat.setPromptText(gitPatText);
197-
}
198-
199-
private void gitPatMask(MouseEvent event) {
200-
if (!"".equals(gitPatText)) {
201-
gitPat.setText(gitPatText);
202-
gitPat.positionCaret(gitPatCaretPosition);
203-
gitPat.setPromptText("");
204-
gitPatText = "";
205-
gitPatCaretPosition = 0;
206-
}
207-
}
208-
209192
@FXML
210193
void checkConnection() {
211194
viewModel.checkConnection();

0 commit comments

Comments
 (0)