Verified Owner
Top Description Inners Fields Constructors Methods
org.jabref.logic.ai.chatting.util

public final Class ChatModelFactory

extends Object
Class Inheritance
Imports
java.net.http.HttpClient, java.time.Duration, java.util.List, java.util.concurrent.ExecutorService, .Executors, org.jabref.logic.ai.chatting.ChatModel, .JvmOpenAiChatLanguageModel, org.jabref.logic.ai.preferences.AiPreferences, org.jabref.logic.ai.tokenization.logic.TokenEstimator, org.jabref.logic.ai.tokenization.util.TokenEstimatorFactory, org.jabref.model.ai.llm.AiProvider, org.jabref.model.ai.tokenization.TokenEstimatorKind, com.google.common.util.concurrent.ThreadFactoryBuilder, dev.langchain4j.model.chat.response.ChatResponse, dev.langchain4j.model.googleai.GoogleAiGeminiChatModel, dev.langchain4j.model.mistralai.MistralAiChatModel

Static factory for creating ChatModel instances.

Each call creates its own HttpClient and ExecutorService. The returned model implements AutoCloseable; callers should close it when it is no longer needed so the underlying resources are released.

Returns null when AI is disabled or the API key is empty.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final Duration

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ChatModel
create(AiProvider provider, String modelName, String apiKey, double temperature, String baseUrl, int contextWindowSize, TokenEstimatorKind tokenEstimatorKind)

Creates a ChatModel from explicit parameters.

public static ChatModel
create(AiPreferences aiPreferences)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CONNECTION_TIMEOUTback to summary
private static final Duration CONNECTION_TIMEOUT

Constructor Detail

ChatModelFactoryback to summary
private ChatModelFactory()

Method Detail

createback to summary
public static ChatModel create(AiProvider provider, String modelName, String apiKey, double temperature, String baseUrl, int contextWindowSize, TokenEstimatorKind tokenEstimatorKind)

Creates a ChatModel from explicit parameters. All decisions about provider, model name, API key, etc. must be made by the caller.

createback to summary
public static ChatModel create(AiPreferences aiPreferences)
org.jabref.logic.ai.chatting.util back to summary

private Class ChatModelFactory.ChatModelImpl

extends Object
implements ChatModel
Class Inheritance
  • java.lang.Object
  • org.jabref.logic.ai.chatting.util.ChatModelFactory.ChatModelImpl
All Implemented Interfaces
org.jabref.logic.ai.chatting.ChatModel, java.lang.AutoCloseable

Field Summary

Modifier and TypeField and Description
private final int
private final dev.langchain4j.model.chat.ChatModel
private final ExecutorService
private final HttpClient
private final String
private final AiProvider
private final TokenEstimator

Constructor Summary

AccessConstructor and Description
pack-priv
ChatModelImpl(dev.langchain4j.model.chat.ChatModel delegate, TokenEstimator tokenEstimator, AiProvider provider, String name, int contextWindowSize, HttpClient httpClient, ExecutorService executorService)

Method Summary

Modifier and TypeMethod and Description
public dev.langchain4j.model.chat.response.ChatResponse
chat(List<dev.langchain4j.data.message.ChatMessage> messages)

public void
close()

Implements org.jabref.logic.ai.chatting.ChatModel.close.

Closes this resource, relinquishing any underlying resources.

public AiProvider
public int
public String
public TokenEstimator
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextWindowSizeback to summary
private final int contextWindowSize
delegateback to summary
private final dev.langchain4j.model.chat.ChatModel delegate
executorServiceback to summary
private final ExecutorService executorService
httpClientback to summary
private final HttpClient httpClient
nameback to summary
private final String name
providerback to summary
private final AiProvider provider
tokenEstimatorback to summary
private final TokenEstimator tokenEstimator

Constructor Detail

ChatModelImplback to summary
pack-priv ChatModelImpl(dev.langchain4j.model.chat.ChatModel delegate, TokenEstimator tokenEstimator, AiProvider provider, String name, int contextWindowSize, HttpClient httpClient, ExecutorService executorService)

Method Detail

chatback to summary
public dev.langchain4j.model.chat.response.ChatResponse chat(List<dev.langchain4j.data.message.ChatMessage> messages)
Annotations
@Override
closeback to summary
public void close()

Implements org.jabref.logic.ai.chatting.ChatModel.close.

Doc from java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

Annotations
@Override
getAiProviderback to summary
public AiProvider getAiProvider()

Implements org.jabref.logic.ai.chatting.ChatModel.getAiProvider.

Annotations
@Override
getContextWindowSizeback to summary
public int getContextWindowSize()

Implements org.jabref.logic.ai.chatting.ChatModel.getContextWindowSize.

Annotations
@Override
getNameback to summary
public String getName()

Implements org.jabref.logic.ai.chatting.ChatModel.getName.

Annotations
@Override
getTokenizerback to summary
public TokenEstimator getTokenizer()

Implements org.jabref.logic.ai.chatting.ChatModel.getTokenizer.

Annotations
@Override