Skip to content

Commit

Permalink
Added Ollama module docs (#784)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilopezluna authored Jun 30, 2024
1 parent 0f26b4a commit 4059231
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
37 changes: 37 additions & 0 deletions docs/modules/ollama.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Ollama

Testcontainers module for [Ollama](https://hub.docker.com/r/ollama/ollama) .

## Ollama usage examples

You can start an Ollama container instance from any NodeJS application by using:

<!--codeinclude-->
[Ollama container](../../packages/modules/ollama/src/ollama-container.test.ts) inside_block:container
<!--/codeinclude-->

### Pulling the model

<!--codeinclude-->
[Pull model](../../packages/modules/ollama/src/ollama-container.test.ts) 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](../../packages/modules/ollama/src/ollama-container.test.ts) inside_block:commitToImage
<!--/codeinclude-->

And use the new image:

<!--codeinclude-->
[Use new Image](../../packages/modules/ollama/src/ollama-container.test.ts) inside_block:substitute
<!--/codeinclude-->

## Adding this module to your project

```bash
npm install @testcontainers/ollama --save-dev
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ nav:
- MySQL: modules/mysql.md
- Nats: modules/nats.md
- Neo4J: modules/neo4j.md
- Ollama: modules/ollama.md
- PostgreSQL: modules/postgresql.md
- Qdrant: modules/qdrant.md
- RabbitMQ: modules/rabbitmq.md
Expand Down
8 changes: 8 additions & 0 deletions packages/modules/ollama/src/ollama-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ describe("OllamaContainer", () => {
jest.setTimeout(180_000);

it("should run ollama with default config", async () => {
// container {
const container = await new OllamaContainer("ollama/ollama:0.1.44").start();
// }
const response = await fetch(`${container.getEndpoint()}/api/version`);
expect(response.status).toEqual(200);
const body = await response.json();
Expand All @@ -14,17 +16,23 @@ describe("OllamaContainer", () => {

it("download model and commit to image", async () => {
const container = await new OllamaContainer("ollama/ollama:0.1.44").start();
// pullModel {
const execResult = await container.exec(["ollama", "pull", "all-minilm"]);
// }
console.log(execResult.output);
const response = await fetch(`${container.getEndpoint()}/api/tags`);
expect(response.status).toEqual(200);
const body = await response.json();
expect(body.models[0].name).toContain("all-minilm");

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

// substitute {
const newContainer = await new OllamaContainer(newImageName).start();
// }
const response2 = await fetch(`${newContainer.getEndpoint()}/api/tags`);
expect(response2.status).toEqual(200);
const body2 = await response2.json();
Expand Down

0 comments on commit 4059231

Please sign in to comment.