Package org.codelibs.fess.llm.openai
Class OpenAiLlmClient
java.lang.Object
org.codelibs.fess.llm.AbstractLlmClient
org.codelibs.fess.llm.openai.OpenAiLlmClient
- All Implemented Interfaces:
LlmClient
LLM client implementation for OpenAI API.
OpenAI provides cloud-based LLM services including GPT-4 and other models.
This client supports both synchronous and streaming chat completions.
- Author:
- FessProject
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringThe name identifier for the OpenAI LLM client.Fields inherited from class org.codelibs.fess.llm.AbstractLlmClient
answerGenerationSystemPrompt, availabilityCheckTask, cachedAvailability, directAnswerSystemPrompt, documentNotFoundSystemPrompt, evaluationPrompt, faqAnswerSystemPrompt, httpClient, intentDetectionPrompt, noResultsSystemPrompt, objectMapper, summarySystemPrompt, summarySystemPromptSuffix, unclearIntentSystemPrompt -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildRequestBody(LlmChatRequest request, boolean stream) Builds the request body for the OpenAI API.chat(LlmChatRequest request) Performs a chat completion request.protected booleanPerforms the actual availability check against the LLM provider.convertMessage(LlmMessage message) Converts an LlmMessage to a map for the API request.protected StringGets the OpenAI API key.protected StringGets the OpenAI API URL.protected intGets the maximum tokens for result evaluation.protected intGets the maximum tokens for intent detection.protected StringgetModel()Gets the model name.getName()Returns the name of this LLM client.protected intGets the request timeout in milliseconds.protected booleanisReasoningModel(String model) Determines whether the given model is a reasoning model that uses internal reasoning tokens (e.g., o1, o3, o4, gpt-5 series).voidstreamChat(LlmChatRequest request, LlmStreamCallback callback) Performs a streaming chat completion request.protected booleansupportsTemperature(String model) Determines whether the given model supports the "temperature" parameter.protected booleanuseMaxCompletionTokens(String model) Determines whether the given model requires the "max_completion_tokens" parameter instead of the legacy "max_tokens" parameter.Methods inherited from class org.codelibs.fess.llm.AbstractLlmClient
addHistory, buildContext, buildEvaluationPrompt, buildIntentDetectionPrompt, buildStreamingRequest, destroy, detectIntent, evaluateResults, extractJsonArray, extractJsonBoolean, extractJsonIntArray, extractJsonString, extractJsonStringFallback, generateAnswer, generateDirectAnswer, generateDocumentNotFoundResponse, generateFaqAnswerResponse, generateNoResultsResponse, generateSummaryResponse, generateUnclearIntentResponse, getAvailabilityCheckInterval, getHttpClient, getLanguageInstruction, getLlmType, getMaxTokens, getStringValue, getTemperature, getUserLocale, init, isAvailable, isRagChatEnabled, parseEvaluationResponse, parseIntentResponse, resolveLanguageInstruction, setAnswerGenerationSystemPrompt, setDirectAnswerSystemPrompt, setDocumentNotFoundSystemPrompt, setEvaluationPrompt, setFaqAnswerSystemPrompt, setIntentDetectionPrompt, setNoResultsSystemPrompt, setSummarySystemPrompt, setSummarySystemPromptSuffix, setUnclearIntentSystemPrompt, startAvailabilityCheck, streamGenerateAnswer, stripCodeFences, updateAvailability
-
Field Details
-
NAME
The name identifier for the OpenAI LLM client.- See Also:
-
-
Constructor Details
-
OpenAiLlmClient
public OpenAiLlmClient()Default constructor.
-
-
Method Details
-
getName
Description copied from interface:LlmClientReturns the name of this LLM client.- Returns:
- the client name (e.g., "ollama", "openai", "gemini")
-
checkAvailabilityNow
protected boolean checkAvailabilityNow()Description copied from class:AbstractLlmClientPerforms the actual availability check against the LLM provider.- Specified by:
checkAvailabilityNowin classAbstractLlmClient- Returns:
- true if the provider is available
-
chat
Description copied from interface:LlmClientPerforms a chat completion request.- Parameters:
request- the chat request containing messages and parameters- Returns:
- the chat response from the LLM
-
streamChat
Description copied from interface:LlmClientPerforms a streaming chat completion request. The callback is invoked for each chunk of the response.- Parameters:
request- the chat request containing messages and parameterscallback- the callback to receive streaming chunks
-
buildRequestBody
Builds the request body for the OpenAI API.- Parameters:
request- the chat requeststream- whether to enable streaming- Returns:
- the request body as a map
-
useMaxCompletionTokens
Determines whether the given model requires the "max_completion_tokens" parameter instead of the legacy "max_tokens" parameter.- Parameters:
model- the model name- Returns:
- true if the model uses max_completion_tokens
-
supportsTemperature
Determines whether the given model supports the "temperature" parameter. Some newer models (e.g., gpt-5-mini) only support the default temperature value.- Parameters:
model- the model name- Returns:
- true if the model supports custom temperature values
-
isReasoningModel
Determines whether the given model is a reasoning model that uses internal reasoning tokens (e.g., o1, o3, o4, gpt-5 series).- Parameters:
model- the model name- Returns:
- true if the model is a reasoning model
-
convertMessage
Converts an LlmMessage to a map for the API request.- Parameters:
message- the message to convert- Returns:
- the message as a map
-
getApiKey
Gets the OpenAI API key.- Returns:
- the API key
-
getApiUrl
Gets the OpenAI API URL.- Returns:
- the API URL
-
getModel
Description copied from class:AbstractLlmClientGets the model name.- Specified by:
getModelin classAbstractLlmClient- Returns:
- the model name
-
getTimeout
protected int getTimeout()Description copied from class:AbstractLlmClientGets the request timeout in milliseconds.- Specified by:
getTimeoutin classAbstractLlmClient- Returns:
- the timeout in milliseconds
-
getIntentDetectionMaxTokens
protected int getIntentDetectionMaxTokens()Description copied from class:AbstractLlmClientGets the maximum tokens for intent detection.- Overrides:
getIntentDetectionMaxTokensin classAbstractLlmClient- Returns:
- the maximum tokens for intent detection
-
getEvaluationMaxTokens
protected int getEvaluationMaxTokens()Description copied from class:AbstractLlmClientGets the maximum tokens for result evaluation.- Overrides:
getEvaluationMaxTokensin classAbstractLlmClient- Returns:
- the maximum tokens for result evaluation
-