at master 2.1 kB view raw
1{ 2 lib, 3 stdenv, 4 buildPythonPackage, 5 fetchFromGitHub, 6 7 # nativeBuildInputs 8 cargo, 9 pkg-config, 10 rustPlatform, 11 rustc, 12 13 # buildInputs 14 oniguruma, 15 openssl, 16 17 # tests 18 pytestCheckHook, 19 torch, 20 transformers, 21}: 22 23buildPythonPackage rec { 24 pname = "llguidance"; 25 version = "1.2.0"; 26 pyproject = true; 27 28 src = fetchFromGitHub { 29 owner = "guidance-ai"; 30 repo = "llguidance"; 31 tag = "v${version}"; 32 hash = "sha256-Fe7cKZotjRexcSHcoT0Y9I3m+dRarhlBOjYR7rdJBRY="; 33 }; 34 35 cargoDeps = rustPlatform.fetchCargoVendor { 36 inherit src pname version; 37 hash = "sha256-//Vjj4QIDcZEPujMfUhZd5nx5pAyF3l3CdNvI/Wi74A="; 38 }; 39 40 nativeBuildInputs = [ 41 cargo 42 pkg-config 43 rustPlatform.cargoSetupHook 44 rustPlatform.maturinBuildHook 45 rustc 46 ]; 47 48 buildInputs = [ 49 oniguruma 50 openssl 51 ]; 52 53 env = { 54 RUSTONIG_SYSTEM_LIBONIG = true; 55 }; 56 57 pythonImportsCheck = [ 58 "llguidance" 59 "llguidance._lib" 60 ]; 61 62 nativeCheckInputs = [ 63 pytestCheckHook 64 torch 65 transformers 66 ]; 67 68 # Prevent python from loading the package from $src instead of the $out 69 preCheck = '' 70 rm -r python/llguidance 71 ''; 72 73 disabledTests = [ 74 # Require internet access (https://huggingface.co) 75 "test_grammar" 76 "test_incomplete_tokenizer" 77 "test_par_errors" 78 "test_par_grammar" 79 "test_tokenize_partial_basic" 80 "test_tokenize_partial_docs" 81 ] 82 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 83 # torch._inductor.exc.CppCompileError: C++ compile error 84 # OpenMP support not found. 85 "test_mask_data_torch" 86 ]; 87 88 disabledTestPaths = [ 89 # Require internet access (https://huggingface.co) 90 "python/torch_tests/test_hf.py" 91 "python/torch_tests/test_llamacpp.py" 92 "python/torch_tests/test_tiktoken.py" 93 "scripts/tokenizer_test.py" 94 ]; 95 96 meta = { 97 description = "Super-fast Structured Outputs"; 98 homepage = "https://github.com/guidance-ai/llguidance"; 99 changelog = "https://github.com/guidance-ai/llguidance/blob/v${version}/CHANGELOG.md"; 100 license = lib.licenses.mit; 101 maintainers = with lib.maintainers; [ GaetanLepage ]; 102 }; 103}