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

Conversation

kaushikaW
Copy link

@kaushikaW kaushikaW commented Mar 16, 2025

Fixes #12702
Added 3 example questions to the AI chat tab section (see the screenshot).
Currently, the 3 questions are hardcoded in the codebase and are not being generated by the AI model.
Some extra styles have been added to improve the user experience.

image
image

Mandatory checks

  • I own the copyright of the code submitted and I licence it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

@kaushikaW kaushikaW marked this pull request as ready for review March 16, 2025 11:01
@subhramit
Copy link
Member

Please keep in mind the contributing guidelines.

@subhramit
Copy link
Member

@palukku Thank you for helping with reviews.

@palukku
Copy link
Contributor

palukku commented Mar 16, 2025

JabRef supports both light and dark modes, so please ensure that the colors are appropriate for both. The current text color might be too light, reducing readability, and the hover state is also not very legible.

image
image

kaushikaW and others added 5 commits March 16, 2025 22:19
# 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
</Loadable>

<HBox spacing="10" alignment="CENTER">
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 external css styles and remove inline css styles

@@ -62,6 +63,9 @@ 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

@kaushikaW
Copy link
Author

@palukku @subhramit Do I need to add UI changes I done in this issue to the CHANGELOG.md file

@koppor koppor mentioned this pull request Mar 16, 2025
7 tasks
@subhramit
Copy link
Member

subhramit commented Mar 16, 2025

@palukku @subhramit Do I need to add UI changes I done in this issue to the CHANGELOG.md file

No, just the summary should be fine. Add it to the changelog.

Copy link
Contributor

@palukku palukku left a comment

Choose a reason for hiding this comment

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

Your code looks fine now and works as intended.
However, one thing is missing in my opinion: the example questions are always displayed. It would be nice to check the history; if a question has already been sent, remove its "button" from the box. Once all example questions have been asked, remove the entire example box.

You can use chatPrompt#getHistory to check that and remove the hyperlinks by obtaining the parent HBox and removing them from its children.

@kaushikaW
Copy link
Author

Your code looks fine now and works as intended. However, one thing is missing in my opinion: the example questions are always displayed. It would be nice to check the history; if a question has already been sent, remove its "button" from the box. Once all example questions have been asked, remove the entire example box.

You can use chatPrompt#getHistory to check that and remove the hyperlinks by obtaining the parent HBox and removing them from its children.

Well I also though of your opinion , but removing each example question as it's used creates a small issue—once all questions are gone, the user is cant see any example questions . is it ok

@kaushikaW kaushikaW requested a review from palukku March 17, 2025 18:17
Copy link
Contributor

@palukku palukku left a comment

Choose a reason for hiding this comment

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

I made some adjustments to the style to better blend with JabRef's existing design. Additionally, I included the removal of buttons after use. Since the chat isn't persistent and varies across entries, we can safely remove each button individually after the corresponding question is asked. When JabRef is reopened, the chat will be empty again, and the suggested questions will reappear.

Comment on lines 22 to 26
<HBox spacing="10" alignment="CENTER">
<Label
fx:id="exQuestionLabel"
text="Try with examples"
BorderPane.alignment="CENTER"
styleClass="exampleQuestionLabelStyle"
/>
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
<HBox spacing="10" alignment="CENTER">
<Label
fx:id="exQuestionLabel"
text="Try with examples"
BorderPane.alignment="CENTER"
styleClass="exampleQuestionLabelStyle"
/>
<HBox fx:id="exQuestionBox" spacing="10" alignment="CENTER">
<Label
text="Try with examples"
BorderPane.alignment="CENTER"
/>

@@ -62,6 +63,9 @@ public class AiChatComponent extends VBox {
@FXML private Button notificationsButton;
@FXML private ChatPromptComponent chatPrompt;
@FXML private Label noticeText;
@FXML private Hyperlink exQuestion1;
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;

Comment on lines 119 to 143
private void sendExampleQuestions() {
exQuestion1.setOnAction(event -> {
onSendMessage(exQuestion1.getText());
});

exQuestion2.setOnAction(event -> {
onSendMessage(exQuestion2.getText());
});

exQuestion3.setOnAction(event -> {
onSendMessage(exQuestion3.getText());
});
}

Copy link
Contributor

@palukku palukku Mar 17, 2025

Choose a reason for hiding this comment

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

Suggested change
private void sendExampleQuestions() {
exQuestion1.setOnAction(event -> {
onSendMessage(exQuestion1.getText());
});
exQuestion2.setOnAction(event -> {
onSendMessage(exQuestion2.getText());
});
exQuestion3.setOnAction(event -> {
onSendMessage(exQuestion3.getText());
});
}
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);
}
return;
}
hyperlink.setOnAction(event -> {
onSendMessage(hyperlink.getText());
exQuestionBox.getChildren().remove(hyperlink);
if (exQuestionBox.getChildren().size() == 1) {
this.getChildren().remove(exQuestionBox);
}
});
}

@@ -10,6 +10,7 @@
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.

@kaushikaW kaushikaW force-pushed the fix-for-issue-12745 branch from 0d519e5 to f1c8a10 Compare March 18, 2025 11:32
@subhramit
Copy link
Member

@kaushikaW please take the latest pull from upstream, resolve merge conflicts and push a single commit for the merge to the updated state. Do not force-push.

@kaushikaW
Copy link
Author

@kaushikaW please take the latest pull from upstream, resolve merge conflicts and push a single commit for the merge to the updated state. Do not force-push.

ok sure sorry for mistake

@kaushikaW kaushikaW requested a review from palukku March 18, 2025 12:00
@kaushikaW
Copy link
Author

Hi @palukku I go through your changes and added them to the code thanks for suggestions !

@koppor
Copy link
Member

koppor commented Mar 18, 2025

Hi @palukku I go through your changes and added them to the code thanks for suggestions !

No need to state this. This increases load of maintainers. ALL maintainers get a notification of your message. They need to switch context etc.

It is clear that you will work on that.

The only reason I see for commenting is that you say: I don't have time now, but will commit something one week :)

image

@ThiloteE
Copy link
Member

ThiloteE commented Mar 18, 2025

Your code looks fine now and works as intended. However, one thing is missing in my opinion: the example questions are always displayed. It would be nice to check the history; if a question has already been sent, remove its "button" from the box. Once all example questions have been asked, remove the entire example box.

You can use chatPrompt#getHistory to check that and remove the hyperlinks by obtaining the parent HBox and removing them from its children.

I apologize for responding so late. Will it still be possible to regenerate one of those questions? LLMs are not precise and tend to confabulate, so regeneration is one of the main use cases as it helps for brainstorming.

I have not tried the PR yet, as I don't have much time and will not have much time in the coming weeks.

@kaushikaW
Copy link
Author

kaushikaW commented Mar 18, 2025

Your code looks fine now and works as intended. However, one thing is missing in my opinion: the example questions are always displayed. It would be nice to check the history; if a question has already been sent, remove its "button" from the box. Once all example questions have been asked, remove the entire example box.
You can use chatPrompt#getHistory to check that and remove the hyperlinks by obtaining the parent HBox and removing them from its children.

I apologize for responding so late. Will it still be possible to regenerate one of those questions? LLMs are not precise and tend to confabulate, so regeneration is one of the main use cases as it helps for brainstorming.

I have not tried the PR yet, as I don't have much time and will not have much time in the coming weeks.

once user clicked on the example question it goes to the chat prompt and despaired from the example question bar (see the ss1). so like wise if user clicked on the all three example questions all the question goes to the chat prompt and disappeared from example question bar(see ss2) . so user have to run the application again to see the example questions.
ss1
image
ss2
image

Thoughts

  • with your thoughts we can use small button to regenerate all three questions (after all three questions are disappeared ) without re run the application to improve UX. (see below ss)
    image

- I am suggesting an idea: Would it be a good approach to randomly pick three questions from a string array containing example questions and displayed to the user .

@palukku
Copy link
Contributor

palukku commented Mar 18, 2025

I apologize for responding so late. Will it still be possible to regenerate one of those questions? LLMs are not precise and tend to confabulate, so regeneration is one of the main use cases as it helps for brainstorming.

I have not tried the PR yet, as I don't have much time and will not have much time in the coming weeks.

Directly regenerating the example buttons is not possible, but if you're not happy with the answer you are free to ask the same question manually again or try to ask for a better answer and why the first response is not the one you expected. I don't see it as an issue for this pr since it's only a suggestion of things you can ask.

But an "regenerate response" Button next to the answer of the ai would be an idea, maybe we can open up a new issue for this.

@palukku
Copy link
Contributor

palukku commented Mar 18, 2025

- I am suggesting an idea: Would it be a good approach to randomly pick three questions from a string array containing example questions and displayed to the user .

As said here #12702 (comment) this would be a great feature to use ai to create (following) questions that are context aware.

Copy link
Contributor

@palukku palukku left a comment

Choose a reason for hiding this comment

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

Tried it out, works fine with both dark and light style.

Comment on lines 2449 to 2452




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

@@ -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

Comment on lines +130 to +132
if (exQuestionBox.getChildren().size() == 1) {
this.getChildren().remove(exQuestionBox);
}
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.

@palukku
Copy link
Contributor

palukku commented Mar 20, 2025

Oh and please add the changes in short and user friendly words to the CHANGELOG.md!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add example questions to AI chat
5 participants