Skip to content

Commit

Permalink
Improve Ollama docs (#8417)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddumelendez authored Mar 4, 2024
1 parent 198b7fa commit 1846805
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/modules/ollama.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<!--/codeinclude-->

### Pulling the model

Testcontainers allows [executing commands in the container](../features/commands.md). So, pulling the model is as simple as:

<!--codeinclude-->
[Pull model](../../modules/ollama/src/test/java/org/testcontainers/ollama/OllamaContainerTest.java) inside_block:pullModel
<!--/codeinclude-->

### Create a new Image

In order to create a new image that contains the model, you can use the following code:

<!--codeinclude-->
[Commit Image](../../modules/ollama/src/test/java/org/testcontainers/ollama/OllamaContainerTest.java) inside_block:commitToImage
<!--/codeinclude-->

And use the new image along with [Image name Substitution](../features/image_name_substitution.md#manual-substitution)

<!--codeinclude-->
[Use new Image](../../modules/ollama/src/test/java/org/testcontainers/ollama/OllamaContainerTest.java) inside_block:containerSubstitute
<!--/codeinclude-->

## Adding this module to your project dependencies

Add the following dependency to your `pom.xml`/`build.gradle` file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,26 @@ 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())
.get("/api/tags")
.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()
Expand Down

0 comments on commit 1846805

Please sign in to comment.