2023-04-12 12:48:02 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, buildPythonPackage
|
|
|
|
, fetchPypi
|
|
|
|
, pythonOlder
|
|
|
|
, rustPlatform
|
2023-05-24 13:37:59 +00:00
|
|
|
, cargo
|
|
|
|
, rustc
|
2023-11-16 04:20:00 +00:00
|
|
|
, setuptools
|
2023-04-12 12:48:02 +00:00
|
|
|
, setuptools-rust
|
2023-11-16 04:20:00 +00:00
|
|
|
, wheel
|
2023-04-12 12:48:02 +00:00
|
|
|
, libiconv
|
|
|
|
, requests
|
|
|
|
, regex
|
|
|
|
, blobfile
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
pname = "tiktoken";
|
2023-11-16 04:20:00 +00:00
|
|
|
version = "0.5.1";
|
2023-04-12 12:48:02 +00:00
|
|
|
src = fetchPypi {
|
|
|
|
inherit pname version;
|
2023-11-16 04:20:00 +00:00
|
|
|
hash = "sha256-J+dzVkIyAE9PgQ/R+FI2Zz7DpW7X8SBvye2GcOvtuXo=";
|
2023-04-12 12:48:02 +00:00
|
|
|
};
|
|
|
|
postPatch = ''
|
|
|
|
cp ${./Cargo.lock} Cargo.lock
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
buildPythonPackage {
|
|
|
|
inherit pname version src postPatch;
|
2023-11-16 04:20:00 +00:00
|
|
|
format = "pyproject";
|
2023-04-12 12:48:02 +00:00
|
|
|
|
|
|
|
disabled = pythonOlder "3.8";
|
|
|
|
|
|
|
|
nativeBuildInput = [
|
2023-11-16 04:20:00 +00:00
|
|
|
setuptools
|
2023-04-12 12:48:02 +00:00
|
|
|
setuptools-rust
|
2023-11-16 04:20:00 +00:00
|
|
|
wheel
|
2023-04-12 12:48:02 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
cargoDeps = rustPlatform.fetchCargoTarball {
|
|
|
|
inherit src postPatch;
|
|
|
|
name = "${pname}-${version}";
|
2023-11-16 04:20:00 +00:00
|
|
|
hash = "sha256-Q7XO+auj4tKDAGbqNn9pmJg8EJvooN2ie0lWwZVrld4=";
|
2023-04-12 12:48:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
rustPlatform.cargoSetupHook
|
|
|
|
setuptools-rust
|
2023-05-24 13:37:59 +00:00
|
|
|
cargo
|
|
|
|
rustc
|
|
|
|
];
|
2023-04-12 12:48:02 +00:00
|
|
|
|
|
|
|
buildInputs = lib.optionals stdenv.isDarwin [ libiconv ];
|
|
|
|
|
|
|
|
propagatedBuildInputs = [
|
|
|
|
requests
|
|
|
|
regex
|
|
|
|
blobfile
|
|
|
|
];
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
# almost all tests require network access
|
|
|
|
doCheck = false;
|
|
|
|
|
|
|
|
pythonImportsCheck = [
|
|
|
|
"tiktoken"
|
|
|
|
];
|
|
|
|
|
2023-04-12 12:48:02 +00:00
|
|
|
meta = with lib; {
|
|
|
|
description = "tiktoken is a fast BPE tokeniser for use with OpenAI's models.";
|
|
|
|
homepage = "https://github.com/openai/tiktoken";
|
|
|
|
license = licenses.mit;
|
|
|
|
maintainers = with maintainers; [ happysalada ];
|
|
|
|
};
|
|
|
|
}
|