Skip to content

Changing the AI model in the preferences does not change the text of the status bar#14053

Merged
Siedlerchr merged 32 commits into
JabRef:mainfrom
sobinovskymatus:fix-for-issue-13855
Oct 13, 2025
Merged

Changing the AI model in the preferences does not change the text of the status bar#14053
Siedlerchr merged 32 commits into
JabRef:mainfrom
sobinovskymatus:fix-for-issue-13855

Conversation

@sobinovskymatus

Copy link
Copy Markdown
Contributor

Closes #13855

  1. The problem was that when user set new ai model in preferences the info text in AI Chat doesn't change only after user switch to another entry then he see changes.
  2. I remake function initializeNotice() in AiChatComponent class - now it binds noticeText.TextProperty() to a computed string using Bindings.createStringBinding() - that binding calls new function computeNoticeText() whenever any of the Observables returned by also new function noticeDependencies() change so the UI text auto-updates
  3. new function computeNoticeText() - looks up the currently selected AI provider label and model from AiPreferences, then it builds string by taking the saved noticeTemplate and replacing the placeholder %0 with "provider model" (e.g. OpenAI gpt-4o-mini), then it returns final string for the binding to show in the UI.
  4. new noticeDependencies() - lists of all observables properties that should trigger the recomputation of the notice, any change of these properties invalidates the binding which makes computeNoticeText() run again and refresh the text
  5. Also i test for this functionality in new Test class AiChatComponentTest

Steps to test

  1. Open JabRef, -> click on any entry -> click on "AI chat" -> down you can see that currently the "Open AI" "gpt-4o-mini" is set
image 2. Go to File -> Preferences -> AI -> and for example change "AI provider" to Gemini -> click "Save" -> now down in AI chat you can see that "Open AI" changes to "Gemini" and "gpt-4o-mini" changes to "gemini-1.5-flash" without need to click on another entry or refresh anything image

Mandatory checks

@sobinovskymatus sobinovskymatus changed the title Fix for issue 13855 Fix for issue 13855 #13855 Oct 8, 2025
@sobinovskymatus sobinovskymatus changed the title Fix for issue 13855 #13855 Fix for issue #13855 Oct 8, 2025
@sobinovskymatus sobinovskymatus changed the title Fix for issue #13855 Changing the AI model in the preferences does not change the text of the status bar Oct 8, 2025
Comment thread CHANGELOG.md Outdated
Comment thread CHANGELOG.md Outdated
@sobinovskymatus sobinovskymatus marked this pull request as ready for review October 8, 2025 19:22
Comment thread jabgui/src/test/java/org/jabref/gui/ai/components/aichat/AiChatComponentTest.java Outdated
Comment thread jabgui/src/test/java/org/jabref/gui/ai/components/aichat/AiChatComponentTest.java Outdated
Comment thread jabgui/src/test/java/org/jabref/gui/ai/components/aichat/AiChatComponentTest.java Outdated
Comment thread jabgui/src/test/java/org/jabref/gui/ai/components/aichat/AiChatComponentTest.java Outdated
Comment thread CHANGELOG.md Outdated
Siedlerchr
Siedlerchr previously approved these changes Oct 12, 2025
Comment thread jabgui/src/test/java/org/jabref/gui/ai/components/aichat/AiChatComponentTest.java Outdated
Comment thread jabgui/src/test/java/org/jabref/gui/ai/components/aichat/AiChatComponentTest.java Outdated
Comment thread jabgui/src/test/java/org/jabref/gui/ai/components/aichat/AiChatComponentTest.java Outdated
sobinovskymatus and others added 3 commits October 13, 2025 00:16
…tComponentTest.java

Co-authored-by: Subhramit Basu <subhramit.bb@live.in>
…tComponentTest.java

Co-authored-by: Subhramit Basu <subhramit.bb@live.in>
subhramit
subhramit previously approved these changes Oct 12, 2025
Comment on lines +67 to +81
when(prefs.getAiProvider()).thenAnswer(_ -> providerProp.get());
when(prefs.getSelectedChatModel()).thenAnswer(_ -> {
return switch (providerProp.get()) {
case OPEN_AI ->
openAiModelProp.get();
case MISTRAL_AI ->
mistralModelProp.get();
case GEMINI ->
geminiModelProp.get();
case HUGGING_FACE ->
hfModelProp.get();
case GPT4ALL ->
gpt4AllModelProp.get();
};
});

Copy link
Copy Markdown
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 a bit nonsense. The answer of getSelectedChatModel() is ignored, instead you are looking up on a local variable providerProp, which is a few lines above set to OPEN_AI.
You could just make this a constant and abolish the switch, if i read this correctly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also change this one now -
image

AiChatComponent component = createComponent(FXCollections.observableArrayList(), FXCollections.observableArrayList());

// Change provider
prefs.aiProviderProperty().set(provider);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You always set prefs to return OPEN_AI in the setup method
grafik

So this test is testing five times if OPEN_AI works.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what the test noticeTextUpdatesWhenProviderChanges() test -
image
image
So I dont think that this test is testing OPEN_AI five times every time this test runs it uses another provider from AiProvider class like you can see in the images i provide.

Comment on lines +138 to +151
// Set the provider and the corresponding model
prefs.aiProviderProperty().set(provider);
switch (provider) {
case OPEN_AI ->
prefs.openAiChatModelProperty().set(newModel);
case MISTRAL_AI ->
prefs.mistralAiChatModelProperty().set(newModel);
case GEMINI ->
prefs.geminiChatModelProperty().set(newModel);
case HUGGING_FACE ->
prefs.huggingFaceChatModelProperty().set(newModel);
case GPT4ALL ->
prefs.gpt4AllChatModelProperty().set(newModel);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The switch is a bit useless imho, i dont see that in testing setting the model of another provider affects the tested provider. Set them up in the setup method. Then the enumsource can also be used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is the second test with little changes -
image
and this is an output from test -
image
@calixtus is it okay now or should I do any other changes because honestly I dont know what else can I do in this class, but if you have some tips how to do it better fell free to write it.

Comment thread jabgui/src/test/java/org/jabref/gui/ai/components/aichat/AiChatComponentTest.java Outdated
@calixtus

calixtus commented Oct 13, 2025

Copy link
Copy Markdown
Member

Ok, what i think whats causing my confusion is that the tests try to test two different things: On one hand if computeNoticeTest produces the correct text and on the other if the observables are triggering the computeNoticeTest method.

@sobinovskymatus

sobinovskymatus commented Oct 13, 2025

Copy link
Copy Markdown
Contributor Author

@calixtus so what should i do now should i remake tests to only test that observables are triggering the computeNoticeTest method (because i think thats the main point what the output of this issue should be) or should i only test that computeNoticeTest produce the correct text or both can you please help me with this one so we can close this issue successfully? I think that we can do something like this we can create little function in test class getNoticeLabelText() which accesses the label (our notice text) via reflection
image
and then we do test like this for example where we dont call any function from AiChatComponent we only set for example new provider and then check if the label was changed something like this.
image What do you think about it?

@Siedlerchr Siedlerchr enabled auto-merge October 13, 2025 18:42
@calixtus

Copy link
Copy Markdown
Member

ok, to move forward, we decided to merge in the state as is.

@Siedlerchr Siedlerchr added this pull request to the merge queue Oct 13, 2025
Merged via the queue into JabRef:main with commit 8ec4808 Oct 13, 2025
49 checks passed
merlinymy pushed a commit to merlinymy/jabref that referenced this pull request Nov 19, 2025
…the status bar (JabRef#14053)

* changed initializeNotice() in AiChatComponent class / now should work properly / need to add test

* add test for checking if the value of ai model is changing

* changed CHANGELOG.md

* deleted System.out from AiChatComponent.java

* some changes in CHANGELOG.md

* another changes in CHANGELOG.md

* updates test for AiChatComponent class

* CHANGELOG.md changes

* edit CHANGELOG.md

* update for tests in AiChatComponentTest class / update for function computeNoticeText() in AiChatComponent class

* Fix submodules

* Fix submodules

* Update

* Update csl-locales

* Update submodules

* Fix submodules

* Update jabgui/src/test/java/org/jabref/gui/ai/components/aichat/AiChatComponentTest.java

Co-authored-by: Subhramit Basu <subhramit.bb@live.in>

* Update jabgui/src/test/java/org/jabref/gui/ai/components/aichat/AiChatComponentTest.java

Co-authored-by: Subhramit Basu <subhramit.bb@live.in>

* Update AiChatComponentTest.java

* Update AiChatComponentTest.java - make som cleanup changes

---------

Co-authored-by: Subhramit Basu <subhramit.bb@live.in>
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.

Changing the AI model in the preferences does not change the text of the status bar

4 participants