Skip to content

Commit 0d5de68

Browse files
kaushikaWkopporsubhramitSiedlerchr
authored
Added example questions to AI chat (#12747)
* Added example questions to AI chat * Added example questions to AI chat * added inline FXML annotaions * fix dark mode support for example questions lables * refactored codes * Added example questions to AI chat # Conflicts: # src/main/java/org/jabref/gui/Base.css # src/main/java/org/jabref/gui/ai/components/aichat/AiChatComponent.fxml # src/main/java/org/jabref/gui/ai/components/aichat/AiChatComponent.java * merged * Merge branch 'main' into fix-for-issue-12745 * refactor the code for issue #12747 * remove unwanted lines in Base.css * remove unwanted lines in AI=iChatComponent.java * Update CHANGELOG.md * optimized imports in AiChatComponent.fxml * Clean up & optimize imports, clean up code style * Clean up and optimize imports in `AiTab.fxml` * added localization to ai chat * Added localization to the AI chat * added localization to ai chat * added localization to ai chat * make example questions strings contant strings --------- Co-authored-by: Oliver Kopp <[email protected]> Co-authored-by: Subhramit Basu <[email protected]> Co-authored-by: Christoph <[email protected]>
1 parent e7f65cc commit 0d5de68

File tree

6 files changed

+77
-6
lines changed

6 files changed

+77
-6
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
- We added a feature for enabling drag-and-drop of files into groups [#12540](https://github.com/JabRef/jabref/issues/12540)
2828
- 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)
2929
- 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)
30+
- We added a set of example questions to guide users in starting meaningful AI chat interactions. [#12702](https://github.com/JabRef/jabref/issues/12702)
3031
- We added support for loading and displaying BibTeX .blg warnings in the Check integrity dialog, with custom path selection and metadata persistence. [#11998](https://github.com/JabRef/jabref/issues/11998)
3132
- We added an option to choose whether to open the file explorer in the files directory or in the last opened directory when attaching files. [#12554](https://github.com/JabRef/jabref/issues/12554)
3233
- We enhanced support for parsing XMP metadata from PDF files. [#12829](https://github.com/JabRef/jabref/issues/12829)

src/main/java/org/jabref/gui/Base.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,6 +2493,21 @@ journalInfo .grid-cell-b {
24932493
-fx-font-size: 1em; -fx-font-weight: bold; -fx-text-fill: -jr-theme;
24942494
}
24952495

2496+
.exampleQuestionStyle {
2497+
-fx-background-color: transparent;
2498+
-fx-padding: 2px 10px;
2499+
-fx-background-radius: 20px;
2500+
-fx-border-radius: 20px;
2501+
-fx-border-width: 0.062em;
2502+
-fx-border-color: -fx-outer-border;
2503+
-fx-font-weight: bold;
2504+
-fx-underline: false !important;
2505+
-fx-text-fill: -fx-text-base-color;
2506+
}
2507+
.exampleQuestionStyle:hover {
2508+
-fx-background-color: rgba(0, 0, 0, 0.12);
2509+
}
2510+
24962511
.refresh {
24972512
-fx-background-color: transparent;
24982513
}

src/main/java/org/jabref/gui/ai/components/aichat/AiChatComponent.fxml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<?import org.jabref.gui.ai.components.aichat.chatprompt.ChatPromptComponent?>
1212
<?import org.jabref.gui.ai.components.util.Loadable?>
1313
<?import org.jabref.gui.icon.JabRefIconView?>
14+
<?import javafx.scene.control.Hyperlink?>
1415
<fx:root type="javafx.scene.layout.VBox"
1516
spacing="10"
1617
xmlns="http://javafx.com/javafx/17.0.2-ea"
@@ -20,9 +21,16 @@
2021
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
2122
</padding>
2223
<Loadable fx:id="uiLoadableChatHistory" VBox.vgrow="ALWAYS">
23-
<ChatHistoryComponent fx:id="uiChatHistory" VBox.vgrow="ALWAYS" fitToWidth="true" />
24+
<ChatHistoryComponent fx:id="uiChatHistory" VBox.vgrow="ALWAYS" fitToWidth="true"/>
2425
</Loadable>
2526

27+
<HBox spacing="10" alignment="CENTER" fx:id="exQuestionBox">
28+
<Label text="%Try with examples" BorderPane.alignment="CENTER"/>
29+
<Hyperlink fx:id="exQuestion1" BorderPane.alignment="CENTER" styleClass="exampleQuestionStyle"/>
30+
<Hyperlink fx:id="exQuestion2" BorderPane.alignment="CENTER" styleClass="exampleQuestionStyle"/>
31+
<Hyperlink fx:id="exQuestion3" BorderPane.alignment="CENTER" styleClass="exampleQuestionStyle"/>
32+
</HBox>
33+
2634
<HBox spacing="10">
2735
<Button alignment="CENTER"
2836
fx:id="notificationsButton"
@@ -32,7 +40,7 @@
3240
<Tooltip text="%Notifications"/>
3341
</tooltip>
3442
</Button>
35-
<ChatPromptComponent fx:id="chatPrompt" HBox.hgrow="ALWAYS" />
43+
<ChatPromptComponent fx:id="chatPrompt" HBox.hgrow="ALWAYS"/>
3644
</HBox>
3745
<HBox alignment="CENTER" spacing="50">
3846
<Label fx:id="noticeText"

src/main/java/org/jabref/gui/ai/components/aichat/AiChatComponent.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import javafx.collections.ObservableList;
1111
import javafx.fxml.FXML;
1212
import javafx.scene.control.Button;
13+
import javafx.scene.control.Hyperlink;
1314
import javafx.scene.control.Label;
15+
import javafx.scene.layout.HBox;
1416
import javafx.scene.layout.VBox;
1517
import javafx.scene.paint.Color;
1618

@@ -46,6 +48,11 @@
4648
public class AiChatComponent extends VBox {
4749
private static final Logger LOGGER = LoggerFactory.getLogger(AiChatComponent.class);
4850

51+
// Example Questions
52+
private static final String EXAMPLE_QUESTION_1 = Localization.lang("What is the goal of the paper?");
53+
private static final String EXAMPLE_QUESTION_2 = Localization.lang("Which methods were used in the research?");
54+
private static final String EXAMPLE_QUESTION_3 = Localization.lang("What are the key findings?");
55+
4956
private final AiService aiService;
5057
private final ObservableList<BibEntry> entries;
5158
private final BibDatabaseContext bibDatabaseContext;
@@ -57,11 +64,17 @@ public class AiChatComponent extends VBox {
5764

5865
private final ObservableList<Notification> notifications = FXCollections.observableArrayList();
5966

67+
68+
6069
@FXML private Loadable uiLoadableChatHistory;
6170
@FXML private ChatHistoryComponent uiChatHistory;
6271
@FXML private Button notificationsButton;
6372
@FXML private ChatPromptComponent chatPrompt;
6473
@FXML private Label noticeText;
74+
@FXML private Hyperlink exQuestion1;
75+
@FXML private Hyperlink exQuestion2;
76+
@FXML private Hyperlink exQuestion3;
77+
@FXML private HBox exQuestionBox;
6578

6679
public AiChatComponent(AiService aiService,
6780
StringProperty name,
@@ -94,6 +107,8 @@ public void initialize() {
94107
initializeChatPrompt();
95108
initializeNotice();
96109
initializeNotifications();
110+
sendExampleQuestions();
111+
initializeExampleQuestions();
97112
}
98113

99114
private void initializeNotifications() {
@@ -111,6 +126,35 @@ private void initializeNotice() {
111126
noticeText.setText(newNotice);
112127
}
113128

129+
private void initializeExampleQuestions() {
130+
exQuestion1.setText(EXAMPLE_QUESTION_1);
131+
exQuestion2.setText(EXAMPLE_QUESTION_2);
132+
exQuestion3.setText(EXAMPLE_QUESTION_3);
133+
}
134+
135+
private void sendExampleQuestions() {
136+
addExampleQuestionAction(exQuestion1);
137+
addExampleQuestionAction(exQuestion2);
138+
addExampleQuestionAction(exQuestion3);
139+
}
140+
141+
private void addExampleQuestionAction(Hyperlink hyperlink) {
142+
if (chatPrompt.getHistory().contains(hyperlink.getText())) {
143+
exQuestionBox.getChildren().remove(hyperlink);
144+
if (exQuestionBox.getChildren().size() == 1) {
145+
this.getChildren().remove(exQuestionBox);
146+
}
147+
return;
148+
}
149+
hyperlink.setOnAction(event -> {
150+
onSendMessage(hyperlink.getText());
151+
exQuestionBox.getChildren().remove(hyperlink);
152+
if (exQuestionBox.getChildren().size() == 1) {
153+
this.getChildren().remove(exQuestionBox);
154+
}
155+
});
156+
}
157+
114158
private void initializeChatPrompt() {
115159
notificationsButton.setOnAction(event ->
116160
new PopOver(new NotificationsComponent(notifications))

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@
55
<?import javafx.scene.control.CheckBox?>
66
<?import javafx.scene.control.ComboBox?>
77
<?import javafx.scene.control.Label?>
8+
<?import javafx.scene.control.Tab?>
9+
<?import javafx.scene.control.TabPane?>
10+
<?import javafx.scene.control.TextArea?>
811
<?import javafx.scene.control.TextField?>
912
<?import javafx.scene.layout.ColumnConstraints?>
1013
<?import javafx.scene.layout.GridPane?>
1114
<?import javafx.scene.layout.HBox?>
1215
<?import javafx.scene.layout.VBox?>
1316
<?import javafx.scene.text.Font?>
1417
<?import org.jabref.gui.icon.JabRefIconView?>
15-
<?import com.dlsc.gemsfx.ResizableTextArea?>
1618
<?import com.dlsc.unitfx.IntegerInputField?>
1719
<?import org.controlsfx.control.SearchableComboBox?>
1820
<?import org.controlsfx.control.textfield.CustomPasswordField?>
19-
<?import javafx.scene.control.TabPane?>
20-
<?import javafx.scene.control.Tab?>
21-
<?import javafx.scene.control.TextArea?>
2221
<fx:root
2322
spacing="10.0"
2423
type="VBox"

src/main/resources/l10n/JabRef_en.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,10 @@ System\ message\ for\ chatting=System message for chatting
27142714
User\ message\ for\ chatting=User message for chatting
27152715
Completion\ text\ for\ summarization\ of\ a\ chunk=Completion text for summarization of a chunk
27162716
Completion\ text\ for\ summarization\ of\ several\ chunks=Completion text for summarization of several chunks
2717+
Try\ with\ examples=Try with examples
2718+
What\ is\ the\ goal\ of\ the\ paper?=What is the goal of the paper?
2719+
Which\ methods\ were\ used\ in\ the\ research?=Which methods were used in the research?
2720+
What\ are\ the\ key\ findings?=What are the key findings?
27172721
27182722
Link=Link
27192723
Source\ URL=Source URL

0 commit comments

Comments
 (0)