Java integration library enabling LangChain4j applications to use Ollama's local language models with support for chat, streaming, embeddings, and advanced reasoning features
The OllamaModels class provides utilities for managing Ollama models, including listing available models, retrieving model information, checking running models, and deleting models.
Utility class for Ollama model management operations.
package dev.langchain4j.model.ollama;
public class OllamaModelsThread Safety: Immutable after build(); safe for concurrent operations
Nullability: Instance never null after successful build()
public Response<List<OllamaModel>> availableModels()Lists all models available on the Ollama server.
Returns: Response<List<OllamaModel>> containing available models
Throws:
HttpTimeoutException - If request exceeds timeoutIOException - If network errorRuntimeException - If server errorThread Safety: Safe for concurrent calls
Example:
import java.io.IOException;
try {
Response<List<OllamaModel>> response = ollamaModels.availableModels();
List<OllamaModel> models = response.content();
for (OllamaModel model : models) {
System.out.println("Model: " + model.getName());
System.out.println(" Size: " + model.getSize() + " bytes");
}
} catch (IOException e) {
System.err.println("Failed to connect to Ollama: " + e.getMessage());
}public Response<OllamaModelCard> modelCard(String modelName)Retrieves detailed information (model card) for a model by name.
Parameters:
modelName - The name of the model (must not be null or empty)Returns: Response<OllamaModelCard> containing detailed model information
Throws:
IllegalArgumentException - If modelName is null or emptyRuntimeException - If model not foundIOException - If network errorThread Safety: Safe for concurrent calls
public void deleteModel(String ollamaModelName)Deletes a model from the Ollama server by name.
Parameters:
ollamaModelName - The name of the model to delete (must not be null or empty)Returns: void
Throws:
IllegalArgumentException - If ollamaModelName is null or emptyRuntimeException - If model not found or deletion failsIOException - If network errorThread Safety: Safe for concurrent calls
Warning: Deletion is permanent; cannot be undone
public Response<List<RunningOllamaModel>> runningModels()Lists all currently running models on the Ollama server.
Returns: Response<List<RunningOllamaModel>> containing running model instances
Throws:
IOException - If network errorRuntimeException - If server errorThread Safety: Safe for concurrent calls
OllamaModel, OllamaModelCard, RunningOllamaModelInstall with Tessl CLI
npx tessl i tessl/maven-dev-langchain4j--langchain4j-ollama