Class OllamaDecisionModel.OllamaDecisionModelBuilder
java.lang.Object
dev.langchain4j.model.ollama.OllamaDecisionModel.OllamaDecisionModelBuilder
- Enclosing class:
OllamaDecisionModel
- Since:
- 1.23.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThe URL of the Ollama server, for examplehttp://localhost:11434.build()customHeaders(Supplier<Map<String, String>> customHeadersSupplier) Sets a supplier for custom HTTP headers.customHeaders(Map<String, String> customHeaders) Sets custom HTTP headers.httpClientBuilder(HttpClientBuilder httpClientBuilder) Sets theHttpClientBuilderused to create the HTTP client that communicates with Ollama.How long, in seconds, Ollama keeps the model loaded in memory after a request.listeners(DecisionModelListener... listeners) listeners(List<DecisionModelListener> listeners) Sets the listeners that are notified of every request, response and error.logger(org.slf4j.Logger logger) An alternateLoggerto be used instead of the default one for logging requests and responses.logRequests(Boolean logRequests) Whether to log requests.logResponses(Boolean logResponses) Whether to log responses.maxRetries(Integer maxRetries) The number of retries after the first attempt, for transient errors such as timeouts and server errors.The decision model to use when a request does not specify one, for examplenimble.The connect and read timeout.
-
Constructor Details
-
OllamaDecisionModelBuilder
public OllamaDecisionModelBuilder()
-
-
Method Details
-
httpClientBuilder
public OllamaDecisionModel.OllamaDecisionModelBuilder httpClientBuilder(HttpClientBuilder httpClientBuilder) Sets theHttpClientBuilderused to create the HTTP client that communicates with Ollama.NOTE:
timeout(Duration)overrides timeouts set on theHttpClientBuilder. -
baseUrl
The URL of the Ollama server, for examplehttp://localhost:11434. Required. -
modelName
The decision model to use when a request does not specify one, for examplenimble. The model name must be set either here or on each request, and the model must have been downloaded (ollama pull nimble). -
timeout
The connect and read timeout. When not set, the timeouts of thehttpClientBuilder(HttpClientBuilder)are used, or 15 seconds (connect) and 60 seconds (read). Without a GPU, or while a model is being loaded, a request can take several seconds. -
maxRetries
The number of retries after the first attempt, for transient errors such as timeouts and server errors. Default value is 2. -
keepAlive
How long, in seconds, Ollama keeps the model loaded in memory after a request.0unloads it right away, and a negative value keeps it loaded. When not set, the Ollama server's setting is used (5 minutes, unless configured otherwise). Loading a decision model can take several seconds, so a longer value avoids that delay when requests are infrequent. -
logRequests
Whether to log requests. Default value isfalse. -
logResponses
Whether to log responses. Default value isfalse. -
logger
An alternateLoggerto be used instead of the default one for logging requests and responses. -
customHeaders
public OllamaDecisionModel.OllamaDecisionModelBuilder customHeaders(Map<String, String> customHeaders) Sets custom HTTP headers. -
customHeaders
public OllamaDecisionModel.OllamaDecisionModelBuilder customHeaders(Supplier<Map<String, String>> customHeadersSupplier) Sets a supplier for custom HTTP headers. The supplier is called before each request, allowing dynamic header values, for example OAuth2 tokens that expire and need refreshing. -
listeners
public OllamaDecisionModel.OllamaDecisionModelBuilder listeners(List<DecisionModelListener> listeners) Sets the listeners that are notified of every request, response and error. -
listeners
-
build
-