Ollama
Testcontainers module for Ollama .
Ollama's usage examples
You can start an Ollama container instance from any Java application by using:
OllamaContainer ollama = new OllamaContainer("ollama/ollama:0.1.26")
Pulling the model
Testcontainers allows executing commands in the container. So, pulling the model is as simple as:
ollama.execInContainer("ollama", "pull", "all-minilm");
Create a new Image
In order to create a new image that contains the model, you can use the following code:
ollama.commitToImage(newImageName);
And use the new image along with Image name Substitution
OllamaContainer ollama = new OllamaContainer(
DockerImageName.parse(newImageName)
.asCompatibleSubstituteFor("ollama/ollama")
)
Adding this module to your project dependencies
Add the following dependency to your pom.xml
/build.gradle
file:
testImplementation "org.testcontainers:ollama:1.20.4"
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>ollama</artifactId>
<version>1.20.4</version>
<scope>test</scope>
</dependency>