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

Added Ollama module docs #784

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