From 40592311b3909c88f9df1c3ae39ab770d0adb6a3 Mon Sep 17 00:00:00 2001 From: Ignasi Date: Sun, 30 Jun 2024 22:21:54 +0200 Subject: [PATCH] Added Ollama module docs (#784) --- docs/modules/ollama.md | 37 +++++++++++++++++++ mkdocs.yml | 1 + .../ollama/src/ollama-container.test.ts | 8 ++++ 3 files changed, 46 insertions(+) create mode 100644 docs/modules/ollama.md diff --git a/docs/modules/ollama.md b/docs/modules/ollama.md new file mode 100644 index 000000000..0921b0a75 --- /dev/null +++ b/docs/modules/ollama.md @@ -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: + + +[Ollama container](../../packages/modules/ollama/src/ollama-container.test.ts) inside_block:container + + +### Pulling the model + + +[Pull model](../../packages/modules/ollama/src/ollama-container.test.ts) inside_block:pullModel + + +### Create a new Image + +In order to create a new image that contains the model, you can use the following code: + + +[Commit Image](../../packages/modules/ollama/src/ollama-container.test.ts) inside_block:commitToImage + + +And use the new image: + + +[Use new Image](../../packages/modules/ollama/src/ollama-container.test.ts) inside_block:substitute + + +## Adding this module to your project + +```bash +npm install @testcontainers/ollama --save-dev +``` \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index a4adec7d9..c64c19f31 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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 diff --git a/packages/modules/ollama/src/ollama-container.test.ts b/packages/modules/ollama/src/ollama-container.test.ts index 3203f36bc..4e51a48d6 100644 --- a/packages/modules/ollama/src/ollama-container.test.ts +++ b/packages/modules/ollama/src/ollama-container.test.ts @@ -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(); @@ -14,7 +16,9 @@ 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); @@ -22,9 +26,13 @@ describe("OllamaContainer", () => { 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();