From 2a492684c2f2c80ea3bcbd5f8f2560dea0cb1575 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Mon, 4 Nov 2024 12:24:08 -0600 Subject: [PATCH] add back working version of llm + llm-plugins --- hosts/othalan/default.nix | 2 +- modules/llm/default.nix | 20 ++-- pkgs/default.nix | 4 + .../llm-plugins/llm-claude-3/default.nix | 2 +- .../llm-plugins/llm-ollama/default.nix | 0 pkgs/llm/default.nix | 96 +++++++++++++++++++ 6 files changed, 110 insertions(+), 14 deletions(-) rename {modules/llm => pkgs}/llm-plugins/llm-claude-3/default.nix (96%) rename {modules/llm => pkgs}/llm-plugins/llm-ollama/default.nix (100%) create mode 100644 pkgs/llm/default.nix diff --git a/hosts/othalan/default.nix b/hosts/othalan/default.nix index 8c9a538..fb01bd0 100644 --- a/hosts/othalan/default.nix +++ b/hosts/othalan/default.nix @@ -19,7 +19,7 @@ # llm '' vpn|desktop|hyprland|chrome - backups|hp-scanner + backups|hp-scanner|llm podman|docker|vbox '' |> listify diff --git a/modules/llm/default.nix b/modules/llm/default.nix index 46d964e..16979a3 100644 --- a/modules/llm/default.nix +++ b/modules/llm/default.nix @@ -2,22 +2,18 @@ pkgs, config, mkOizysModule, - # enabled, + flake, ... }: -let - inherit (pkgs) python3Packages; - # llm-ollama = python3Packages.callPackage ./llm-plugins/llm-ollama { }; - llm-claude3 = python3Packages.callPackage ./llm-plugins/llm-claude-3 { }; -in - mkOizysModule config "llm" { - # services.ollama = enabled; environment.systemPackages = with pkgs; [ - (python3.withPackages (ps: [ - ps.llm - llm-claude3 - ])) + (python3.withPackages (ps: + with (flake.pkgs "self"); + [ + llm + llm-claude-3 + ] + )) ]; } diff --git a/pkgs/default.nix b/pkgs/default.nix index 6ef3686..cbfaa74 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,7 +1,11 @@ { pkgs, ... }: + let inherit (pkgs) python3Packages; + in { nph = pkgs.callPackage ./nim/nph { }; # doesn't compile with 2.2.0 :/ nimlangserver = pkgs.callPackage ./nim/nimlangserver { }; nimble = pkgs.callPackage ./nim/nimble { }; distrobox = pkgs.callPackage ./distrobox {}; + llm = python3Packages.callPackage ./llm {}; + llm-claude-3 = python3Packages.callPackage ./llm-plugins/llm-claude-3 {}; } diff --git a/modules/llm/llm-plugins/llm-claude-3/default.nix b/pkgs/llm-plugins/llm-claude-3/default.nix similarity index 96% rename from modules/llm/llm-plugins/llm-claude-3/default.nix rename to pkgs/llm-plugins/llm-claude-3/default.nix index 28e0804..22a908b 100644 --- a/modules/llm/llm-plugins/llm-claude-3/default.nix +++ b/pkgs/llm-plugins/llm-claude-3/default.nix @@ -13,7 +13,7 @@ buildPythonPackage rec { pname = "llm-claude-3"; - version = "0.4"; + version = "0.7"; pyproject = true; src = fetchFromGitHub { diff --git a/modules/llm/llm-plugins/llm-ollama/default.nix b/pkgs/llm-plugins/llm-ollama/default.nix similarity index 100% rename from modules/llm/llm-plugins/llm-ollama/default.nix rename to pkgs/llm-plugins/llm-ollama/default.nix diff --git a/pkgs/llm/default.nix b/pkgs/llm/default.nix new file mode 100644 index 0000000..f32a108 --- /dev/null +++ b/pkgs/llm/default.nix @@ -0,0 +1,96 @@ +{ + lib, + buildPythonPackage, + fetchFromGitHub, + pytestCheckHook, + pythonOlder, + setuptools, + click-default-group, + numpy, + openai, + pip, + pluggy, + pydantic, + python-ulid, + pyyaml, + sqlite-migrate, + cogapp, + pytest-httpx, + puremagic, + sqlite-utils, +}: +let + llm = buildPythonPackage rec { + pname = "llm"; + version = "0.17.1"; + pyproject = true; + + build-system = [ setuptools ]; + + disabled = pythonOlder "3.8"; + + src = fetchFromGitHub { + owner = "simonw"; + repo = "llm"; + rev = "refs/tags/${version}"; + hash = "sha256-6OO0SIIxChM5HRJoUM4CYGbsINmc3i+iyL/oahLHhrY="; + }; + + # patches = [ ./001-disable-install-uninstall-commands.patch ]; + + dependencies = [ + click-default-group + numpy + openai + pip + pluggy + pydantic + python-ulid + pyyaml + setuptools # for pkg_resources + sqlite-migrate + sqlite-utils + puremagic + ]; + + nativeCheckInputs = [ + cogapp + numpy + pytest-httpx + pytestCheckHook + ]; + + doCheck = true; + + pytestFlagsArray = [ + "-svv" + "tests/" + ]; + + pythonImportsCheck = [ "llm" ]; + + passthru = { + inherit withPlugins; + }; + + meta = with lib; { + homepage = "https://github.com/simonw/llm"; + description = "Access large language models from the command-line"; + changelog = "https://github.com/simonw/llm/releases/tag/${version}"; + license = licenses.asl20; + mainProgram = "llm"; + maintainers = with maintainers; [ + aldoborrero + mccartykim + ]; + }; + }; + + withPlugins = throw '' + llm.withPlugins was confusing to use and has been removed. + Please migrate to using python3.withPackages(ps: [ ps.llm ]) instead. + + See https://nixos.org/manual/nixpkgs/stable/#python.withpackages-function for more usage examples. + ''; +in +llm