-
-
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
Generate embeddings and summaries of a group in context menu #11832
Changes from 3 commits
11c8587
29d7d75
0d439f1
245da92
1a17456
76e0053
7a8399a
7ec5b7a
afd3bb3
bcb0d34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
import org.jabref.logic.util.TaskExecutor; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.LinkedFile; | ||
import org.jabref.model.groups.AbstractGroup; | ||
import org.jabref.model.groups.AutomaticKeywordGroup; | ||
import org.jabref.model.groups.AutomaticPersonsGroup; | ||
|
@@ -54,6 +55,7 @@ public class GroupTreeViewModel extends AbstractViewModel { | |
private final ListProperty<GroupNodeViewModel> selectedGroups = new SimpleListProperty<>(FXCollections.observableArrayList()); | ||
private final StateManager stateManager; | ||
private final DialogService dialogService; | ||
private final AiService aiService; | ||
private final ChatHistoryService chatHistoryService; | ||
private final GuiPreferences preferences; | ||
private final TaskExecutor taskExecutor; | ||
|
@@ -78,9 +80,17 @@ public class GroupTreeViewModel extends AbstractViewModel { | |
}; | ||
private Optional<BibDatabaseContext> currentDatabase = Optional.empty(); | ||
|
||
public GroupTreeViewModel(StateManager stateManager, DialogService dialogService, ChatHistoryService chatHistoryService, GuiPreferences preferences, TaskExecutor taskExecutor, CustomLocalDragboard localDragboard) { | ||
public GroupTreeViewModel(StateManager stateManager, | ||
DialogService dialogService, | ||
AiService aiService, | ||
ChatHistoryService chatHistoryService, | ||
GuiPreferences preferences, | ||
TaskExecutor taskExecutor, | ||
CustomLocalDragboard localDragboard | ||
) { | ||
this.stateManager = Objects.requireNonNull(stateManager); | ||
this.dialogService = Objects.requireNonNull(dialogService); | ||
this.aiService = aiService; | ||
this.chatHistoryService = Objects.requireNonNull(chatHistoryService); | ||
this.preferences = Objects.requireNonNull(preferences); | ||
this.taskExecutor = Objects.requireNonNull(taskExecutor); | ||
|
@@ -386,7 +396,6 @@ public void editGroup(GroupNodeViewModel oldGroup) { | |
} | ||
|
||
public void chatWithGroup(GroupNodeViewModel group) { | ||
// This should probably be done some other way. Please don't blame, it's just a thing to make it quick and fast. | ||
if (currentDatabase.isEmpty()) { | ||
dialogService.showErrorDialogAndWait(Localization.lang("Unable to chat with group"), Localization.lang("No library is selected.")); | ||
return; | ||
|
@@ -430,6 +439,57 @@ private void openAiChat(StringProperty name, ObservableList<ChatMessage> chatHis | |
} | ||
} | ||
|
||
public void generateEmbeddings(GroupNodeViewModel groupNode) { | ||
if (currentDatabase.isEmpty()) { | ||
dialogService.notify(Localization.lang("Unable to generate embeddings. No library is selected.")); | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this branch ever it in th execution? Maybe, it can be replaced by a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #11832 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. porposal for now. Re-use |
||
|
||
AbstractGroup group = groupNode.getGroupNode().getGroup(); | ||
|
||
List<LinkedFile> linkedFiles = currentDatabase | ||
.get() | ||
.getDatabase() | ||
.getEntries() | ||
.stream() | ||
.filter(group::isMatch) | ||
.flatMap(entry -> entry.getFiles().stream()) | ||
.toList(); | ||
|
||
aiService.getIngestionService().ingest( | ||
group.nameProperty(), | ||
linkedFiles, | ||
currentDatabase.get() | ||
); | ||
|
||
dialogService.notify(Localization.lang("Ingestion started for group \"%0\".", group.getName())); | ||
} | ||
|
||
public void generateSummaries(GroupNodeViewModel groupNode) { | ||
if (currentDatabase.isEmpty()) { | ||
dialogService.notify(Localization.lang("Unable to generate summaries. No library is selected.")); | ||
return; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this branch ever it in th execution? Maybe, it can be replaced by a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #11832 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. porposal for now. Re-use |
||
AbstractGroup group = groupNode.getGroupNode().getGroup(); | ||
|
||
List<BibEntry> entries = currentDatabase | ||
.get() | ||
.getDatabase() | ||
.getEntries() | ||
.stream() | ||
.filter(group::isMatch) | ||
.toList(); | ||
|
||
aiService.getSummariesService().summarize( | ||
group.nameProperty(), | ||
entries, | ||
currentDatabase.get() | ||
); | ||
|
||
dialogService.notify(Localization.lang("Summarization started for group \"%0\".", group.getName())); | ||
} | ||
|
||
public void removeSubgroups(GroupNodeViewModel group) { | ||
boolean confirmation = dialogService.showConfirmationDialogAndWait( | ||
Localization.lang("Remove subgroups"), | ||
|
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.
Is this branch ever it in th execution? Maybe, it can be replaced by a
LOGGER.warn
statement?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.
Well, the code really can't proceed without a database.
I don't like that if there is no database, there is no reasonably visible response from the JabRef. Just a LOGGER.warn. Not sure what should I do
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.
What I mean, we could do
assert !currentDatabase.isEmpty()
. -- Thus: My bet is: This branch is never hit during real use in JabRef.This creates an additional translation string - therefore I was thinking and worrying.