-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add Markdown and JSON export buttons to AI Summary and Chat tabs #14486
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
base: main
Are you sure you want to change the base?
Conversation
Why: Quite often, JabRef users would like to share a conversation with AI, or store it in some text file that would be read later without opening JabRef. However, currently we don't have an option of saving the conversation or summary to some external file. How: - Add `MenuButton` with export options to `SummaryShowingComponent.fxml` and `AiChatComponent.fxml`. - Implement `exportMarkdown` method to construct Markdown content including the BibTeX source code. - Implement `exportJson` method using Jackson to generate JSON output that adheres to the OpenAI conversation format. - Add necessary localization keys to `JabRef_en.properties`. - Update `CHANGELOG.md` to reflect the new feature. Tags: ai, export, json, markdown Fixes JabRef#13868
|
@CXZHANG0508 Please do not close PRs and open new ones. Just push changes to your branch. |
|
Understood, thanks! |
|
Hi, thanks for your contribution. Please use a proper PR title. "Feat ai export" is not enough to quickly understand from the table what this PR is about. Remember that in open source you occansionally happen to work with other people together and as long as we dont have the technology for mind sharing and telepathy, we need to keep communicating in a mutual understandable way. |
|
Thank you for your feedback! I apologize for the previous simple title. I have updated the PR title to be more descriptive.I hope that is clearer. |
| if (summary == null) { | ||
| dialogService.notify(Localization.lang("No summary available to export")); | ||
| return; | ||
| } |
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.
I would add a blank line after }, but that's not critical
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.
Thank you for the review and the approval! I really appreciate your feedback. I will definitely pay more attention to spacing and formatting details in my future contributions.
InAnYan
left a comment
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.
Cool!
| } | ||
|
|
||
| public String buildMarkdownForChat(List<ChatMessage> messages) { | ||
| StringBuilder conversation = new StringBuilder(); |
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.
Please use StringJoiner so that you don't need to put \n
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.
I think, this is still not addressed. It is an easy change. Please @CXZHANG0508 work on this. This PR should go in before we both lose context and need to work from the beginning.
| } | ||
|
|
||
| public String buildMarkdownExport(String contentTitle, String contentBody) { | ||
| StringBuilder sb = new StringBuilder(); |
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.
Not sure whether I already commented.
Please use StringJoiner so that you don't need to put \n
See https://apidia.net/java/OpenJDK/25/?pck=java.util&cls=.StringJoiner for JavaDoc
| role = "assistant"; | ||
| content = aiMessage.text(); | ||
| } else { | ||
| continue; |
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.
@InAnYan @ThiloteE We should include ErrorMessage, shouldn't we?
@CXZHANG0508 Please remove "ErrorMessage" - you have it written twice in the comment
| StringJoiner sj = new StringJoiner("\n\n"); | ||
| sj.add("## Bibtex"); | ||
|
|
||
| StringJoiner bibtexBlock = new StringJoiner("\n"); |
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.
No - not two nested string joiners.
Use
StringJoiner sj = new StringJoiner("\n");
If you need two empty lines, do
sj.add("");
Rename "sj" to "stringJoiner"; we use more readable variable names in JabRef.
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.
Thanks for the detailed review! I have addressed this point.
koppor
left a comment
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.
Does not work - some issues with resolving the actions
I am in the AI Summary tab and click on "Regenerate"
Caused by: javafx.fxml.LoadException: Error resolving onAction='#exportMarkdown', either the event handler is not in the Namespace or there is an error in the script.
file:///C:/git-repositories/jabref-all/jabref/jabgui/build/libs/jabgui-100.0.0.jar!/org/jabref/gui/ai/components/summary/SummaryShowingComponent.fxml:27
at [email protected]/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2688)
|
Apologies for the oversight, it was a careless mistake on my part.Now I had fixed it. |
koppor
left a comment
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.
Does not crash. Good.
Does not work for chat with group. Exports only first paper.
There must not be an empty line at the end of the code block
Exported markdown should pass David's markdown-lint
JSON Format is for single file only... I think, it should contain all entries?
Not sure about timestamp? Is this the export_timestamp?
I am not sure about whether we need to include entry_bibtex, but maybe its OK as is... The alternative would be to include doi (or other identifier(s)) in the entry map.


Closes #13868
Implemented the export functionality for AI Summary and AI Chat as requested. Users can now save the content to Markdown (human-readable) or JSON (machine-readable, OpenAI format). Added an export menu button to the UI and handled the file saving logic.
Steps to test
Open an entry that has a citation key and a linked PDF. I tested the UI logic in a simulated local environment (since I don't have an AI API key)
Go to the AI Summary or AI Chat tab.
Mandatory checks
CHANGELOG.mdin a way that is understandable for the average user (if change is visible to the user)