-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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.