1{
2 buildPythonApplication,
3 buildPythonPackage,
4 fetchFromGitHub,
5 lib,
6 makeWrapper,
7 pytestCheckHook,
8 python3,
9 pythonOlder,
10 ruff,
11 setuptools,
12}: let
13 llm = buildPythonPackage rec {
14 pname = "llm";
15 version = "0.12";
16 pyproject = true;
17
18 disabled = pythonOlder "3.8";
19
20 src = fetchFromGitHub {
21 owner = "simonw";
22 repo = pname;
23 rev = "refs/tags/${version}";
24 hash = "sha256-aCqdw2co/cXrBwVY/k/aSLl3C22nlH5LvU2yir1/NnQ=";
25 };
26
27 patches = [
28 ./001-disable-install-uninstall-commands.patch
29 ];
30
31 nativeBuildInputs = [
32 setuptools
33 ];
34
35 propagatedBuildInputs = with python3.pkgs; [
36 click-default-group
37 numpy
38 openai
39 pluggy
40 pydantic
41 python-ulid
42 pyyaml
43 setuptools # for pkg_resources
44 sqlite-migrate
45 sqlite-utils
46 ];
47
48 nativeCheckInputs = with python3.pkgs; [
49 cogapp
50 numpy
51 pytestCheckHook
52 requests-mock
53 ];
54
55 doCheck = true;
56
57 pytestFlagsArray = [
58 "-svv"
59 "tests/"
60 ];
61
62 pythonImportsCheck = [
63 "llm"
64 ];
65
66 passthru = {inherit withPlugins;};
67
68 meta = with lib; {
69 homepage = "https://github.com/simonw/llm";
70 description = "Access large language models from the command-line";
71 changelog = "https://github.com/simonw/llm/releases/tag/${version}";
72 license = licenses.asl20;
73 mainProgram = "llm";
74 maintainers = with maintainers; [aldoborrero];
75 };
76 };
77
78 withPlugins = plugins: buildPythonApplication {
79 inherit (llm) pname version;
80 format = "other";
81
82 disabled = pythonOlder "3.8";
83
84 dontUnpack = true;
85 dontBuild = true;
86 doCheck = false;
87
88 nativeBuildInputs = [
89 makeWrapper
90 ];
91
92 installPhase = ''
93 makeWrapper ${llm}/bin/llm $out/bin/llm \
94 --prefix PYTHONPATH : "${llm}/${python3.sitePackages}:$PYTHONPATH"
95 ln -sfv ${llm}/lib $out/lib
96 '';
97
98 propagatedBuildInputs = llm.propagatedBuildInputs ++ plugins;
99
100 passthru = llm.passthru // {
101 withPlugins = morePlugins: withPlugins (morePlugins ++ plugins);
102 };
103
104 inherit (llm) meta;
105 };
106in
107 llm