From 184680507f420922a2b18b86f5a07efeba7c589f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez=20Gonzales?= Date: Mon, 4 Mar 2024 16:52:42 -0500 Subject: [PATCH] Improve Ollama docs (#8417) --- docs/modules/ollama.md | 22 +++++++++++++++++++ .../ollama/OllamaContainerTest.java | 6 +++++ 2 files changed, 28 insertions(+) diff --git a/docs/modules/ollama.md b/docs/modules/ollama.md index 97e8865bdc1..98d9c204966 100644 --- a/docs/modules/ollama.md +++ b/docs/modules/ollama.md @@ -10,6 +10,28 @@ You can start an Ollama container instance from any Java application by using: [Ollama container](../../modules/ollama/src/test/java/org/testcontainers/ollama/OllamaContainerTest.java) inside_block:container +### Pulling the model + +Testcontainers allows [executing commands in the container](../features/commands.md). So, pulling the model is as simple as: + + +[Pull model](../../modules/ollama/src/test/java/org/testcontainers/ollama/OllamaContainerTest.java) inside_block:pullModel + + +### Create a new Image + +In order to create a new image that contains the model, you can use the following code: + + +[Commit Image](../../modules/ollama/src/test/java/org/testcontainers/ollama/OllamaContainerTest.java) inside_block:commitToImage + + +And use the new image along with [Image name Substitution](../features/image_name_substitution.md#manual-substitution) + + +[Use new Image](../../modules/ollama/src/test/java/org/testcontainers/ollama/OllamaContainerTest.java) inside_block:containerSubstitute + + ## Adding this module to your project dependencies Add the following dependency to your `pom.xml`/`build.gradle` file: diff --git a/modules/ollama/src/test/java/org/testcontainers/ollama/OllamaContainerTest.java b/modules/ollama/src/test/java/org/testcontainers/ollama/OllamaContainerTest.java index d33660b40b0..cefd665b044 100644 --- a/modules/ollama/src/test/java/org/testcontainers/ollama/OllamaContainerTest.java +++ b/modules/ollama/src/test/java/org/testcontainers/ollama/OllamaContainerTest.java @@ -29,7 +29,9 @@ public void downloadModelAndCommitToImage() throws IOException, InterruptedExcep String newImageName = "tc-ollama-allminilm-" + Base58.randomString(4).toLowerCase(); try (OllamaContainer ollama = new OllamaContainer("ollama/ollama:0.1.26")) { ollama.start(); + // pullModel { ollama.execInContainer("ollama", "pull", "all-minilm"); + // } String modelName = given() .baseUri(ollama.getEndpoint()) @@ -37,12 +39,16 @@ public void downloadModelAndCommitToImage() throws IOException, InterruptedExcep .jsonPath() .getString("models[0].name"); assertThat(modelName).contains("all-minilm"); + // commitToImage { ollama.commitToImage(newImageName); + // } } try ( + // containerSubstitute { OllamaContainer ollama = new OllamaContainer( DockerImageName.parse(newImageName).asCompatibleSubstituteFor("ollama/ollama") ) + // } ) { ollama.start(); String modelName = given()