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 15 commits into
base: main
Choose a base branch
from
Open
18 changes: 18 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,24 @@ 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);
}




Copy link
Member

Choose a reason for hiding this comment

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

Remove these extra newlines

.refresh {
-fx-background-color: transparent;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import org.jabref.gui.ai.components.aichat.chathistory.ChatHistoryComponent?>
<?import org.jabref.gui.ai.components.aichat.chatprompt.ChatPromptComponent?>
<?import org.jabref.gui.ai.components.util.Loadable?>
Expand All @@ -20,9 +16,31 @@
<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 +50,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())) {
exQuestionBox.getChildren().remove(hyperlink);
if (exQuestionBox.getChildren().size() == 1) {
this.getChildren().remove(exQuestionBox);
}
Comment on lines +130 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 exists in two places where the same condition and removal logic is repeated. Should be extracted to a separate 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 Expand Up @@ -174,8 +204,8 @@ private List<Notification> updateNotificationsForEntry(BibEntry entry) {
entry.getFiles().stream().map(file -> aiService.getIngestionService().ingest(file, bibDatabaseContext)).forEach(ingestionStatus -> {
switch (ingestionStatus.getState()) {
case PROCESSING -> notifications.add(new Notification(
Localization.lang("File %0 is currently being processed", ingestionStatus.getObject().getLink()),
Localization.lang("After the file will be ingested, you will be able to chat with it.")
Localization.lang("File %0 is currently being processed", ingestionStatus.getObject().getLink()),
Localization.lang("After the file will be ingested, you will be able to chat with it.")
));

case ERROR -> {
Expand Down Expand Up @@ -270,3 +300,4 @@ private void deleteLastMessage() {
}
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Revert this as well

Loading