-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add AiModelService for improving JabRef handling of language models (#13860) #14197
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
base: main
Are you sure you want to change the base?
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. |
jablib/src/main/java/org/jabref/logic/ai/models/OpenAiCompatibleModelProvider.java
Outdated
Show resolved
Hide resolved
InAnYan
left a comment
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.
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
jablib/src/main/java/org/jabref/logic/ai/models/AiModelService.java
Outdated
Show resolved
Hide resolved
jablib/src/main/java/org/jabref/logic/ai/models/OpenAiCompatibleModelProvider.java
Show resolved
Hide resolved
jablib/src/main/java/org/jabref/logic/ai/models/OpenAiCompatibleModelProvider.java
Outdated
Show resolved
Hide resolved
jablib/src/main/java/org/jabref/logic/ai/models/OpenAiCompatibleModelProvider.java
Outdated
Show resolved
Hide resolved
|
Your code currently does not meet JabRef's code guidelines. IntelliJ auto format covers some cases. There seem to be issues with your code style and autoformat configuration. Please reformat your code (Ctrl+Alt+L) and commit, then push. In special cases, consider using |
koppor
left a comment
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
|
Thank you for advices @Siedlerchr, @koppor and @InAnYan. I've removed redundant FetchThread timeout mechanism for simpler synchronous model fetching and I've used built-in timeout for HTTP Client fetching. I didn't use |
|
JUnit tests of You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide. |
Closes #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)