Skip to content

Conversation

@st-rm-ng
Copy link

@st-rm-ng st-rm-ng commented Oct 30, 2025

Closes #13860

Steps to test

Mandatory checks

@github-actions
Copy link
Contributor

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.

@jabref-machine
Copy link
Collaborator

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 // formatter:off and // formatter:on annotations to allow deviation from the code style.

}
}
} catch (Exception e) {
LOGGER.warn("Failed to parse models response: {}", e.getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

Please read our docs on Logging.

@koppor koppor requested a review from InAnYan October 30, 2025 15:14
Copy link
Member

@InAnYan InAnYan left a 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

* @param apiKey The API key for authentication
* @return A CompletableFuture containing the list of model names
*/
public CompletableFuture<List<String>> fetchModelsAsync(AiProvider aiProvider, String apiBaseUrl, String apiKey) {
Copy link
Member

Choose a reason for hiding this comment

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

I think there is too much asynchronous/parallelism.

What we use in JabRef, and what I think is enough to do is to actually write only synchronous methods, and if we need something to happen in background we create a new class that inherits from BackgroundTask and it calls a synchronous method.

So, you write everything synchronously, then you create a class FetchAiModelsBackgroundTask, and in the AiService you start that task. Could you implement an approach like this?

private final HttpClient httpClient;

public OpenAiCompatibleModelProvider() {
this.httpClient = HttpClient.newBuilder()
Copy link
Member

Choose a reason for hiding this comment

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

Just in case, can you check: does this object needs to be closed?

|| aiProvider == AiProvider.GPT4ALL;
}

private String buildModelsEndpoint(String apiBaseUrl) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you use a type that is more specific to URLs, rather than a raw string?


@Override
public boolean supports(AiProvider aiProvider) {
// OpenAI-compatible providers: OpenAI, Mistral AI, and custom OpenAI-compatible endpoints
Copy link
Member

Choose a reason for hiding this comment

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

I think this comment (and potentially other docstrings) should be rewritten to sound like this:

"Mistral provides an API that has the same endpoint for fetching available models as OpenAI, thus this class is able to fetch models also from Mistral"

This is not ideal wording, but I hope you got the idea - so that person reading code would understand why these providers are called "OpenAI compatible". It's actually my mistake too, as I also haven't explained this properly

@st-rm-ng
Copy link
Author

Hello @koppor and @InAnYan,

this is just a Draft PR, and it's not ready to be tested or anything. Think of this as my initial attempt or establishment to view all changes. I will let you know when it will be in ready for review state.

Thank you very much for your quick response to this PR 😄

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.

Improve JabRef handling of language models

4 participants