Add AiModelService for improving JabRef handling of language models (#13860)#14197
Conversation
Hey @st-rm-ng!Thank you for contributing to JabRef! Your help is truly appreciated ❤️. We have automatic checks in place, based on which you will soon get automated feedback if any of them are failing. We also use TragBot with custom rules that scans your changes and provides some preliminary comments, before a maintainer takes a look. TragBot is still learning, and may not always be accurate. In the "Files changed" tab, you can go through its comments and just click on "Resolve conversation" if you are sure that it is incorrect, or comment on the conversation if you are doubtful. Please re-check our contribution guide in case of any other doubts related to our contribution workflow. |
InAnYan
left a comment
There was a problem hiding this comment.
Hi!
Thanks very much for looking into this issue. I left some comments to change. Currently I'm on phone and I wasn't able to test the PR
koppor
left a comment
There was a problem hiding this comment.
The threading thing looks complicated. There at least should be a note why a "synchronous" nested thread-spawning thing is nested in a Background-Task.
Not sure if this is the call for using RxJava to enable easy parallel processing: https://github.com/ReactiveX/RxJava#parallel-processing
The reason for this complexity is to implement a timeout mechanism that we need to avoid blocking the BackgroundTask thread indefinitely. You are right, this solution is maybe overly complicated and from my perspective it would be maybe better to use Regarding RxJava - I think that in this case I am only fetching models from one provider at a time and maybe it would be better for the future to fetch models from multiple providers in parallel using RxJava. Maybe something like @koppor Should I use RxJava approach instead? What would be your advice? |
…enAiCompatibleModelProvider
For timeouts you could leverage the functionality of the Completable Future https://www.baeldung.com/java-completablefuture-timeout |
@st-rm-ng please follow that advice. |
|
Okay, I only reviewed the code, but I find it very clear and easy to read. But may I ask this question: why there is at all some complicated logic for fetching the models? Why do you need to create a fetch thread and check that it's alive? I think 1 |
koppor
left a comment
There was a problem hiding this comment.
Okay, I only reviewed the code, but I find it very clear and easy to read. But may I ask this question: why there is at all some complicated logic for fetching the models? Why do you need to create a fetch thread and check that it's alive?
The contributor answered:
The reason for this complexity is to implement a timeout mechanism that we need to avoid blocking the BackgroundTask thread indefinitely
Therefore siedlerchr recommended https://www.baeldung.com/java-completablefuture-timeout
Hope this works.
|
Sorry, maybe I miss something, but I still don't get why implementing timeout is that hard and how it can block the background tasks? (I think we use a thread pool) Here is an example how to send http request with timeout that ChatGPT generated me: import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
public class SimpleHttp {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(5)) // connection timeout
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI("https://example.com"))
.timeout(Duration.ofSeconds(3)) // request timeout
.GET()
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}When it reaches timeout, an exception will be thrown.
|
|
Sorry, maybe I just don't know something about Java |
|
@koppor I've made modifications to use Nullmarked and Nullable as you hinted me. Is this what you had in your mind? |
@st-rm-ng what's the answer for that? |
I haven't connected this back-end code to UI yet, still working on it |
Nice one thank you. Looking forward for the update. |
| } | ||
| } | ||
| } | ||
| } catch (Exception e) { |
There was a problem hiding this comment.
No catching of global exception, needs to be a more specific ones
|
Although the UI is missing I think it would be good start to have this |
I agree. We can add a follow-up issue. |
| "test-key" | ||
| ); | ||
|
|
||
| assertTrue(models.isEmpty()); |
There was a problem hiding this comment.
AI generated
Normally,
assertEquals(List.of(), models);
* upstream/main: (64 commits) New Crowdin updates (JabRef#14862) Make JDK25 available (JabRef#14861) Fix empty entries array when exporting group chat to JSON (JabRef#14814) feat: add right-click copy context menu to AI chat messages (JabRef#14722) FIX : generic error dialog and icon in Source Tab parsing (JabRef#14828) Factor out setup-* actions (JabRef#14859) Link .http files. Update dependency org.postgresql:postgresql to v42.7.9 (JabRef#14857) Add more commands to JabSrv (JabRef#14855) Fix JabRef#14821: Hide identifier action buttons when field is empty (JabRef#14831) Add GH_TOKEN to closed issues/PRs processing step New Crowdin updates (JabRef#14854) New Crowdin updates (JabRef#14849) Chore(deps): Bump jablib/src/main/resources/csl-styles from `0201999` to `f345aa8` (JabRef#14833) Add support for book front covers, again (JabRef#14777) Readd min width to button in new enty dialog (JabRef#14791) Replace plugin impl from jbang plugin (JabRef#14846) Revise AI policy wording Chore(deps): Bump jablib/src/main/resources/csl-locales (JabRef#14677) Update dependency com.konghq:unirest-modules-gson to v4.7.1 (JabRef#14845) ...
koppor
left a comment
There was a problem hiding this comment.
I would say: Good enough, we can fix things later.
Contributes to #13860
Steps to test
./gradlew :jablib:test --tests "org.jabref.logic.ai.models.*Test"Mandatory checks
CHANGELOG.mdin a way that is understandable for the average user (if change is visible to the user)