1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5
6 # build-system
7 pybind11,
8 setuptools,
9
10 # dependencies
11 diskcache,
12 guidance-stitch,
13 llguidance,
14 numpy,
15 ordered-set,
16 platformdirs,
17 psutil,
18 pydantic,
19 referencing,
20 requests,
21 tiktoken,
22
23 # optional-dependencies
24 openai,
25 jsonschema,
26 fastapi,
27 uvicorn,
28
29 # tests
30 huggingface-hub,
31 pytestCheckHook,
32 tokenizers,
33 torch,
34 writableTmpDirAsHomeHook,
35}:
36
37buildPythonPackage rec {
38 pname = "guidance";
39 version = "0.2.5";
40 pyproject = true;
41
42 src = fetchFromGitHub {
43 owner = "guidance-ai";
44 repo = "guidance";
45 tag = version;
46 hash = "sha256-dTMJOBGirEumbpTanCVZQJATfLxqxmpUCqE7pah97Zw=";
47 };
48
49 build-system = [
50 pybind11
51 setuptools
52 ];
53
54 pythonRelaxDeps = [
55 "llguidance"
56 ];
57
58 dependencies = [
59 diskcache
60 guidance-stitch
61 llguidance
62 numpy
63 ordered-set
64 platformdirs
65 psutil
66 pydantic
67 referencing
68 requests
69 tiktoken
70 ];
71
72 optional-dependencies = {
73 azureai = [ openai ];
74 openai = [ openai ];
75 schemas = [ jsonschema ];
76 server = [
77 fastapi
78 uvicorn
79 ];
80 };
81
82 nativeCheckInputs = [
83 huggingface-hub
84 pytestCheckHook
85 tokenizers
86 torch
87 writableTmpDirAsHomeHook
88 ]
89 ++ optional-dependencies.schemas;
90
91 enabledTestPaths = [ "tests/unit" ];
92
93 disabledTests = [
94 # require network access
95 "test_ll_backtrack_stop"
96 "test_ll_dolphin"
97 "test_ll_fighter"
98 "test_ll_max_tokens"
99 "test_ll_nice_man"
100 "test_ll_nullable_bug"
101 "test_ll_nullable_lexeme"
102 "test_ll_pop_tokens"
103 "test_ll_stop_quote_comma"
104 "test_llparser"
105 "test_str_method_smoke"
106
107 # flaky tests
108 "test_remote_mock_gen" # frequently fails when building packages in parallel
109 ];
110
111 preCheck = ''
112 rm tests/conftest.py
113 '';
114
115 pythonImportsCheck = [ "guidance" ];
116
117 __darwinAllowLocalNetworking = true;
118
119 meta = {
120 description = "Guidance language for controlling large language models";
121 homepage = "https://github.com/guidance-ai/guidance";
122 changelog = "https://github.com/guidance-ai/guidance/releases/tag/${src.tag}";
123 license = lib.licenses.mit;
124 maintainers = with lib.maintainers; [ natsukium ];
125 };
126}