1{ 2 lib, 3 buildPythonPackage, 4 fetchFromGitHub, 5 6 # nativeBuildInputs 7 cargo, 8 pkg-config, 9 rustPlatform, 10 rustc, 11 12 # buildInputs 13 openssl, 14 15 # build-system 16 setuptools-rust, 17 setuptools-scm, 18 19 # dependencies 20 interegular, 21 jsonschema, 22 23 # optional-dependencies 24 datasets, 25 numpy, 26 pydantic, 27 scipy, 28 torch, 29 transformers, 30 31 # tests 32 pytestCheckHook, 33}: 34 35buildPythonPackage rec { 36 pname = "outlines-core"; 37 version = "0.2.11"; 38 39 pyproject = true; 40 41 src = fetchFromGitHub { 42 owner = "dottxt-ai"; 43 repo = "outlines-core"; 44 tag = version; 45 hash = "sha256-lLMTHFytJT2MhnzT0RlRCaSBPijA81fjxUqx4IGfVo8="; 46 }; 47 48 cargoDeps = rustPlatform.importCargoLock { 49 lockFile = ./Cargo.lock; 50 }; 51 52 postPatch = '' 53 substituteInPlace Cargo.toml \ 54 --replace-fail \ 55 'version = "0.0.0"' \ 56 'version = "${version}"' 57 58 cp --no-preserve=mode ${./Cargo.lock} Cargo.lock 59 ''; 60 61 nativeBuildInputs = [ 62 cargo 63 pkg-config 64 rustPlatform.cargoSetupHook 65 rustPlatform.maturinBuildHook 66 rustc 67 ]; 68 69 buildInputs = [ 70 openssl.dev 71 ]; 72 73 build-system = [ 74 setuptools-rust 75 setuptools-scm 76 ]; 77 78 dependencies = [ 79 interegular 80 jsonschema 81 ]; 82 83 optional-dependencies = { 84 tests = [ 85 datasets 86 numpy 87 pydantic 88 scipy 89 torch 90 transformers 91 ]; 92 }; 93 94 pythonImportsCheck = [ "outlines_core" ]; 95 96 preCheck = '' 97 rm -rf outlines_core 98 ''; 99 100 nativeCheckInputs = [ pytestCheckHook ] ++ lib.flatten (lib.attrValues optional-dependencies); 101 102 disabledTests = [ 103 # Tests that need to download from Hugging Face Hub. 104 "test_complex_serialization" 105 "test_create_fsm_index_tokenizer" 106 "test_from_pretrained" 107 "test_pickling_from_pretrained_with_revision" 108 "test_reduced_vocabulary_with_rare_tokens" 109 ]; 110 111 disabledTestPaths = [ 112 # Downloads from Hugging Face Hub 113 "tests/test_kernels.py" 114 ]; 115 116 meta = { 117 description = "Structured text generation (core)"; 118 homepage = "https://github.com/outlines-dev/outlines-core"; 119 changelog = "https://github.com/dottxt-ai/outlines-core/releases/tag/${version}"; 120 license = lib.licenses.asl20; 121 maintainers = with lib.maintainers; [ danieldk ]; 122 }; 123}