From 190193c61939daf0fab2f11e7ab4e79261f5193a Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Thu, 20 Feb 2025 11:18:23 +0100 Subject: [PATCH] python312Packages.llguidance: init at 0.6.27 --- .../python-modules/llguidance/default.nix | 101 ++++++++++++++++++ pkgs/top-level/python-packages.nix | 2 + 2 files changed, 103 insertions(+) create mode 100644 pkgs/development/python-modules/llguidance/default.nix diff --git a/pkgs/development/python-modules/llguidance/default.nix b/pkgs/development/python-modules/llguidance/default.nix new file mode 100644 index 000000000000..4639c08ed983 --- /dev/null +++ b/pkgs/development/python-modules/llguidance/default.nix @@ -0,0 +1,101 @@ +{ + lib, + stdenv, + buildPythonPackage, + fetchFromGitHub, + + # build-system + cargo, + pkg-config, + rustPlatform, + rustc, + + # buildInputs + oniguruma, + openssl, + + # tests + pytestCheckHook, + torch, + transformers, + pythonOlder, +}: + +buildPythonPackage rec { + pname = "llguidance"; + version = "0.6.27"; + pyproject = true; + + src = fetchFromGitHub { + owner = "guidance-ai"; + repo = "llguidance"; + tag = "v${version}"; + hash = "sha256-7XtGKqkAk6ZvWPSswLe07FaB/RYKZEi+3Lp+GBIP0OI="; + }; + + cargoDeps = rustPlatform.fetchCargoVendor { + inherit src; + hash = "sha256-WbPTnB1Mv9HYOrMnDhayO2V4zkuwVH/C17MdkFy57Rc="; + }; + + build-system = [ + cargo + pkg-config + rustPlatform.cargoSetupHook + rustPlatform.maturinBuildHook + rustc + ]; + + buildInputs = [ + oniguruma + openssl + ]; + + env = { + RUSTONIG_SYSTEM_LIBONIG = true; + }; + + pythonImportsCheck = [ + "llguidance" + "llguidance._lib" + ]; + + nativeCheckInputs = [ + pytestCheckHook + torch + transformers + ]; + + # Prevent python from loading the package from $src instead of the $out + preCheck = '' + rm -r python/llguidance + ''; + + disabledTests = + [ + # Require internet access (https://huggingface.co) + "test_grammar" + "test_par_grammar" + "test_par_errors" + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + # torch._inductor.exc.CppCompileError: C++ compile error + # OpenMP support not found. + "test_mask_data_torch" + ]; + + disabledTestPaths = [ + # Require internet access (https://huggingface.co) + "scripts/tokenizer_test.py" + ]; + + # As dynamo is not supported on Python 3.13+, no successfull tests remain. + doCheck = pythonOlder "3.13"; + + meta = { + description = "Super-fast Structured Outputs"; + homepage = "https://github.com/guidance-ai/llguidance"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ GaetanLepage ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 044b6e500932..125ba193228c 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -7711,6 +7711,8 @@ self: super: with self; { inherit (pkgs) fuse; }; + llguidance = callPackage ../development/python-modules/llguidance { }; + llm = callPackage ../development/python-modules/llm { }; llm-anthropic = callPackage ../development/python-modules/llm-anthropic { };