-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add options to auto generate embeddings and summaries #11833
Conversation
@@ -28,7 +35,8 @@ | |||
* Use this class in the logic and UI. | |||
*/ | |||
public class IngestionService { | |||
private final Map<LinkedFile, ProcessingInfo<LinkedFile, Void>> ingestionStatusMap = new HashMap<>(); | |||
// We use a {@link TreeMap} here for the same reasons we use it in {@link ChatHistoryService}. | |||
private final TreeMap<LinkedFile, ProcessingInfo<LinkedFile, Void>> ingestionStatusMap = new TreeMap<>((o1, o2) -> o1 == o2 ? 0 : o1.getLink().compareTo(o2.getLink())); |
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.
You can use the more easier way with Compartor.comparing( ... )
https://www.baeldung.com/java-8-comparator-comparing
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 Please adress, too.
private void configureDatabaseListeners(StateManager stateManager) { | ||
stateManager.getOpenDatabases().addListener((ListChangeListener<BibDatabaseContext>) change -> { | ||
while (change.next()) { | ||
if (change.wasAdded()) { | ||
change.getAddedSubList().forEach(this::configureDatabaseListeners); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private void configureDatabaseListeners(BibDatabaseContext bibDatabaseContext) { | ||
// GC was eating the listeners, so we have to fall back to the event bus. | ||
bibDatabaseContext.getDatabase().registerListener(new EntriesChangedListener(bibDatabaseContext)); | ||
} | ||
|
||
private class EntriesChangedListener { | ||
private final BibDatabaseContext bibDatabaseContext; | ||
|
||
public EntriesChangedListener(BibDatabaseContext bibDatabaseContext) { | ||
this.bibDatabaseContext = bibDatabaseContext; | ||
} | ||
|
||
@Subscribe | ||
public void listen(EntriesAddedEvent e) { | ||
e.getBibEntries().forEach(entry -> { | ||
if (aiPreferences.getAutoGenerateSummaries()) { | ||
summarize(entry, bibDatabaseContext); | ||
} | ||
}); | ||
} | ||
|
||
@Subscribe | ||
public void listen(FieldChangedEvent e) { | ||
if (e.getField() == StandardField.FILE && aiPreferences.getAutoGenerateSummaries()) { | ||
summarize(e.getBibEntry(), bibDatabaseContext); | ||
} | ||
} | ||
} |
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.
Move this code to UI.
The logic should not depend on the UI (see architecture tests).
Reason: AI should also be usable via CLI.
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.
StateManager
belongs to UI?
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.
Yes. See the package
of the StateManger.
package org.jabref.gui; |
You can also see it, because it holds the list of opened BibTeX files
# Conflicts: # src/main/java/org/jabref/gui/preferences/ai/AiTab.fxml
Updated |
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.
Two small comments, then it should be good to go!
@@ -58,12 +56,13 @@ public class ChatHistoryService implements AutoCloseable { | |||
|
|||
private static final String CHAT_HISTORY_FILE_NAME = "chat-histories.mv"; | |||
|
|||
private final StateManager stateManager = Injector.instantiateModelOrService(StateManager.class); |
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, you can move the class to logic
. No gui dependency as far as I can see.
Also the JavaDoc can be updated --> no more use of StateManager.
@@ -28,7 +35,8 @@ | |||
* Use this class in the logic and UI. | |||
*/ | |||
public class IngestionService { | |||
private final Map<LinkedFile, ProcessingInfo<LinkedFile, Void>> ingestionStatusMap = new HashMap<>(); | |||
// We use a {@link TreeMap} here for the same reasons we use it in {@link ChatHistoryService}. | |||
private final TreeMap<LinkedFile, ProcessingInfo<LinkedFile, Void>> ingestionStatusMap = new TreeMap<>((o1, o2) -> o1 == o2 ? 0 : o1.getLink().compareTo(o2.getLink())); |
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 Please adress, too.
Updated |
Partially closes the issue https://github.com/JabRef/jabref-issue-melting-pot/issues/546.
NOTE: Please, merge the #11835, before this, to reduce merge conflicts.
New options:
I think this space after "Enable AI" is because of the help button.
I'll address the help buttons in other PR.
Mandatory checks
~- [ ] Change in
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)- [ ] Tests created for changes (if applicable)