Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example questions to AI chat #12747

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added a feature for enabling drag-and-drop of files into groups [#12540](https://github.com/JabRef/jabref/issues/12540)
- We added support for reordering keywords via drag and drop, automatic alphabetical ordering, and improved pasting and editing functionalities in the keyword editor. [#10984](https://github.com/JabRef/jabref/issues/10984)
- We added a new functionality where author names having multiple spaces in-between will be considered as separate user block as it does for " and ". [#12701](https://github.com/JabRef/jabref/issues/12701)
- We added a set of example questions to guide users in starting meaningful AI chat interactions. [#12702](https://github.com/JabRef/jabref/issues/12702)

### Changed

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,21 @@ journalInfo .grid-cell-b {
-fx-font-size: 1em; -fx-font-weight: bold; -fx-text-fill: -jr-theme;
}

.exampleQuestionStyle {
-fx-background-color: transparent;
-fx-padding: 2px 10px;
-fx-background-radius: 20px;
-fx-border-radius: 20px;
-fx-border-width: 0.062em;
-fx-border-color: -fx-outer-border;
-fx-font-weight: bold;
-fx-underline: false !important;
-fx-text-fill: -fx-text-base-color;
}
.exampleQuestionStyle:hover {
-fx-background-color: rgba(0, 0, 0, 0.12);
}

.refresh {
-fx-background-color: transparent;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<?import org.jabref.gui.ai.components.aichat.chatprompt.ChatPromptComponent?>
<?import org.jabref.gui.ai.components.util.Loadable?>
<?import org.jabref.gui.icon.JabRefIconView?>
<?import javafx.scene.control.Hyperlink?>
<fx:root type="javafx.scene.layout.VBox"
spacing="10"
xmlns="http://javafx.com/javafx/17.0.2-ea"
Expand All @@ -20,9 +21,16 @@
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
<Loadable fx:id="uiLoadableChatHistory" VBox.vgrow="ALWAYS">
<ChatHistoryComponent fx:id="uiChatHistory" VBox.vgrow="ALWAYS" fitToWidth="true" />
<ChatHistoryComponent fx:id="uiChatHistory" VBox.vgrow="ALWAYS" fitToWidth="true"/>
</Loadable>

<HBox spacing="10" alignment="CENTER" fx:id="exQuestionBox">
<Label text="Try with examples" BorderPane.alignment="CENTER"/>
<Hyperlink fx:id="exQuestion1" text="What is the goal of the paper?" BorderPane.alignment="CENTER" styleClass="exampleQuestionStyle"/>
<Hyperlink fx:id="exQuestion2" text="Which methods were used in the research?" BorderPane.alignment="CENTER" styleClass="exampleQuestionStyle"/>
<Hyperlink fx:id="exQuestion3" text="What are the key findings?" BorderPane.alignment="CENTER" styleClass="exampleQuestionStyle"/>
</HBox>

<HBox spacing="10">
<Button alignment="CENTER"
fx:id="notificationsButton"
Expand All @@ -32,7 +40,7 @@
<Tooltip text="%Notifications"/>
</tooltip>
</Button>
<ChatPromptComponent fx:id="chatPrompt" HBox.hgrow="ALWAYS" />
<ChatPromptComponent fx:id="chatPrompt" HBox.hgrow="ALWAYS"/>
</HBox>
<HBox alignment="CENTER" spacing="50">
<Label fx:id="noticeText"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;

this is needed for my code suggestion to work properly.

import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;

Expand Down Expand Up @@ -62,6 +64,10 @@ public class AiChatComponent extends VBox {
@FXML private Button notificationsButton;
@FXML private ChatPromptComponent chatPrompt;
@FXML private Label noticeText;
@FXML private Hyperlink exQuestion1;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@palukku added inline FXML annotations

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@FXML private Hyperlink exQuestion1;
@FXML private HBox exQuestionBox;
@FXML private Hyperlink exQuestion1;

@FXML private Hyperlink exQuestion2;
@FXML private Hyperlink exQuestion3;
@FXML private HBox exQuestionBox;

public AiChatComponent(AiService aiService,
StringProperty name,
Expand Down Expand Up @@ -94,6 +100,7 @@ public void initialize() {
initializeChatPrompt();
initializeNotice();
initializeNotifications();
sendExampleQuestions();
}

private void initializeNotifications() {
Expand All @@ -111,6 +118,29 @@ private void initializeNotice() {
noticeText.setText(newNotice);
}

private void sendExampleQuestions() {
addExampleQuestionAction(exQuestion1);
addExampleQuestionAction(exQuestion2);
addExampleQuestionAction(exQuestion3);
}

private void addExampleQuestionAction(Hyperlink hyperlink) {
if (chatPrompt.getHistory().contains(hyperlink.getText())) {
Comment on lines +127 to +128
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method violates fail-fast principle by nesting logic inside else branch implicitly. The early return pattern should be used after the condition check.

exQuestionBox.getChildren().remove(hyperlink);
if (exQuestionBox.getChildren().size() == 1) {
this.getChildren().remove(exQuestionBox);
}
Comment on lines +129 to +132
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code duplication detected. The same removal logic appears twice in the method. Should be extracted to a separate private method.

return;
}
hyperlink.setOnAction(event -> {
onSendMessage(hyperlink.getText());
exQuestionBox.getChildren().remove(hyperlink);
if (exQuestionBox.getChildren().size() == 1) {
this.getChildren().remove(exQuestionBox);
}
});
}

private void initializeChatPrompt() {
notificationsButton.setOnAction(event ->
new PopOver(new NotificationsComponent(notifications))
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/jabref/gui/preferences/ai/AiTab.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<?import org.jabref.gui.icon.JabRefIconView?>
<?import com.dlsc.gemsfx.ResizableTextArea?>
<?import com.dlsc.unitfx.IntegerInputField?>
<?import org.controlsfx.control.SearchableComboBox?>
<?import org.controlsfx.control.textfield.CustomPasswordField?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TextArea?>
<fx:root
spacing="10.0"
type="VBox"
Expand Down
Loading