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

public Class AiModelService

extends Object
Class Inheritance
Annotations
@NullMarked
Imports
java.util.List, .Optional, org.jabref.logic.ai.chatting.ChatModel, .PredefinedChatModelUtil, org.jabref.logic.ai.chatting.util.ChatModelFactory, org.jabref.model.ai.llm.AiProvider, org.jabref.model.ai.tokenization.TokenEstimatorKind, dev.langchain4j.data.message.UserMessage, org.jspecify.annotations.NullMarked, .Nullable, org.slf4j.Logger, .LoggerFactory

Service for managing AI models from different providers. Provides both static (hardcoded) and dynamic (API-fetched) model lists.

Field Summary

Modifier and TypeField and Description
private static final Logger
private final List<AiModelProvider>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public List<String>

Returns:

A list of model names, or an empty list if the fetch fails
fetchModelsSynchronously
(AiProvider
The AI provider
aiProvider
,
String
The base URL for the API
apiBaseUrl
,
@Nullable String
The API key for authentication (may be null)
apiKey
)

Synchronously fetches the list of available models from the API.

public List<String>

Returns:

A list of available model names
getAvailableModels
(AiProvider
The AI provider
aiProvider
,
String
The base URL for the API
apiBaseUrl
,
@Nullable String
The API key for authentication (may be null)
apiKey
)

Gets the list of available models for the given provider.

public List<String>

Returns:

A list of available model names
getStaticModels
(AiProvider
The AI provider
aiProvider
)

Gets the list of available models for the given provider, using only hardcoded values.

public static boolean
isModelNotFound(Exception exception)

Servers report a model they do not have with a "not found" message, e.g., Ollama: model 'gpt-oss20b' not found.

public String

Returns:

the reply of the model
testConnection
(AiProvider aiProvider, String modelName, String apiKey, double temperature, String apiBaseUrl, int contextWindowSize, TokenEstimatorKind tokenEstimatorKind)

Sends a minimal chat request, which verifies provider, model name, API key, and API base URL in one call.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGGERback to summary
private static final Logger LOGGER
modelProvidersback to summary
private final List<AiModelProvider> modelProviders

Constructor Detail

AiModelServiceback to summary
public AiModelService()

Method Detail

fetchModelsSynchronouslyback to summary
public List<String> fetchModelsSynchronously(AiProvider aiProvider, String apiBaseUrl, @Nullable String apiKey)

Synchronously fetches the list of available models from the API. This method will block until the fetch completes or the HTTP client times out.

Parameters
aiProvider:AiProvider

The AI provider

apiBaseUrl:String

The base URL for the API

apiKey:@Nullable String

The API key for authentication (may be null)

Returns:List<String>

A list of model names, or an empty list if the fetch fails

getAvailableModelsback to summary
public List<String> getAvailableModels(AiProvider aiProvider, String apiBaseUrl, @Nullable String apiKey)

Gets the list of available models for the given provider. First attempts to fetch models dynamically from the API. If that fails or times out, falls back to the hardcoded list.

Parameters
aiProvider:AiProvider

The AI provider

apiBaseUrl:String

The base URL for the API

apiKey:@Nullable String

The API key for authentication (may be null)

Returns:List<String>

A list of available model names

getStaticModelsback to summary
public List<String> getStaticModels(AiProvider aiProvider)

Gets the list of available models for the given provider, using only hardcoded values.

Parameters
aiProvider:AiProvider

The AI provider

Returns:List<String>

A list of available model names

isModelNotFoundback to summary
public static boolean isModelNotFound(Exception exception)

Servers report a model they do not have with a "not found" message, e.g., Ollama: model 'gpt-oss20b' not found.

testConnectionback to summary
public String testConnection(AiProvider aiProvider, String modelName, String apiKey, double temperature, String apiBaseUrl, int contextWindowSize, TokenEstimatorKind tokenEstimatorKind)

Sends a minimal chat request, which verifies provider, model name, API key, and API base URL in one call. A chat request is used instead of listing models, because it works for every provider.

Returns:String

the reply of the model