Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Ollama docs #8417

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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