Skip to content

Commit

Permalink
Chat with groups + AI chat UI and logic overhaul (#11666)
Browse files Browse the repository at this point in the history
* AI chat UI overhaul

* Chat history and AI chat overhaul

* Implement ingestion logic

* Implement ingestion logic

* Accept list of entries

* Group chat history logic

* Move components to folders and introduce AiPrivacyNoticeGuardedComponent

* Move components to folders and introduce AiPrivacyNoticeGuardedComponent

* Introduce EmbeddingModelGuardedComponent

* SummaryComponent overhaul

* Summarization logic overhaul

* Finish work on refactoring the summarization

* Introduce group chats

* Introduce group chat

* Refactor AI code

* AI chat UI overhaul

* Chat history and AI chat overhaul

* Implement ingestion logic

* Implement ingestion logic

* Accept list of entries

* Group chat history logic

* Move components to folders and introduce AiPrivacyNoticeGuardedComponent

* Move components to folders and introduce AiPrivacyNoticeGuardedComponent

* Introduce EmbeddingModelGuardedComponent

* SummaryComponent overhaul

* Summarization logic overhaul

* Finish work on refactoring the summarization

* Introduce group chats

* Introduce group chat

* Refactor AI code

* Fix GenerateEmbeddingsTask

* Introduce windows

* Refactor notifications

* No linting errors occurring

* Improve chat history component

* Discard changes to src/main/java/module-info.java

* Refine JavaDoc

* Fix for InAnYan#173

* Fix for InAnYan#171

* Fix from code review

* Fix checkers

* Fix for InAnYan#175 and InAnYan#174

* Follow-up for InAnYan#175

* Fix for InAnYan#166

* Fix for InAnYan#164

* Fix checkers

* Fix from code review

* Update src/main/java/org/jabref/gui/ai/components/aichat/AiChatGuardedComponent.java

Co-authored-by: Oliver Kopp <[email protected]>

* Fix for InAnYan#166 and fix for InAnYan#176

* Might be fix for InAnYan#178

* Migrate from AbstractGroup to GroupTreeNode

* Fix for InAnYan#170

* Fix for InAnYan#164

* InAnYan#177

* Fix for InAnYan#180

* Fix checkers

* Fix the system message

* Fix for InAnYan#180

* Fix context menu order

* Fix `startsWith`

* Fix system message

* Fix for ProgressCounter

* Fix for system message

---------

Co-authored-by: Oliver Kopp <[email protected]>
  • Loading branch information
InAnYan and koppor authored Sep 4, 2024
1 parent 419d2a7 commit 7f7726e
Show file tree
Hide file tree
Showing 93 changed files with 3,431 additions and 1,677 deletions.
21 changes: 21 additions & 0 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
Expand Up @@ -1496,3 +1496,24 @@ We want to have a look that matches our icons in the tool-bar */
-fx-padding: 0.5em 2em;
-fx-min-width: 10em;
}

.chat-message-text-area {
-fx-border-radius: 10;
-fx-background-radius: 10;
}

/* region: fix for making text area round corners (source: https://stackoverflow.com/a/49617953) */

.chat-message-text-area .scroll-pane {
-fx-background-color: transparent;
}

.chat-message-text-area .scroll-pane .viewport {
-fx-background-color: transparent;
}

.chat-message-text-area .scroll-pane .content {
-fx-background-color: transparent;
}

/* endregion */
8 changes: 8 additions & 0 deletions src/main/java/org/jabref/gui/DialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javafx.util.StringConverter;

import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.BaseWindow;
import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.logic.importer.FetcherException;
Expand Down Expand Up @@ -185,6 +186,13 @@ boolean showConfirmationDialogWithOptOutAndWait(String title, String content,
*/
void showCustomDialog(BaseDialog<?> dialog);

/**
* Shows a custom window.
*
* @param window window to show
*/
void showCustomWindow(BaseWindow window);

/**
* This will create and display a new dialog of the specified
* {@link Alert.AlertType} but with user defined buttons as optional
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/jabref/gui/JabRefDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.BaseWindow;
import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.gui.util.UiTaskExecutor;
Expand Down Expand Up @@ -510,4 +511,13 @@ public void showCustomDialog(BaseDialog<?> aboutDialogView) {
}
aboutDialogView.show();
}

@Override
public void showCustomWindow(BaseWindow window) {
if (window.getOwner() == null) {
window.initOwner(mainWindow);
}
window.applyStylesheets(mainWindow.getScene().getStylesheets());
window.show();
}
}
8 changes: 7 additions & 1 deletion src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,13 @@ public void initialize() {
JabRefGUI.clipBoardManager = new ClipBoardManager();
Injector.setModelOrService(ClipBoardManager.class, clipBoardManager);

JabRefGUI.aiService = new AiService(preferencesService.getAiPreferences(), Injector.instantiateModelOrService(AiApiKeyProvider.class), dialogService, taskExecutor);
JabRefGUI.aiService = new AiService(
preferencesService.getAiPreferences(),
preferencesService.getFilePreferences(),
preferencesService.getCitationKeyPatternPreferences(),
Injector.instantiateModelOrService(AiApiKeyProvider.class),
dialogService,
taskExecutor);
Injector.setModelOrService(AiService.class, aiService);
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/jabref/gui/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javafx.scene.Node;
import javafx.util.Pair;

import org.jabref.gui.ai.components.aichat.AiChatWindow;
import org.jabref.gui.edit.automaticfiededitor.LastAutomaticFieldEditorEdit;
import org.jabref.gui.search.SearchType;
import org.jabref.gui.sidepane.SidePaneType;
Expand Down Expand Up @@ -45,6 +46,7 @@
* <li>active number of search results</li>
* <li>focus owner</li>
* <li>dialog window sizes/positions</li>
* <li>opened AI chat window (controlled by {@link org.jabref.logic.ai.AiService})</li>
* </ul>
*/
public class StateManager {
Expand All @@ -69,6 +71,7 @@ public class StateManager {
private final ObservableList<SidePaneType> visibleSidePanes = FXCollections.observableArrayList();
private final ObjectProperty<LastAutomaticFieldEditorEdit> lastAutomaticFieldEditorEdit = new SimpleObjectProperty<>();
private final ObservableList<String> searchHistory = FXCollections.observableArrayList();
private final List<AiChatWindow> aiChatWindows = new ArrayList<>();

public ObservableList<SidePaneType> getVisibleSidePaneComponents() {
return visibleSidePanes;
Expand Down Expand Up @@ -207,4 +210,8 @@ public List<String> getLastSearchHistory(int size) {
public void clearSearchHistory() {
searchHistory.clear();
}

public List<AiChatWindow> getAiChatWindows() {
return aiChatWindows;
}
}
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/actions/StandardActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public enum StandardActions implements Action {
GROUP_REMOVE(Localization.lang("Remove group")),
GROUP_REMOVE_KEEP_SUBGROUPS(Localization.lang("Keep subgroups")),
GROUP_REMOVE_WITH_SUBGROUPS(Localization.lang("Also remove subgroups")),
GROUP_CHAT(Localization.lang("Chat with group")),
GROUP_EDIT(Localization.lang("Edit group")),
GROUP_SUBGROUP_ADD(Localization.lang("Add subgroup")),
GROUP_SUBGROUP_REMOVE(Localization.lang("Remove subgroups")),
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/ai/ClearEmbeddingsAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void execute() {

dialogService.notify(Localization.lang("Clearing embeddings cache..."));

List<LinkedFile> linkedFile = stateManager
List<LinkedFile> linkedFiles = stateManager
.getActiveDatabase()
.get()
.getDatabase()
Expand All @@ -55,7 +55,7 @@ public void execute() {
.flatMap(entry -> entry.getFiles().stream())
.toList();

BackgroundTask.wrap(() -> aiService.getEmbeddingsManager().clearEmbeddingsFor(linkedFile))
BackgroundTask.wrap(() -> aiService.getIngestionService().clearEmbeddingsFor(linkedFiles))
.executeWith(taskExecutor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,63 @@
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<?import org.jabref.gui.icon.JabRefIconView?>

<?import com.dlsc.gemsfx.ExpandingTextArea?>
<fx:root spacing="10.0" type="javafx.scene.layout.VBox" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.ai.components.aichat.AiChatComponent">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<children>
<StackPane fx:id="stackPane" VBox.vgrow="ALWAYS">
<children>
<ScrollPane fx:id="scrollPane" fitToWidth="true" style="-fx-border-color: black;">
<content>
<VBox fx:id="chatVBox" spacing="10.0">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</VBox>
</content>
</ScrollPane>
</children>
</StackPane>
<HBox fx:id="promptHBox" alignment="CENTER" spacing="10.0">
<children>
<ExpandingTextArea fx:id="userPromptTextArea" HBox.hgrow="ALWAYS" />
<Button fx:id="submitButton" mnemonicParsing="false" onAction="#onSendMessage" text="%Submit" />
</children>
</HBox>
<HBox alignment="CENTER" spacing="50">
<Label fx:id="noticeText" text="%Current AI model: %0. The AI may generate inaccurate or inappropriate responses. Please verify any information provided." BorderPane.alignment="CENTER" />
<?import org.jabref.gui.ai.components.util.Loadable?>
<?import org.jabref.gui.ai.components.aichat.chathistory.ChatHistoryComponent?>
<?import org.jabref.gui.ai.components.aichat.chatprompt.ChatPromptComponent?>

<Button alignment="CENTER" onAction="#onClearChatHistory" styleClass="icon-button,narrow" textAlignment="CENTER">
<graphic>
<JabRefIconView glyph="DELETE_ENTRY"/>
</graphic>
<tooltip>
<Tooltip text="%Clear chat history" />
</tooltip>
</Button>
</HBox>
<fx:root
type="javafx.scene.layout.VBox"
spacing="10"
xmlns="http://javafx.com/javafx/17.0.2-ea"
xmlns:fx="http://javafx.com/fxml/1"
fillWidth="true"
fx:controller="org.jabref.gui.ai.components.aichat.AiChatComponent">
<padding>
<Insets bottom="10.0"
left="10.0"
right="10.0"
top="10.0"/>
</padding>
<children>
<Loadable fx:id="uiLoadableChatHistory" VBox.vgrow="ALWAYS">
<ChatHistoryComponent fx:id="uiChatHistory" VBox.vgrow="ALWAYS" fitToWidth="true" />
</Loadable>

</children>
<HBox spacing="10">
<Button alignment="CENTER"
fx:id="notificationsButton"
styleClass="icon-button,narrow"
textAlignment="CENTER">
<tooltip>
<Tooltip
text="%Notifications"/>
</tooltip>
</Button>
<ChatPromptComponent fx:id="chatPrompt" HBox.hgrow="ALWAYS" />
</HBox>

<HBox alignment="CENTER"
spacing="50">
<Label fx:id="noticeText"
text="%Current AI model: %0. The AI may generate inaccurate or inappropriate responses. Please verify any information provided."
BorderPane.alignment="CENTER"/>

<Button alignment="CENTER"
onAction="#onClearChatHistory"
styleClass="icon-button,narrow"
textAlignment="CENTER">
<graphic>
<JabRefIconView
glyph="DELETE_ENTRY"/>
</graphic>
<tooltip>
<Tooltip
text="%Clear chat history"/>
</tooltip>
</Button>
</HBox>
</children>
</fx:root>
Loading

0 comments on commit 7f7726e

Please sign in to comment.