Merge pull request #295197 from abysssol/ollama-tests

nixos/ollama: add tests
This commit is contained in:
Pol Dellaiera 2024-03-12 20:28:16 +01:00 committed by GitHub
commit 734b199708
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 60 additions and 2 deletions

View file

@ -640,6 +640,7 @@ in {
nzbget = handleTest ./nzbget.nix {};
nzbhydra2 = handleTest ./nzbhydra2.nix {};
oh-my-zsh = handleTest ./oh-my-zsh.nix {};
ollama = handleTest ./ollama.nix {};
ombi = handleTest ./ombi.nix {};
openarena = handleTest ./openarena.nix {};
openldap = handleTest ./openldap.nix {};

56
nixos/tests/ollama.nix Normal file
View file

@ -0,0 +1,56 @@
import ./make-test-python.nix ({ pkgs, lib, ... }:
let
mainPort = "11434";
altPort = "11435";
curlRequest = port: request:
"curl http://127.0.0.1:${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.listenAddress = "127.0.0.1:${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)
'';
})

View file

@ -7,6 +7,7 @@
, overrideCC
, makeWrapper
, stdenv
, nixosTests
, pkgs
, cmake
@ -163,8 +164,8 @@ goBuild ((lib.optionalAttrs enableRocm {
"-X=github.com/jmorganca/ollama/server.mode=release"
];
# for now, just test that rocm and cuda build
passthru.tests = lib.optionalAttrs stdenv.isLinux {
passthru.tests = {
service = nixosTests.ollama;
rocm = pkgs.ollama.override { acceleration = "rocm"; };
cuda = pkgs.ollama.override { acceleration = "cuda"; };
};