Package org.codelibs.fess.llm.ollama
Class OllamaLlmClient
java.lang.Object
org.codelibs.fess.llm.AbstractLlmClient
org.codelibs.fess.llm.ollama.OllamaLlmClient
- All Implemented Interfaces:
LlmClient
LLM client implementation for Ollama.
Ollama provides a local LLM server that can run various models
like Llama, Mistral, etc. on your own hardware.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringThe name identifier for the Ollama 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 Ollama 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 Ollama 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 booleanisModelAvailable(String responseBody) Checks if the configured model is available in Ollama.voidstreamChat(LlmChatRequest request, LlmStreamCallback callback) Performs a streaming chat completion request.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 Ollama LLM client.- See Also:
-
-
Constructor Details
-
OllamaLlmClient
public OllamaLlmClient()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
-
isModelAvailable
Checks if the configured model is available in Ollama.- Parameters:
responseBody- the response body from /api/tags endpoint- Returns:
- true if the configured model 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 Ollama API.- Parameters:
request- the chat requeststream- whether to enable streaming- Returns:
- the request body as a map
-
convertMessage
Converts an LlmMessage to a map for the API request.- Parameters:
message- the message to convert- Returns:
- the message as a map
-
getApiUrl
Gets the Ollama 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
-