Skip to content

Commit

Permalink
feat(index): start the ollama server in the background
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Feb 21, 2025
1 parent b24cb04 commit d320a63
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ jobs:
- name: Run action
uses: ./

- name: Start Ollama
run: ollama serve &

- name: Get version
run: ollama --version

Expand All @@ -62,10 +59,6 @@ jobs:
version: ${{ matrix.version }}
name: ollama-cli

- name: Start Ollama
shell: bash
run: ollama-cli serve &

- name: Locate binary
run: command -v ollama-cli

Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ jobs:
- name: Setup Ollama
uses: ai-action/setup-ollama@v1

- name: Start Ollama
run: ollama serve &

- name: Run LLM
run: ollama run llama3.2 'Explain the basics of machine learning.'
```
Expand All @@ -31,13 +28,13 @@ jobs:

## Usage

Install Ollama CLI:
Set up Ollama CLI and start server:

```yaml
- uses: ai-action/setup-ollama@v1
```

See [action.yml](action.yml)
See [action.yml](action.yml).

## Inputs

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as tc from '@actions/tool-cache';
import { type ChildProcess, spawn } from 'child_process';
import os from 'os';

import { run } from '.';

jest.mock('@actions/core');
jest.mock('@actions/exec');
jest.mock('@actions/tool-cache');
jest.mock('child_process');
jest.mock('os');

const mockedCore = jest.mocked(core);
const mockedExec = jest.mocked(exec);
const mockedTc = jest.mocked(tc);
const mockedOs = jest.mocked(os);
const mockedSpawn = jest.mocked(spawn);
const mockedTc = jest.mocked(tc);

beforeEach(() => {
jest.resetAllMocks();
Expand Down Expand Up @@ -48,6 +51,8 @@ describe.each(['darwin', 'win32', 'linux'])('when OS is %p', (os) => {
mockedTc.downloadTool.mockResolvedValueOnce(pathToTarball);
const extract = os === 'win32' ? mockedTc.extractZip : mockedTc.extractTar;
extract.mockResolvedValueOnce(pathToCLI);
const unref = jest.fn();
mockedSpawn.mockReturnValueOnce({ unref } as unknown as ChildProcess);

await run();

Expand All @@ -70,6 +75,12 @@ describe.each(['darwin', 'win32', 'linux'])('when OS is %p', (os) => {
);

expect(mockedCore.addPath).toHaveBeenCalledWith(binPath);

expect(mockedSpawn).toHaveBeenCalledWith(cliName, ['serve'], {
detached: true,
stdio: 'ignore',
});
expect(unref).toHaveBeenCalledTimes(1);
});
});

Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
extractZip,
find,
} from '@actions/tool-cache';
import { spawn } from 'child_process';
import path from 'path';

import { getBinaryPath, getDownloadObject } from './utils';
Expand Down Expand Up @@ -50,6 +51,13 @@ export async function run() {
// Expose the tool by adding it to the PATH
addPath(path.dirname(binaryPath));

// Start the Ollama server in the background
const subprocess = spawn(cliName, ['serve'], {
detached: true,
stdio: 'ignore',
});
subprocess.unref();

// Cache the tool
if (!isCached) {
await cacheFile(binaryPath, cliName, toolName, cliVersion);
Expand Down

0 comments on commit d320a63

Please sign in to comment.