Skip to content

Conversation

@CXZHANG0508
Copy link

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

  1. 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)

  2. Go to the AI Summary or AI Chat tab.

image 3. Even without an API key (interface might show an error), you should see the new **Export** button (floppy disk icon) in the toolbar. In the AI Summary tab, the Export button is only visible after a summary has been successfully generated. 屏幕截图 2025-12-01 104756 屏幕截图 2025-11-30 194147
  1. Click the button and select Export to Markdown or Export to JSON.
屏幕截图 2025-12-01 104854 5. Save the file and verify the content: - **Markdown:** Should contain the BibTeX source and the text. - **JSON:** Should contain metadata and a `conversation` list compatible with OpenAI format. - I confirmed that clicking the Export button correctly triggers the 'Save As' file dialog and generates the file with the expected structure.

Mandatory checks

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 CXZHANG0508 closed this Dec 1, 2025
@CXZHANG0508 CXZHANG0508 reopened this Dec 1, 2025
@koppor
Copy link
Member

koppor commented Dec 1, 2025

@CXZHANG0508 Please do not close PRs and open new ones. Just push changes to your branch.

@CXZHANG0508
Copy link
Author

Understood, thanks!

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 1, 2025
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 2, 2025
@calixtus
Copy link
Member

calixtus commented Dec 2, 2025

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.

@koppor koppor added status: changes-required Pull requests that are not yet complete status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed status: changes-required Pull requests that are not yet complete labels Dec 2, 2025
@koppor koppor requested a review from InAnYan December 2, 2025 13:59
@CXZHANG0508 CXZHANG0508 changed the title Feat ai export feat(ai): Add Markdown and JSON export buttons to AI Summary and Chat tabs Dec 2, 2025
@CXZHANG0508
Copy link
Author

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;
}
Copy link
Member

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

Copy link
Author

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
InAnYan previously approved these changes Dec 3, 2025
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.

Cool!

}

public String buildMarkdownForChat(List<ChatMessage> messages) {
StringBuilder conversation = new StringBuilder();
Copy link
Member

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

Copy link
Member

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();
Copy link
Member

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;
Copy link
Member

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

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 9, 2025
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 9, 2025
Comment on lines 35 to 38
StringJoiner sj = new StringJoiner("\n\n");
sj.add("## Bibtex");

StringJoiner bibtexBlock = new StringJoiner("\n");
Copy link
Member

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.

Copy link
Author

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.

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 11, 2025
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 12, 2025
Copy link
Member

@koppor koppor left a 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)
grafik

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 12, 2025
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 12, 2025
@CXZHANG0508
Copy link
Author

Apologies for the oversight, it was a careless mistake on my part.Now I had fixed it.

Copy link
Member

@koppor koppor left a 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.

image

There must not be an empty line at the end of the code block

image

Exported markdown should pass David's markdown-lint

image image

JSON Format is for single file only... I think, it should contain all entries?

image

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.

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 12, 2025
@koppor
Copy link
Member

koppor commented Dec 12, 2025

Moreover, consistency please!!

image image

Export always right - as in AI summary

@calixtus calixtus changed the title feat(ai): Add Markdown and JSON export buttons to AI Summary and Chat tabs Add Markdown and JSON export buttons to AI Summary and Chat tabs Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add export chat and summary feature to AI functionality

4 participants