Skip to content
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

AI chatting functionality #11430

Open
wants to merge 190 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 142 commits
Commits
Show all changes
190 commits
Select commit Hold shift + click to select a range
d9d58f6
First AI steps
InAnYan May 8, 2024
7c358c9
Some changes to AI code
InAnYan May 8, 2024
0a05213
Add AI preferences
InAnYan May 8, 2024
812820a
First part of fix
koppor May 8, 2024
7f92e0d
Fix: second part
koppor May 8, 2024
cee2278
More fixes
koppor May 8, 2024
37d0534
Remove unneded Apache PDFBox
koppor May 8, 2024
d9b6c3e
Added AiChatTab to EntryEditor tabs
InAnYan May 8, 2024
c0b56f3
Merge remote-tracking branch 'origin/ai-1' into ai-1
InAnYan May 8, 2024
19d8aa3
Fix dependency
koppor May 8, 2024
2dcaa3a
Add require on kotlin.stdlib
koppor May 8, 2024
f389bad
Some changes
InAnYan May 8, 2024
971fdce
AI preferences tab
InAnYan May 10, 2024
ddacd47
AI is split to classes. Preferences tab. UI changes
InAnYan May 11, 2024
1da98b5
Changed according to code review
InAnYan May 15, 2024
9ffeaa4
Deleted check for OpenAI token format
InAnYan May 15, 2024
3bf8ac1
Tried to solve the bug with token
InAnYan May 15, 2024
14b7c72
Tried to solve the bug with token
InAnYan May 15, 2024
784434f
Split preferences: "Show AI chat tab" / "Chat with PDFs"
InAnYan May 17, 2024
7fac426
Fix typos
InAnYan May 17, 2024
8a12515
Improve UI
InAnYan May 17, 2024
221f961
Save chat history in memory. Split UI to classes
InAnYan May 18, 2024
185de4e
Manage chat history
InAnYan May 19, 2024
267efc9
Clean saving chat history
InAnYan May 25, 2024
62ea22e
Fix module-info.java
InAnYan May 25, 2024
4ddf173
Fix SaveDatabaseAction
InAnYan May 25, 2024
f9bd0d0
Fix chat UI
InAnYan May 25, 2024
43845ae
Make custom components for UI
InAnYan May 25, 2024
c9cf1a0
Improve AI service
InAnYan May 27, 2024
70ddca5
Pollute AI service everywhere
InAnYan May 27, 2024
6cec13a
Fix bugs
InAnYan May 27, 2024
008c8c7
Pollute AI service everywhere
InAnYan May 27, 2024
bda1efb
Merge remote-tracking branch 'origin/add-ai-service' into add-ai-service
InAnYan May 27, 2024
066747c
Fix logger messages (changes provided by @koppor)
InAnYan May 27, 2024
3943505
Fix chat message alignment
InAnYan May 27, 2024
3a39552
Remove comment
InAnYan May 27, 2024
51cdcde
Use CustomPasswordField
InAnYan May 27, 2024
2675b56
Improve the UI for AI chat tab states
InAnYan May 27, 2024
afb01cd
Autogenerate citation key
InAnYan May 27, 2024
74014c8
Revert "Autogenerate citation key"
InAnYan May 27, 2024
d8c19c3
Autogenerate citation key
InAnYan May 27, 2024
20bb6ac
Fix Jackson adding a `typeLabel` field
InAnYan May 27, 2024
c79e5d2
Improve `AiService` and `AiChat` classes
InAnYan May 27, 2024
5cffaa1
Fix code bug
InAnYan May 27, 2024
97349de
Fix code bug
InAnYan May 27, 2024
49d6e00
Merge pull request #31 from InAnYan/fix-for-issue-16
InAnYan May 28, 2024
add2e05
Merge pull request #28 from InAnYan/fix-for-issue-18
InAnYan May 28, 2024
284a050
Merge pull request #22 from InAnYan/fix-for-issue-12
InAnYan May 28, 2024
ad08227
Merge pull request #24 from InAnYan/fix-for-issue-20
InAnYan May 28, 2024
8b4d3c6
Merge pull request #30 from InAnYan/fix-for-issue-13
InAnYan May 28, 2024
c8048ca
Merge branch 'refs/heads/ai-1' into fix-for-issue-19
InAnYan May 29, 2024
df60c5f
Fix code after merge
InAnYan May 29, 2024
baad7b3
Merge pull request #26 from InAnYan/fix-for-issue-19
InAnYan May 29, 2024
5755334
Merge pull request #9 from InAnYan/add-ai-service
InAnYan May 29, 2024
391e921
Add draft ADRs
InAnYan May 29, 2024
1ea6029
Fix bugs
InAnYan May 29, 2024
80f591a
Add warning to AiChatComponent
InAnYan May 29, 2024
883dbe7
Add requestFocus on user prompt text field
InAnYan May 29, 2024
84220b3
Attempt to fix the issue
InAnYan May 29, 2024
2a18e01
First attempt
InAnYan Jun 3, 2024
bca31f6
Request focus on user prompt field after AI has generated answer
InAnYan Jun 3, 2024
94bf0e3
Change branches of `scanLabeledControls`
InAnYan Jun 3, 2024
7545c27
Fix bugs
InAnYan Jun 3, 2024
dec354e
Merge pull request #38 from InAnYan/fix-for-33
InAnYan Jun 4, 2024
9aacf9b
Merge pull request #37 from InAnYan/fix-for-34
InAnYan Jun 4, 2024
6ee1f0e
Add translation string
InAnYan Jun 4, 2024
b2ab59e
Clean code
InAnYan Jun 4, 2024
51d682b
Merge pull request #39 from InAnYan/fix-for-29
InAnYan Jun 4, 2024
cc3939f
Merge branch 'refs/heads/ai-1' into fix-for-32
InAnYan Jun 4, 2024
99e0f8d
Add missing localization keys
InAnYan Jun 4, 2024
6b6713a
Merge remote-tracking branch 'origin/ai-1' into ai-1
InAnYan Jun 4, 2024
a0bec89
Update ADR files
InAnYan Jun 4, 2024
0fa2450
Update ADR files
InAnYan Jun 4, 2024
afe98d3
Merge pull request #35 from InAnYan/fix-for-32
InAnYan Jun 4, 2024
359b7b9
Attempt to upgrade langchain4j version to 0.31.0
InAnYan Jun 4, 2024
0aa3880
Add missing dependency
koppor Jun 4, 2024
cf6be7e
Make and use MVStore
InAnYan Jun 6, 2024
2505656
Change directory creation logic
InAnYan Jun 6, 2024
3c4de4b
Track adding and removing from index
InAnYan Jun 6, 2024
7a803ef
Merge branch 'refs/heads/main' into ai-1
InAnYan Jun 7, 2024
eb53cb7
Merge branch 'refs/heads/ai-1' into fix-for-14
InAnYan Jun 7, 2024
0ab6e68
Change PdfIndexer
InAnYan Jun 9, 2024
edc22f6
Listen to ingested files changes
InAnYan Jun 9, 2024
f057a58
Refactor AiChatTab methods
InAnYan Jun 9, 2024
8ae7130
Implement removing of embeddings
InAnYan Jun 9, 2024
eccb2a8
Remove store path logging
InAnYan Jun 9, 2024
2010745
Fix bugs
InAnYan Jun 11, 2024
a8f164d
Improve ErrorStateComponent
InAnYan Jun 11, 2024
2c2617a
Merge branch 'refs/heads/ai-1' into fix-for-14
InAnYan Jun 11, 2024
7ce6eaf
Add spinner
InAnYan Jun 11, 2024
12430ec
Make all fields in AI preferences vertical
InAnYan Jun 11, 2024
59a8a78
Use MVStore for storing chats
InAnYan Jun 12, 2024
72e306c
Change "System message" to "Instruction"
InAnYan Jun 12, 2024
987e527
Reimplement ID logic for chat history
InAnYan Jun 14, 2024
31d4527
Use synchronize in BibDatabaseChats
InAnYan Jun 14, 2024
fbf2502
Merge pull request #50 from InAnYan/fix-for-11-2
InAnYan Jun 14, 2024
06e79af
Merge branch 'ai-1' into fix-for-14
InAnYan Jun 14, 2024
1f1dcf7
Merge pull request #48 from InAnYan/fix-for-14
InAnYan Jun 14, 2024
7706813
Fix merge conflicts
InAnYan Jun 14, 2024
b47db32
Improve expert settings. (Maybe)
InAnYan Jun 14, 2024
bdc4a9e
Add validation status visualization
InAnYan Jun 14, 2024
70e29fc
Add model ComboBox
InAnYan Jun 14, 2024
bc30d1a
Add temperature parameter
InAnYan Jun 14, 2024
ce85e89
Use MVStore for saving embeddings
InAnYan Jun 15, 2024
f0e518e
Implement EmbeddingsGenerationTaskManager
InAnYan Jun 15, 2024
dbb6f3b
Refactor AI classes
InAnYan Jun 16, 2024
14cf181
Implement the rest of logic of EmbeddingsGenerationTaskManager and ad…
InAnYan Jun 17, 2024
4a114df
For now use web page as help
InAnYan Jun 17, 2024
5b55391
Use MarkdownView for chat message content
InAnYan Jun 17, 2024
747132f
Implement clearing of chat history
InAnYan Jun 17, 2024
8fd52ef
Proper scrolling and change the design of progress indication
InAnYan Jun 17, 2024
5e638bd
Try to implement priority for selected linked files
InAnYan Jun 18, 2024
7df72ed
Attempt to properly handle errors from MVStore opening
InAnYan Jun 18, 2024
a264d6b
Merge pull request #61 from InAnYan/fix-for-51
InAnYan Jun 18, 2024
dbad13c
Merge remote-tracking branch 'refs/remotes/origin/fix-for-preferences…
InAnYan Jun 18, 2024
5a70790
Merge remote-tracking branch 'origin/ai-1' into ai-1
InAnYan Jun 18, 2024
bb716e3
Make public
InAnYan Jun 18, 2024
cd3c2a8
Merge branch 'refs/heads/fix-for-chat-ui' into ai-1
InAnYan Jun 18, 2024
ee8f2a3
Workaround for Markdown chat message content
InAnYan Jun 18, 2024
f4b0195
Use TextArea for chat message content
InAnYan Jun 20, 2024
2aad4b7
Make ExpandableTextArea work
InAnYan Jun 20, 2024
9d92566
Add ADRs
InAnYan Jun 20, 2024
3bc2c2f
Merge remote-tracking branch 'refs/remotes/origin/main' into ai-1
InAnYan Jun 20, 2024
cdc4f81
Resolve conflicts and move AiService
InAnYan Jun 21, 2024
0909743
Fix default parameters of AI
InAnYan Jun 21, 2024
b4e22cb
Fix sentence end mark appearing on left in user messages
InAnYan Jun 21, 2024
f5e432d
Add comments and refactoring
InAnYan Jun 21, 2024
2c091d9
Remove comment
InAnYan Jun 21, 2024
d0adf0b
Merge branch 'refs/heads/main-jabref'
InAnYan Jun 21, 2024
d0d4486
Improve AI preferences tab
InAnYan Jun 21, 2024
0ba1ee7
Fix some of the GitHub actions errors
InAnYan Jun 22, 2024
cc160e3
Fix tests issues
InAnYan Jun 22, 2024
512107f
Merge branch 'refs/heads/main-jabref'
InAnYan Jun 25, 2024
92db40f
Fixes
InAnYan Jun 25, 2024
302dbce
Merge remote-tracking branch 'origin/main'
InAnYan Jun 25, 2024
c2effff
Make new PR
InAnYan Jun 25, 2024
1f88436
Make new PR
InAnYan Jun 26, 2024
4f52037
Merge branch 'refs/heads/upstream-main' into ai-pr-1
InAnYan Jun 26, 2024
926b2a7
Merge branch 'main' into ai-pr-1
Siedlerchr Jun 26, 2024
0e07225
Merge branch 'main' into ai-pr-1
Siedlerchr Jun 26, 2024
91ded93
Use ActionButtons for AI settings documentation
InAnYan Jun 27, 2024
91aa5be
Fix checkstyle warnings
InAnYan Jun 27, 2024
5d49ae4
Update build step in docs
InAnYan Jul 1, 2024
10d72ac
Move // TODO marker
koppor Jul 3, 2024
8e24f93
Sort langchain4j readings
koppor Jul 3, 2024
299ee17
Try to fix "Error: Java heap space" by offering 32 GB RAM (instead of…
koppor Jul 4, 2024
6b6f40f
Order settings alphabetically
koppor Jul 4, 2024
216b9c0
Merge remote-tracking branch 'upstream/main' into ai-pr-1
koppor Jul 4, 2024
305f0d8
Refine description
koppor Jul 4, 2024
94652ba
Update langcahin4j
koppor Jul 4, 2024
6ac6b31
Merge remote-tracking branch 'upstream/main' into ai-pr-1
koppor Jul 4, 2024
468e662
Discard changes to src/main/java/org/jabref/logic/pdf/search/PdfIndex…
koppor Jul 4, 2024
51ce931
Discard changes to src/main/java/org/jabref/logic/pdf/search/Indexing…
koppor Jul 4, 2024
4b015ba
Discard changes to src/test/java/org/jabref/logic/pdf/search/PdfIndex…
koppor Jul 4, 2024
53aec04
Discard changes to src/test/java/org/jabref/logic/pdf/search/PdfSearc…
koppor Jul 4, 2024
4b910b1
Discard changes to src/main/resources/tinylog.properties
koppor Jul 4, 2024
49dce23
Convert to record
koppor Jul 4, 2024
7760b7f
Improve AiChatTab
koppor Jul 4, 2024
59ba6e3
Fix compile errors
koppor Jul 4, 2024
536fc84
Uses patched verison of org.javamodularity.moduleplugin
koppor Jul 4, 2024
d1ead33
Enable the fix
koppor Jul 4, 2024
06c9ec6
Discard changes to src/main/java/org/jabref/gui/exporter/SaveDatabase…
koppor Jul 4, 2024
7b14e50
Merge remote-tracking branch 'origin/fix-run' into ai-pr-1
koppor Jul 4, 2024
521866d
Discard changes to src/main/java/org/jabref/gui/theme/Theme.java
koppor Jul 4, 2024
ef847e5
Merge branch 'refs/heads/upstream-main' into ai-pr-1
InAnYan Jul 5, 2024
d597f5e
Merge remote-tracking branch 'origin/ai-pr-1' into ai-pr-1
InAnYan Jul 5, 2024
8ca536e
Fix the code from code review
InAnYan Jul 6, 2024
1e7221a
Fix from code review and create new AiChatTabWorking
InAnYan Jul 6, 2024
874e513
Improve chat history storage code
koppor Jul 4, 2024
a3b9dd9
More fix from code review
InAnYan Jul 6, 2024
2d65495
Remove obsolete parameter
koppor Jul 8, 2024
08c77ce
Add JavaDoc comment
koppor Jul 8, 2024
ab9ff18
Fix checkstyle
koppor Jul 8, 2024
eb00e30
Fix JavaDoc
koppor Jul 8, 2024
3e6ffb1
Fix more checkstyle
koppor Jul 8, 2024
154d621
More checkstyle fixes
koppor Jul 8, 2024
7e70584
Fix code changes
InAnYan Jul 8, 2024
27cb183
Merge remote-tracking branch 'origin/ai-pr-1' into ai-pr-1
InAnYan Jul 8, 2024
3fb4cbb
Improve the PR
InAnYan Jul 10, 2024
0d617b5
Merge remote-tracking branch 'origin/main' into ai-pr-1
koppor Jul 10, 2024
b3598f6
Rework ADR-0031 to enable to use another option
koppor Jul 10, 2024
ef8b16c
Add many LOGGEr.trace statements
koppor Jul 10, 2024
1b377ee
Change "message window" to "context window"
InAnYan Jul 10, 2024
6ba5cc3
Fix compiler errors
InAnYan Jul 10, 2024
861da12
Fix issue list index issue of langchain4j
koppor Jul 10, 2024
53f1b0f
Fix lint issue
koppor Jul 10, 2024
0034f94
Update 0031-store-chats-alongside-database.md
koppor Jul 10, 2024
81f0278
More tracing
koppor Jul 10, 2024
8f6b252
Merge remote-tracking branch 'origin/main' into ai-pr-1
koppor Jul 11, 2024
e50ff5c
Refine logging
koppor Jul 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ version = project.findProperty('projVersion') ?: '100.0.0'
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

// Workaround needed for Eclipse, probably because of https://github.com/gradle/gradle/issues/16922
// Should be removed as soon as Gradle 7.0.1 is released ( https://github.com/gradle/gradle/issues/16922#issuecomment-828217060 )
modularity.inferModulePath.set(false)
Expand Down Expand Up @@ -96,6 +97,13 @@ application {
// See also https://github.com/java9-modularity/gradle-modules-plugin/issues/165
modularity.disableEffectiveArgumentsAdjustment()

// Required as workaround for https://github.com/langchain4j/langchain4j/issues/1066
modularity.patchModule("langchain4j", "langchain4j-core-0.31.0.jar")
modularity.patchModule("langchain4j", "langchain4j-embeddings-0.31.0.jar")
modularity.patchModule("langchain4j", "langchain4j-embeddings-all-minilm-l6-v2-0.31.0.jar")
modularity.patchModule("langchain4j", "langchain4j-embeddings-all-minilm-l6-v2-q-0.31.0.jar")
modularity.patchModule("langchain4j", "langchain4j-open-ai-0.31.0.jar")

sourceSets {
main {
java {
Expand Down Expand Up @@ -230,12 +238,17 @@ dependencies {
exclude module: 'commons-lang3'
exclude group: 'org.apache.commons.validator'
exclude group: 'org.apache.commons.commons-logging'
exclude module: 'kotlin-stdlib-jdk8'
exclude group: 'com.squareup.retrofit2'
exclude group: 'org.openjfx'
exclude group: 'org.apache.logging.log4j'
exclude group: 'tech.units'
}
// Required by gemsfx
implementation 'tech.units:indriya:2.2'
implementation ('com.squareup.retrofit2:retrofit:2.11.0') {
exclude group: 'com.squareup.okhttp3'
}

implementation 'org.controlsfx:controlsfx:11.2.1'

Expand Down Expand Up @@ -307,6 +320,23 @@ dependencies {
// YAML formatting
implementation 'org.yaml:snakeyaml:2.2'

// AI
implementation 'dev.langchain4j:langchain4j:0.31.0'
implementation 'dev.langchain4j:langchain4j-embeddings-all-minilm-l6-v2:0.31.0'
implementation 'dev.langchain4j:langchain4j-embeddings-all-minilm-l6-v2-q:0.31.0'
implementation('dev.langchain4j:langchain4j-open-ai:0.31.0') {
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
}
// openai depends on okhttp, which needs kotlin - see https://github.com/square/okhttp/issues/5299 for details
// GemxFX also (transitively) depends on kotlin
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.24'

implementation "one.jpro.platform:jpro-mdfx:0.3.3-SNAPSHOT"

implementation ('com.squareup.okhttp3:okhttp:4.12.0') {
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
}

implementation 'commons-io:commons-io:2.16.1'

testImplementation 'io.github.classgraph:classgraph:4.8.174'
Expand Down Expand Up @@ -450,7 +480,22 @@ compileJava {
// TODO: Remove access to internal api
addExports = [
'javafx.controls/com.sun.javafx.scene.control' : 'org.jabref',
'org.controlsfx.controls/impl.org.controlsfx.skin' : 'org.jabref'
'org.controlsfx.controls/impl.org.controlsfx.skin' : 'org.jabref',

'langchain4j/dev.langchain4j.data.document' : 'org.jabref',
'langchain4j/dev.langchain4j.data.segment' : 'org.jabref',
'langchain4j/dev.langchain4j.model.chat' : 'org.jabref',
'langchain4j/dev.langchain4j.model.embedding' : 'org.jabref',
'langchain4j/dev.langchain4j.model.openai' : 'org.jabref',
'langchain4j/dev.langchain4j.rag.content.retriever' : 'org.jabref',
'langchain4j/dev.langchain4j.store.embedding' : 'org.jabref',
'langchain4j/dev.langchain4j.store.embedding.inmemory' : 'org.jabref',
'langchain4j/dev.langchain4j.memory' : 'org.jabref',
'langchain4j/dev.langchain4j.store.memory.chat' : 'org.jabref',
'langchain4j/dev.langchain4j.data.message' : 'org.jabref',
'langchain4j/dev.langchain4j.store.embedding.filter' : 'org.jabref',
'langchain4j/dev.langchain4j.store.embedding.filter.comparison' : 'org.jabref',
'langchain4j/dev.langchain4j.data.embedding' : 'org.jabref',
]
}
}
Expand All @@ -469,6 +514,9 @@ run {
'javafx.base/com.sun.javafx.event' : 'org.jabref.merged.module',
'javafx.controls/com.sun.javafx.scene.control' : 'org.jabref',

'langchain4j/dev.langchain4j.model.chat' : 'org.jabref',
'langchain4j/dev.langchain4j.model.chat' : 'org.jabref.merged.module',

// We need to restate the ControlsFX exports, because we get following error otherwise:
// java.lang.IllegalAccessError:
// class org.controlsfx.control.textfield.AutoCompletionBinding (in module org.controlsfx.controls)
Expand Down
61 changes: 61 additions & 0 deletions docs/decisions/0031-store-chats-alongside-database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
nav_order: 0031
parent: Decision Records
---
<!-- markdownlint-disable-next-line MD025 -->
# Store chats alongside database

## Context and Problem Statement

Chats with AI should be stored somewhere. But where and how?

## Considered Options

* Inside `.bib` file
* In local user folder
* Alongside `.bib` file

## Decision Outcome

Chosen option: "Alongside `.bib` file", because
simple to implement and gives the user the ability to share or not to share the chats.

### Positive Consequences

* Simple implementation
* The user can send the chats file alongside the `.bib` file if they want to share the chats. If users do not want
to share the messages, then they can omit the chats file
* `.bib` files is kept clean

### Negative Consequences

* User may not expect that a new file will be created alongside their `.bib` (or other LaTeX-related) files
* It may be not convenient to share both files (`.bib` file and chats file) in order to share chat history.
* If `.bib` files are edited externally (meaning, not inside the JabRef), then chats file will not be updated correspondingly
* If user moves `.bib` file, they should move the chats file too

## Pros and Cons of the Options

### Inside `.bib` file

* Good, because we already have a machinery for managing the fields and other information of BIB entries
* Good, because chats are stored inside one file, and if the `.bib` file is moved, the chat history is preserved
* Bad, because there may be lots of chats and messages and `.bib` file become too cluttered and too big which slows down the processing of `.bib` file
* Bad, because if user shares a `.bib` file, they will also share chat messages, but chats are not ideal, so user may not
want to share them

### In local user folder

One can use `%APPDATA%`, where JabRef stores the Lucene index and other information.
See `org.jabref.gui.desktop.os.NativeDesktop#getFulltextIndexBaseDirectory` for use in JabRef and
<https://github.com/harawata/appdirs> for general information.

* Good, because `.bib` file is kept clean
* Good, because chat messages are saved locally
* Neutral, because may be a little harder to implement
* Bad, because chat messages cannot be easily shared
* Bad, because when path of a `.bib` file is changed, the chats are lost

### Alongside `.bib` file

Refer to positive and negative consequences of the decision outcome.
49 changes: 49 additions & 0 deletions docs/decisions/0032-store-chats-in-mvstore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
nav_order: 0032
parent: Decision Records
---
# Store chats in MVStore

## Context and Problem Statement

This is a follow-up to [ADR-031](0031-store-chats-alongside-database.md).

The chats with AI should be saved on exit from JabRef and retrieved on launch. We need to decide the format of
the serialized messages.

## Decision Drivers

* Easy to implement and maintain
* Memory-efficient (because JabRef is said to consume much memory)

## Considered Options

* JSON
* MVStore
* Custom format

## Decision Outcome

Chosen option: "MVStore", because it is simple and memory-efficient.

## Pros and Cons of the Options

### JSON

* Good, because allows for easy storing and loading of chats
* Good, because cross-platform
* Good, because widely used and accepted, so there are lots of libraries for JSON format
* Good, because it is even possible to reuse the chats file for other purposes
* Bad, because too verbose (meaning the file size could be much smaller)

### MVStore

* Good, because automatic loading and saving to disk
* Good, because memory-efficient
* Bad, because the order of messages need to be "hand-crafted" (e.g., by mapping from an Integer to the concrete message)

### Custom format

* Good, because we have the full control
* Bad, because involves writing our own language and parser
* Bad, because we need to implement optimizations found in databases on our own (storing some data in RAM, other on disk)
69 changes: 69 additions & 0 deletions docs/decisions/0033-use-citation-key-for-grouping-chat-messages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
nav_order: 0033
parent: Decision Records
---
<!-- markdownlint-disable-next-line MD025 -->
# Use citation key for grouping chat messages

## Context and Problem Statement

Because we store chat messages not inside a BIB entry in `.bib` filecc, the chats file is represented as a map to
BIB entry and a list of messages. We need to specify the key of this map. Turns out, it is not that easy.

## Decision Drivers

* The key should exist for every BIB entry
* The key should be unique along other BIB entries in one library file
* The key should not change at run-time, between launches of JabRef, and should be cross-platform (most important)

## Considered Options

* `BibEntry` Java object
* `BibEntry` ID
* Citation key
* Use `ShareId`

## Decision Outcome

Chosen option: "Citation key", because this is the only choice that complains to the third point in Decision Drivers.

### Positive Consequences

* Easy to implement
* Cross-platform

### Negative Consequences

* If the citation key is changed externally, then the chats file becomes out-of-sync
* Additional user interaction in order to make the citation key complain the first and second points of Decision Drivers

## Pros and Cons of the Options

### `BibEntry` Java object

Very bad, because it works only at run-time and is not stable.

### `BibEntry` ID

JabRef stores a unique identifier for each BibEntry.
This identifier is created on each load of a library (and not stored permanently).

Very bad, for the same reasons as `BibEntry` Java object.

### Citation key

* Good, because it is cross-platform, stable (meaning stays the same across launches of JabRef)
* Bad, because it is not guaranteed that citation key exists on BIB entry, and that it is unique across other
BIB entries in the library

### Use `ShareId`

[ADR-0027](0027-synchronization.md) describes the procedure of synchronization of a Bib(La)TeX library with a server.
Thereby, also local and remote entries need to be kept consistent.
The solution chosen there is that the **server** creates a UUID for each entry.

This approach cannot be used here, because there is no server running which we can ask for an UUID of an entry.

## More Information

Refer to [issue #160](https://github.com/JabRef/jabref/issues/160) in JabRef main repository
84 changes: 84 additions & 0 deletions docs/decisions/0034-use-textarea-for-chat-content.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
nav_order: 0034
parent: Decision Records
---
<!-- markdownlint-disable-next-line MD025 -->
# Use TextArea for chat message content

## Context and Problem Statement

This decision record concerns the UI component that is used for rendering the content of chat messages.

## Decision Drivers

* Looks good (renders Markdown)
* Can select and copy text
* Have good performance

## Considered Options

* Use TextArea
* Use a [third-party package](https://github.com/JPro-one/jpro-platform)
* Use a Markdown parser and convert AST nodes to JavaFX TextFlow elements
* Use a Markdown parser to convert content into HTML and use a WebView for one message
* Use a Markdown parser and WebView for the whole chat history

## Decision Outcome

Chosen option: "Use TextArea".
All other options require some time to implement.
Some of the options doesn't support text selection and copying,
which for now we value better than Markdown rendering.

## Pros and Cons of the Options

### Use TextArea

* Good, because it is easy to implement
* Good, because it supports text selection and copying
* Bad, because it cannot render Markdown
* Bad, because default JavaFX's `TextArea` shrinks

### Use a third-party package

There seems to be only one package for JavaFX that provides a ready-to-use UI node for Markdown rendering.

* Good, because it is easy to implement
* Good, because it renders Markdown
* Good, because it renders Markdown to JavaFX nodes (does not use a `WebView`)
* Good, because complex elements from Markdown are supported (tables, code blocks, etc.)
* Bad, because it has very strange issues and architectural flaws with styling
* Bad, because it does not support text selection and copying (because of underlying JavaFX `Text` nodes)

### Use a Markdown parser and convert AST nodes to JavaFX TextFlow elements

* Good, because we will support Markdown
* Good, because no need to write a Markdown parser from scratch
* Good, because does not use a WebView
* Good, because easy styling
* Bad, because we need some time to implement Markdown AST -> JavaFX nodes converter
* Bad, because rendering tables and code blocks may be hard
* Bad, because it will not support text selection and copying

### Use a Markdown parser to convert content into HTML and use a WebView for one message

* Good, because there are libraries to convert Markdown to HTML
* Good, because may be easier to implement than other choices (except `TextArea`)
* Good, because it supports text selection and copying
* Bad, because it may be a problem to connect JavaFX CSS to `WebView`
* Bad, because one `WebView` for one message is resourceful

### Use a Markdown parser and WebView for the whole chat history

* Good, because there are libraries to convert Markdown to HTML
* Good, because it supports text selection and copying
* Bad, because it may be a problem to connect JavaFX CSS to `WebView`
* Bad, because it may be a problem to correctly communicate with Java code and `WebView` to add new messages

## More Information

Actually we used an `ExpandingTextArea` from `GemsFX` package so the content can occupy
as much space as it needs in the `ScrollPane`.

About the selection and copying, this goes down to fundamental issue from JavaFX.
`Text` and `Label` cannot be selected by any means.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}

rootProject.name = "JabRef"
9 changes: 9 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@

requires org.jooq.jool;

// AI
requires langchain4j;
requires kotlin.stdlib;

// fulltext search
requires org.apache.lucene.core;
// In case the version is updated, please also adapt SearchFieldConstants#VERSION to the newly used version
Expand Down Expand Up @@ -150,4 +154,9 @@
requires dd.plist;
requires mslinks;
requires org.apache.httpcomponents.core5.httpcore5;
requires com.dlsc.unitfx;
requires org.checkerframework.checker.qual;
requires jakarta.validation;
requires one.jpro.platform.mdfx;
requires scala.library;
}
Loading
Loading