Skip to content

Added example questions to AI chat #12747

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

Merged
merged 28 commits into from
Apr 18, 2025
Merged

Conversation

kaushikaW
Copy link
Contributor

@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 license 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 (if change is visible to the user)
  • 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
Contributor 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
Contributor 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
Contributor 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
Contributor 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
@ThiloteE
Copy link
Member

I now remember why we did not hard-code system prompts in the AI preferences: Because of internationalisation. Hard-coded prompts necessitate for JabRef maintainers to translate them to other languages, if the community calls for it, whereas user configurable prompts give users the possibility to use their language of choice.

Copy link
Member

@InAnYan InAnYan left a comment

Choose a reason for hiding this comment

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

Awesome!

Left some small review comments

</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"/>
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for introducing those questions.

Can you make them localized?

I think the proper way is to do this:

  1. Leave text empty in FXML.
  2. Then in some initialization method in Java class, call setText with Localization.lang("...").

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't you just use the same method as for the "Try with examples" Label by adding a % in front? Or aren't they detected by the localization tests?

</Loadable>

<HBox spacing="10" alignment="CENTER" fx:id="exQuestionBox">
<Label text="Try with examples" BorderPane.alignment="CENTER"/>
Copy link
Member

Choose a reason for hiding this comment

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

@subhramit subhramit added status: changes required Pull requests that are not yet complete and removed status: awaiting second review For non-trivial changes labels Mar 25, 2025
@@ -111,6 +119,35 @@ private void initializeNotice() {
noticeText.setText(newNotice);
}

private void initializeExampleQuestions() {
exQuestion1.setText(Localization.lang("What is the goal of the paper?"));
Copy link

Choose a reason for hiding this comment

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

The strings for example questions should be defined as constants to avoid magic strings and improve maintainability.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, private static final String ....

Copy link
Member

Choose a reason for hiding this comment

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

@koppor This is a false positive. For l10n this doesn't work

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking about

private static final String EXAMPLE_QUESTION_1 = Localization.lang("What is the goal of the paper?"));

on top of the class - to make it very easy to update the example question.

I also can follow the line of argumetnation that find-in-all-files also finds the string and then can be replaced.

Copy link
Member

Choose a reason for hiding this comment

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

Use the String you want to localize directly, do not use members or local variables: Localization.lang("Translate me"); instead of Localization.lang(someVariable) (possibly in the form someVariable = Localization.lang("Translate me")
https://devdocs.jabref.org/code-howtos/localization.html

Copy link
Member

Choose a reason for hiding this comment

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

maybe I confused it with that one

@kaushikaW kaushikaW requested a review from InAnYan March 27, 2025 07:23
@koppor
Copy link
Member

koppor commented Mar 28, 2025

@kaushikaW Please merge upstream/main, because CHANGELOG.md was modified meanwhile.

addExampleQuestionAction(exQuestion3);
}

private void addExampleQuestionAction(Hyperlink hyperlink) {
Copy link

Choose a reason for hiding this comment

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

The method addExampleQuestionAction contains nested logic that could be simplified by returning early when the hyperlink text is already in the chat history, following the fail-fast principle.

Copy link

trag-bot bot commented Apr 18, 2025

@trag-bot didn't find any issues in the code! ✅✨

@kaushikaW
Copy link
Contributor Author

@InAnYan why this PR filing do I have mentioned wrong issue no in the PR description.

@Siedlerchr Siedlerchr added this pull request to the merge queue Apr 18, 2025
Merged via the queue into JabRef:main with commit 0d5de68 Apr 18, 2025
35 of 36 checks passed
-fx-underline: false !important;
-fx-text-fill: -fx-text-base-color;
}
.exampleQuestionStyle:hover {
Copy link
Member

Choose a reason for hiding this comment

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

Emtpy line missing

Copy link
Member

Choose a reason for hiding this comment

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

Fixed these in #12966

@@ -57,11 +64,17 @@ public class AiChatComponent extends VBox {

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


Copy link
Member

Choose a reason for hiding this comment

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

Too many empty lines

subhramit added a commit that referenced this pull request Apr 18, 2025
@subhramit subhramit mentioned this pull request Apr 18, 2025
2 tasks
subhramit added a commit that referenced this pull request Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ai status: changes required Pull requests that are not yet complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add example questions to AI chat
7 participants