Skip to content

Commit 3bcb124

Browse files
Ollama
1 parent a94467b commit 3bcb124

File tree

2 files changed

+17
-41
lines changed

2 files changed

+17
-41
lines changed

docs/modules/ollama.md

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,17 @@
11
# Ollama
22

3-
Testcontainers module for [Ollama](https://hub.docker.com/r/ollama/ollama) .
3+
## Install
44

5-
## Ollama usage examples
6-
7-
You can start an Ollama container instance from any NodeJS application by using:
8-
9-
<!--codeinclude-->
10-
[Ollama container](../../packages/modules/ollama/src/ollama-container.test.ts) inside_block:container
11-
<!--/codeinclude-->
12-
13-
### Pulling the model
14-
15-
<!--codeinclude-->
16-
[Pull model](../../packages/modules/ollama/src/ollama-container.test.ts) inside_block:pullModel
17-
<!--/codeinclude-->
18-
19-
### Create a new Image
5+
```bash
6+
npm install @testcontainers/ollama --save-dev
7+
```
208

21-
In order to create a new image that contains the model, you can use the following code:
9+
## Examples
2210

23-
<!--codeinclude-->
24-
[Commit Image](../../packages/modules/ollama/src/ollama-container.test.ts) inside_block:commitToImage
25-
<!--/codeinclude-->
11+
Choose an image from the [container registry](https://hub.docker.com/r/ollama/ollama) and substitute `IMAGE`.
2612

27-
And use the new image:
13+
### Pull and commit an image
2814

2915
<!--codeinclude-->
30-
[Use new Image](../../packages/modules/ollama/src/ollama-container.test.ts) inside_block:substitute
16+
[](../../packages/modules/ollama/src/ollama-container.test.ts) inside_block:ollamaPullModel
3117
<!--/codeinclude-->
32-
33-
## Adding this module to your project
34-
35-
```bash
36-
npm install @testcontainers/ollama --save-dev
37-
```
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ImageName } from "testcontainers";
1+
import { ImageName, randomUuid } from "testcontainers";
22
import { getImage } from "../../../testcontainers/src/utils/test-helper";
33
import { OllamaContainer } from "./ollama-container";
44

@@ -16,27 +16,23 @@ describe("OllamaContainer", { timeout: 180_000 }, () => {
1616
});
1717

1818
it.skip("download model and commit to image", async () => {
19+
// ollamaPullModel {
1920
await using container = await new OllamaContainer(IMAGE).start();
20-
// pullModel {
21-
const execResult = await container.exec(["ollama", "pull", "all-minilm"]);
22-
// }
23-
console.log(execResult.output);
21+
await container.exec(["ollama", "pull", "all-minilm"]);
22+
2423
const response = await fetch(`${container.getEndpoint()}/api/tags`);
2524
expect(response.status).toEqual(200);
2625
const body = (await response.json()) as { models: { name: string }[] };
2726
expect(body.models[0].name).toContain("all-minilm");
2827

29-
const newImageName: string = "tc-ollama-allminilm-" + (Math.random() + 1).toString(36).substring(4).toLowerCase();
30-
// commitToImage {
28+
const newImageName = "tc-ollama-allminilm-" + randomUuid().substring(4);
3129
await container.commitToImage(newImageName);
32-
// }
3330

34-
// substitute {
3531
await using newContainer = await new OllamaContainer(newImageName).start();
32+
const newResponse = await fetch(`${newContainer.getEndpoint()}/api/tags`);
33+
expect(newResponse.status).toEqual(200);
34+
const newBody = (await newResponse.json()) as { models: { name: string }[] };
35+
expect(newBody.models[0].name).toContain("all-minilm");
3636
// }
37-
const response2 = await fetch(`${newContainer.getEndpoint()}/api/tags`);
38-
expect(response2.status).toEqual(200);
39-
const body2 = (await response2.json()) as { models: { name: string }[] };
40-
expect(body2.models[0].name).toContain("all-minilm");
4137
});
4238
});

0 commit comments

Comments
 (0)