Verified Owner
Top Description Fields Constructors Methods
org.jabref.logic.ai.models

public Class OpenAiCompatibleModelProvider

extends Object
implements AiModelProvider
Class Inheritance
All Implemented Interfaces
org.jabref.logic.ai.models.AiModelProvider
Annotations
@NullMarked
Imports
java.net.MalformedURLException, java.time.Duration, java.util.ArrayList, .List, org.jabref.logic.importer.FetcherClientException, .FetcherException, org.jabref.logic.net.URLDownload, org.jabref.model.ai.llm.AiProvider, kong.unirest.core.JsonNode, kong.unirest.core.json.JSONArray, kong.unirest.core.json.JSONException, kong.unirest.core.json.JSONObject, org.jspecify.annotations.NullMarked, .Nullable, org.slf4j.Logger, .LoggerFactory

Model provider for OpenAI-compatible APIs. Fetches available models from the /v1/models endpoint. Mistral provides an OpenAI-compatible API, so this works for Mistral as well.

Field Summary

Modifier and TypeField and Description
private static final Duration
private static final Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private String

Returns:

the complete URL for the models endpoint
buildModelsEndpoint
(String
the base URL of the API (e.g., "https://api.openai.com" or "https://api.openai.com/v1")
apiBaseUrl
)

Builds the URL for the models endpoint from the given API base URL.

public List<String>
fetchModels(AiProvider aiProvider, String apiBaseUrl, @Nullable String apiKey)

private List<String>
parseModelsFromResponse(kong.unirest.core.JsonNode jsonNode)

public boolean
supports(AiProvider aiProvider)

Implements org.jabref.logic.ai.models.AiModelProvider.supports.

Checks if this provider supports the given AI provider type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CONNECT_TIMEOUTback to summary
private static final Duration CONNECT_TIMEOUT
LOGGERback to summary
private static final Logger LOGGER

Constructor Detail

OpenAiCompatibleModelProviderback to summary
public OpenAiCompatibleModelProvider()

Method Detail

buildModelsEndpointback to summary
private String buildModelsEndpoint(String apiBaseUrl)

Builds the URL for the models endpoint from the given API base URL.

The OpenAI API specification defines the models endpoint at /v1/models. This method handles various URL formats:

  • If the URL already ends with /v1, appends /models
  • If the URL doesn't end with /v1, appends /v1/models
  • Removes trailing slashes before building the path
Parameters
apiBaseUrl:String

the base URL of the API (e.g., "https://api.openai.com" or "https://api.openai.com/v1")

Returns:String

the complete URL for the models endpoint

fetchModelsback to summary
public List<String> fetchModels(AiProvider aiProvider, String apiBaseUrl, @Nullable String apiKey)
Annotations
@Override
parseModelsFromResponseback to summary
private List<String> parseModelsFromResponse(kong.unirest.core.JsonNode jsonNode)
supportsback to summary
public boolean supports(AiProvider aiProvider)

Implements org.jabref.logic.ai.models.AiModelProvider.supports.

Doc from org.jabref.logic.ai.models.AiModelProvider.supports.

Checks if this provider supports the given AI provider type.

Annotations
@Override