Unverified Commit a2239dff authored by Sandro Jäckel's avatar Sandro Jäckel Committed by GitHub
Browse files

python312Packages.guidance: fix (#383617)

parents b7d506d7 ef250b63
Loading
Loading
Loading
Loading
+59 −0
Original line number Diff line number Diff line
{
  lib,
  buildPythonPackage,
  fetchPypi,

  # build-system
  hatch-jupyter-builder,
  hatch-nodejs-version,
  hatchling,
  jupyterlab,

  # dependencies
  ipywidgets,

  # tests
  nbval,
  pytest-cov-stub,
  pytestCheckHook,
}:

buildPythonPackage rec {
  pname = "guidance-stitch";
  version = "0.1.4";
  pyproject = true;

  src = fetchPypi {
    pname = "guidance_stitch";
    inherit version;
    hash = "sha256-Wthz02C2AU6hzQ+TTGs+sI73ejwHQRCStZXZts0i1+w=";
  };

  build-system = [
    hatch-jupyter-builder
    hatch-nodejs-version
    hatchling
    jupyterlab
  ];

  dependencies = [
    ipywidgets
  ];

  pythonImportsCheck = [ "stitch" ];

  nativeCheckInputs = [
    nbval
    pytest-cov-stub
    pytestCheckHook
  ];

  __darwinAllowLocalNetworking = true;

  meta = {
    description = "Guidance language for controlling large language models";
    homepage = "https://github.com/guidance-ai/guidance/tree/main/packages/python/stitch";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ GaetanLepage ];
  };
}
+49 −17
Original line number Diff line number Diff line
@@ -2,23 +2,36 @@
  lib,
  buildPythonPackage,
  fetchFromGitHub,
  pytestCheckHook,

  # build-system
  pybind11,
  setuptools,

  # dependencies
  diskcache,
  fastapi,
  huggingface-hub,
  jsonschema,
  guidance-stitch,
  llguidance,
  numpy,
  openai,
  ordered-set,
  platformdirs,
  protobuf,
  psutil,
  pydantic,
  referencing,
  requests,
  tiktoken,
  torch,

  # optional-dependencies
  openai,
  jsonschema,
  fastapi,
  uvicorn,

  # tests
  huggingface-hub,
  pytestCheckHook,
  tokenizers,
  torch,
  writableTmpDirAsHomeHook,
}:

buildPythonPackage rec {
@@ -38,13 +51,20 @@ buildPythonPackage rec {
    setuptools
  ];

  pythonRelaxDeps = [
    "llguidance"
  ];

  dependencies = [
    diskcache
    guidance-stitch
    llguidance
    numpy
    ordered-set
    platformdirs
    protobuf
    psutil
    pydantic
    referencing
    requests
    tiktoken
  ];
@@ -62,27 +82,40 @@ buildPythonPackage rec {
  nativeCheckInputs = [
    huggingface-hub
    pytestCheckHook
    tokenizers
    torch
    writableTmpDirAsHomeHook
  ] ++ optional-dependencies.schemas;

  pytestFlagsArray = [ "tests/unit" ];

  disabledTests = [
    # require network access
    "test_select_simple"
    "test_commit_point"
    "test_token_healing"
    "test_fstring"
    "test_fstring_custom"
    "test_token_count"
    "test_gpt2"
    "test_recursion_error"
    "test_openai_class_detection"
    "test_openai_chat_without_roles"
    "test_image_from_bytes"
    "test_ll_backtrack_stop"
    "test_ll_dolphin"
    "test_ll_fighter"
    "test_ll_max_tokens"
    "test_ll_nice_man"
    "test_ll_nullable_bug"
    "test_ll_nullable_lexeme"
    "test_ll_pop_tokens"
    "test_ll_stop_quote_comma"
    "test_llparser"
    "test_local_image"
    "test_openai_chat_without_roles"
    "test_openai_class_detection"
    "test_recursion_error"
    "test_remote_image"
    "test_image_from_bytes"
    "test_remote_image_not_found"
    "test_select_simple"
    "test_str_method_smoke"
    "test_token_count"
    "test_token_healing"

    # flaky tests
    "test_remote_mock_gen" # frequently fails when building packages in parallel
@@ -94,7 +127,6 @@ buildPythonPackage rec {
  ];

  preCheck = ''
    export HOME=$TMPDIR
    rm tests/conftest.py
  '';

@@ -105,7 +137,7 @@ buildPythonPackage rec {
  meta = {
    description = "Guidance language for controlling large language models";
    homepage = "https://github.com/guidance-ai/guidance";
    changelog = "https://github.com/guidance-ai/guidance/releases/tag/${src.tag}";
    changelog = "https://github.com/guidance-ai/guidance/releases/tag/v${version}";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ natsukium ];
  };
+101 −0
Original line number Diff line number Diff line
{
  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 ];
  };
}
+4 −0
Original line number Diff line number Diff line
@@ -5772,6 +5772,8 @@ self: super: with self; {
  guidance = callPackage ../development/python-modules/guidance { };
  guidance-stitch = callPackage ../development/python-modules/guidance-stitch { };
  guidata = callPackage ../development/python-modules/guidata { };
  gumath = callPackage ../development/python-modules/gumath { };
@@ -7709,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 { };