Class OllamaContainerProvider
- All Implemented Interfaces:
io.flowinquiry.testcontainers.LifecycleAware
This class manages the lifecycle of Ollama containers in a Spring environment, including container creation, configuration, and integration with Spring's property system. It handles pulling the specified AI model during container startup and configuring Spring AI properties to connect to the containerized Ollama instance.
The provider uses the EnableOllamaContainer annotation to configure the container with
specific parameters such as the Docker image, version, model name, and model options (temperature
and top-p values).
-
Field Summary
Fields inherited from class io.flowinquiry.testcontainers.SpringAwareContainerProvider
container, dockerImage, enableContainerAnnotation, version -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyTo(org.springframework.core.env.ConfigurableEnvironment environment) Applies Ollama-specific configuration to the Spring environment.protected org.testcontainers.ollama.OllamaContainerCreates and configures an Ollama container instance.io.flowinquiry.testcontainers.ContainerTypeReturns the type of container managed by this provider.voidstart()Starts the Ollama container and pulls the specified AI model.Methods inherited from class io.flowinquiry.testcontainers.SpringAwareContainerProvider
initContainerInstance, stop
-
Constructor Details
-
OllamaContainerProvider
public OllamaContainerProvider()
-
-
Method Details
-
getContainerType
public io.flowinquiry.testcontainers.ContainerType getContainerType()Returns the type of container managed by this provider.- Specified by:
getContainerTypein classio.flowinquiry.testcontainers.SpringAwareContainerProvider<io.flowinquiry.testcontainers.ai.EnableOllamaContainer,org.testcontainers.ollama.OllamaContainer> - Returns:
- the OLLAMA container type
-
createContainer
protected org.testcontainers.ollama.OllamaContainer createContainer()Creates and configures an Ollama container instance.- Specified by:
createContainerin classio.flowinquiry.testcontainers.SpringAwareContainerProvider<io.flowinquiry.testcontainers.ai.EnableOllamaContainer,org.testcontainers.ollama.OllamaContainer> - Returns:
- a new OllamaContainer instance configured with the specified Docker image and version
-
start
public void start()Starts the Ollama container and pulls the specified AI model.This method first calls the parent class's start method to start the container, then executes the 'ollama pull' command inside the container to download the specified AI model.
- Specified by:
startin interfaceio.flowinquiry.testcontainers.LifecycleAware- Overrides:
startin classio.flowinquiry.testcontainers.SpringAwareContainerProvider<io.flowinquiry.testcontainers.ai.EnableOllamaContainer,org.testcontainers.ollama.OllamaContainer> - Throws:
RuntimeException- if there is an error pulling the model
-
applyTo
public void applyTo(org.springframework.core.env.ConfigurableEnvironment environment) Applies Ollama-specific configuration to the Spring environment.These properties are added to the Spring environment with high precedence to ensure they override any existing configuration.
- Specified by:
applyToin classio.flowinquiry.testcontainers.SpringAwareContainerProvider<io.flowinquiry.testcontainers.ai.EnableOllamaContainer,org.testcontainers.ollama.OllamaContainer> - Parameters:
environment- the Spring environment to configure
-