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