about summary refs log tree commit diff
path: root/nixos/tests/ollama.nix
blob: 30e475553eb1a762aca48f84522d71924609574f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import ./make-test-python.nix ({ pkgs, lib, ... }:
let
  mainPort = 11434;
  altPort = 11435;

  curlRequest = port: request:
    "curl http://127.0.0.1:${toString port}/api/generate -d '${builtins.toJSON request}'";

  prompt = {
    model = "tinydolphin";
    prompt = "lorem ipsum";
    options = {
      seed = 69;
      temperature = 0;
    };
  };
in
{
  name = "ollama";
  meta = with lib.maintainers; {
    maintainers = [ abysssol ];
  };

  nodes = {
    cpu = { ... }: {
      services.ollama.enable = true;
    };

    rocm = { ... }: {
      services.ollama.enable = true;
      services.ollama.acceleration = "rocm";
    };

    cuda = { ... }: {
      services.ollama.enable = true;
      services.ollama.acceleration = "cuda";
    };

    altAddress = { ... }: {
      services.ollama.enable = true;
      services.ollama.port = altPort;
    };
  };

  testScript = ''
    vms = [ cpu, rocm, cuda, altAddress ];

    start_all()
    for vm in vms:
        vm.wait_for_unit("multi-user.target")

    stdout = cpu.succeed("""${curlRequest mainPort prompt}""", timeout=100)

    stdout = altAddress.succeed("""${curlRequest altPort prompt}""", timeout=100)
  '';
})