Skip to content

Added example questions to AI chat#12747

Merged
Siedlerchr merged 28 commits into
JabRef:mainfrom
kaushikaW:fix-for-issue-12745
Apr 18, 2025
Merged

Added example questions to AI chat#12747
Siedlerchr merged 28 commits into
JabRef:mainfrom
kaushikaW:fix-for-issue-12745

Conversation

@kaushikaW

@kaushikaW kaushikaW commented Mar 16, 2025

Copy link
Copy Markdown
Contributor

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
Comment thread src/main/java/org/jabref/gui/ai/components/aichat/AiChatComponent.java Outdated
@subhramit

Copy link
Copy Markdown
Member

Please keep in mind the contributing guidelines.

@subhramit

Copy link
Copy Markdown
Member

@palukku Thank you for helping with reviews.

@palukku

palukku commented Mar 16, 2025

Copy link
Copy Markdown
Member

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

Comment thread src/main/java/org/jabref/gui/ai/components/aichat/AiChatComponent.fxml Outdated
Comment thread src/main/java/org/jabref/gui/Base.css Outdated
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
Comment thread src/main/java/org/jabref/gui/ai/components/aichat/AiChatComponent.java Outdated
<ChatHistoryComponent fx:id="uiChatHistory" VBox.vgrow="ALWAYS" fitToWidth="true"/>
</Loadable>

<HBox spacing="10" alignment="CENTER">

Copy link
Copy Markdown
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

@FXML private Button notificationsButton;
@FXML private ChatPromptComponent chatPrompt;
@FXML private Label noticeText;
@FXML private Hyperlink exQuestion1;

Copy link
Copy Markdown
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
Copy Markdown
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

subhramit commented Mar 16, 2025

Copy link
Copy Markdown
Member

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

@palukku palukku left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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.

@InAnYan InAnYan left a comment

Copy link
Copy Markdown
Member

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


<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
Copy Markdown
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
Copy Markdown
Member

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
Copy Markdown
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
}

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

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

koppor commented Mar 28, 2025

Copy link
Copy Markdown
Member

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

addExampleQuestionAction(exQuestion3);
}

private void addExampleQuestionAction(Hyperlink hyperlink) {

Copy link
Copy Markdown

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.

@trag-bot

trag-bot Bot commented Apr 18, 2025

Copy link
Copy Markdown

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

@kaushikaW

Copy link
Copy Markdown
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
-fx-underline: false !important;
-fx-text-fill: -fx-text-base-color;
}
.exampleQuestionStyle:hover {

Copy link
Copy Markdown
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
Copy Markdown
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


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


Copy link
Copy Markdown
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