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 #12745

Closed
wants to merge 2 commits into from
Closed
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
30 changes: 30 additions & 0 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
@@ -2431,3 +2431,33 @@ journalInfo .grid-cell-b {
#styleSelectDialog .currentStyleNameLabel {
-fx-font-size: 1em; -fx-font-weight: bold; -fx-text-fill: -jr-theme;
}

exampleQuestionLabelStyle {
-fx-background-color: #f1f1f1;
-fx-padding: 2px 10px;
-fx-background-radius: 20px;
-fx-border-radius: 20px;
-fx-border-width: 0px;
-fx-font-weight: bold;
-fx-focus-color: transparent;
-fx-faint-focus-color: transparent;
}


.exampleQuestionStyle {
-fx-background-color: #d8d8d8;
-fx-padding: 2px 10px;
-fx-background-radius: 20px;
-fx-border-radius: 20px;
-fx-border-width: 0px;
-fx-font-weight: bold;
-fx-focus-color: transparent;
-fx-faint-focus-color: transparent;
}

.exampleQuestionStyle:hover {
-fx-background-color: #8a8a8a;
}



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?>
@@ -20,9 +16,36 @@
<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">
<Label
fx:id="exQuestionLabel"
text="Try with examples"
BorderPane.alignment="CENTER"
styleClass="exampleQuestionLabelStyle"
/>
<Hyperlink fx:id="exQuestion1"
text="What is the goal of the paper?"
BorderPane.alignment="CENTER"
onAction="#sendExampleQuestion1Prompt"
styleClass="exampleQuestionStyle"
style="-fx-underline: false; -fx-text-fill: -fx-mid-text-color;"/>
<Hyperlink fx:id="exQuestion2"
text="Which methods were used in the research?"
BorderPane.alignment="CENTER"
onAction="#sendExampleQuestion2Prompt"
styleClass="exampleQuestionStyle"
style="-fx-underline: false; -fx-text-fill: -fx-mid-text-color;"/>
<Hyperlink fx:id="exQuestion3"
text="What are the key findings?"
BorderPane.alignment="CENTER"
onAction="#sendExampleQuestion3Prompt"
styleClass="exampleQuestionStyle"
style="-fx-underline: false; -fx-text-fill: -fx-mid-text-color;"/>
</HBox>

<HBox spacing="10">
<Button alignment="CENTER"
fx:id="notificationsButton"
@@ -32,7 +55,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"
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package org.jabref.gui.ai.components.aichat;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

import com.airhacks.afterburner.views.ViewLoader;
import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.ChatMessage;
import dev.langchain4j.data.message.UserMessage;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;

import org.controlsfx.control.PopOver;
import org.jabref.gui.DialogService;
import org.jabref.gui.ai.components.aichat.chathistory.ChatHistoryComponent;
import org.jabref.gui.ai.components.aichat.chatprompt.ChatPromptComponent;
@@ -34,15 +34,14 @@
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.util.ListUtil;

import com.airhacks.afterburner.views.ViewLoader;
import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.ChatMessage;
import dev.langchain4j.data.message.UserMessage;
import org.controlsfx.control.PopOver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

public class AiChatComponent extends VBox {
private static final Logger LOGGER = LoggerFactory.getLogger(AiChatComponent.class);

@@ -62,6 +61,10 @@ public class AiChatComponent extends VBox {
@FXML private Button notificationsButton;
@FXML private ChatPromptComponent chatPrompt;
@FXML private Label noticeText;
@FXML private Hyperlink exQuestion1;
@FXML private Hyperlink exQuestion2;
@FXML private Hyperlink exQuestion3;
@FXML private Label exQuestionLabel;

public AiChatComponent(AiService aiService,
StringProperty name,
@@ -94,6 +97,7 @@ public void initialize() {
initializeChatPrompt();
initializeNotice();
initializeNotifications();
initializeExampleQuestions();
}

private void initializeNotifications() {
@@ -111,6 +115,18 @@ private void initializeNotice() {
noticeText.setText(newNotice);
}

private void initializeExampleQuestions() {
String newExampleLabel = exQuestionLabel.getText();
String newExQuestion1 = exQuestion1.getText();
String newExQuestion2 = exQuestion2.getText();
String newExQuestion3 = exQuestion3.getText();

exQuestion1.setText(newExQuestion1);
exQuestion2.setText(newExQuestion2);
exQuestion3.setText(newExQuestion3);
exQuestionLabel.setText(newExampleLabel);
}
Comment on lines +118 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 reads text values and sets them back without any transformation, making these operations redundant and potentially confusing. This violates clean code principles and adds unnecessary complexity.

Comment on lines +118 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 gets text from UI elements and sets the same text back to them without any transformation, making these operations redundant and potentially causing unnecessary UI updates.


private void initializeChatPrompt() {
notificationsButton.setOnAction(event ->
new PopOver(new NotificationsComponent(notifications))
@@ -174,8 +190,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 -> {
@@ -269,4 +285,23 @@ private void deleteLastMessage() {
aiChatLogic.getChatHistory().remove(index);
}
}

@FXML
private void sendExampleQuestion1Prompt() {
String questionText = exQuestion1.getText();
onSendMessage(questionText);
}
Comment on lines +290 to +293
Copy link

Choose a reason for hiding this comment

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

Code duplication across three similar methods (sendExampleQuestion1/2/3Prompt). Should be refactored into a single method taking the question number as parameter to improve maintainability.


@FXML
private void sendExampleQuestion2Prompt() {
String questionText = exQuestion2.getText();
onSendMessage(questionText);
}

@FXML
private void sendExampleQuestion3Prompt() {
String questionText = exQuestion3.getText();
onSendMessage(questionText);
}
}