Skip to main content

Bindings for the Low-level Guidance (llguidance) Rust library for use within Guidance

Project description

Low-level Guidance (llguidance)

This controller implements a context-free grammar parser with Earley's algorithm on top of a lexer which uses derivatives of regular expressions.

It's to be used by next-generation Guidance grammars. See how it works in plan.md.

This is now available in main branch of Guidance. Guidance PR: https://github.com/guidance-ai/guidance/pull/951

Building

  • install rust; 1.75 or later
  • install python 3.9 or later; very likely you'll need a virtual env/conda
  • run ./scripts/install-deps.sh
  • to build and after any changes, run ./scripts/test-guidance.sh

Guidance implementation notes

  • gen() now generates a new node, Gen
  • grammar is serialized to JSON, see ll_serialize()

TODO

  • substring() in Guidance needs to be re-implemented (translate to RegexAst)
  • to_regex_vec() in lexerspec.rs - non-contextual keywords
  • allow byte sequence to fast-forward through grammar at start (grammar derivative)
  • check if env allows for backtracking (if not, don't use it)
  • return {when_sampled:[EOS],ff:[]} as slice when EOS ends gen()
  • check for relevance of intersection and negation in derivre

Lexeme-splitting

See https://github.com/microsoft/llguidance/issues/2

    g = select(["a", "abq", "c"]) + optional("bQ")
    check_grammar(g, ["", "a‧b‧q‧≺EOS≻"]) # fails 'q' is forced
    check_grammar(g, ["", "a‧b‧Q"]) # doesn't match at all

Only valid tokens

See https://github.com/microsoft/llguidance/issues/1

  • implement .forced_byte() method in derivre
  • use this for cheap .forced_byte() impl in llguidance
  • while walking token trie, remember all forced paths (there shouldn't be too many of them)

In toktrie walk, if we encounter a forced byte, we go into forced mode where we just chase all forced bytes. The first token we find on this path we put on some list. We do not add any of these tokens to the allow set.

Then, after token trie walk, for every token on this list we re-create the forced byte string, tokenize, chop excessive tokens, and add the first token from tokenization to allow set and remaining tokens (if any) as conditional splice.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llguidance-0.1.8.tar.gz (63.9 kB view details)

Uploaded Source

Built Distributions

llguidance-0.1.8-cp39-abi3-win_amd64.whl (685.6 kB view details)

Uploaded CPython 3.9+ Windows x86-64

llguidance-0.1.8-cp39-abi3-win32.whl (650.6 kB view details)

Uploaded CPython 3.9+ Windows x86

llguidance-0.1.8-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (803.0 kB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ x86-64

llguidance-0.1.8-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (859.4 kB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ i686

llguidance-0.1.8-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (763.3 kB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ ARM64

llguidance-0.1.8-cp39-abi3-macosx_11_0_arm64.whl (804.7 kB view details)

Uploaded CPython 3.9+ macOS 11.0+ ARM64

llguidance-0.1.8-cp39-abi3-macosx_10_12_x86_64.whl (819.5 kB view details)

Uploaded CPython 3.9+ macOS 10.12+ x86-64

File details

Details for the file llguidance-0.1.8.tar.gz.

File metadata

  • Download URL: llguidance-0.1.8.tar.gz
  • Upload date:
  • Size: 63.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.7.1

File hashes

Hashes for llguidance-0.1.8.tar.gz
Algorithm Hash digest
SHA256 e1c7b4010a1bc9b0e5e040e785e1c1bda7070cb966012d18957911e7bc587264
MD5 d5bf5004c0ec855f6b322847379d946b
BLAKE2b-256 d426dd8dd032432080869e946a460cb2dcd1449831c3fa7b6a2b1b39695fc614

See more details on using hashes here.

File details

Details for the file llguidance-0.1.8-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for llguidance-0.1.8-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4c879ef10eff5eda2e9a65b81b6f89e3e056cb46f19d3a3e6d044e8012172d24
MD5 5ebecd7326240f99f77d285d9baf381b
BLAKE2b-256 4f75ed60c7a457b424200f5ffe26939cac4c7c2cba70874245b6fa6b3aa503a2

See more details on using hashes here.

File details

Details for the file llguidance-0.1.8-cp39-abi3-win32.whl.

File metadata

  • Download URL: llguidance-0.1.8-cp39-abi3-win32.whl
  • Upload date:
  • Size: 650.6 kB
  • Tags: CPython 3.9+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.7.1

File hashes

Hashes for llguidance-0.1.8-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 f5259794c5eff33fd4438e683138c0402350501c0ed8fe15124200f2f3884ed8
MD5 0d9f3f062658163dd4c2825ccfb65eb8
BLAKE2b-256 eed2237e63a53cd44f770c301f517f2df415208169fd79cf4c3a0c80de11998c

See more details on using hashes here.

File details

Details for the file llguidance-0.1.8-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for llguidance-0.1.8-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e57e105b96a07be5723616cc77a58461c3d47badca15548a4492a19fbef321e7
MD5 ae38fe28700aafc5b6d819c258de5b42
BLAKE2b-256 64b74a9a7ae19f2cfb7c5e590d742703b71126cb6cf2fd6f9222ff176ecda944

See more details on using hashes here.

File details

Details for the file llguidance-0.1.8-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for llguidance-0.1.8-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 59cc94c1a23ec725c515911a1d26be93ed8e7ef6a0cc153d85f35b8765536031
MD5 996f15f532365013f7403e9133a9b0d9
BLAKE2b-256 e1efe24e01d8747e5e5713eeabbb24f36d3a7993c9ab96512dbf2e8d51f94789

See more details on using hashes here.

File details

Details for the file llguidance-0.1.8-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for llguidance-0.1.8-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f52bbfc95c06f14536f439ef06774e27c023307bb98a8bd2df5871e69768080e
MD5 060716dbc7253bb43670a7f0f4e5037d
BLAKE2b-256 7d774650450d1bb98bc954f7991f7b6bc94285f40fc7e3f073cca17d287ccfc7

See more details on using hashes here.

File details

Details for the file llguidance-0.1.8-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for llguidance-0.1.8-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 20d7042bb8b8831c191f6117e19f3089599d715833649549218f2ddf85b60e84
MD5 e1a093aa84736327e67b5a3d0b0a6832
BLAKE2b-256 9645c9feadac3fb229184592568b9cc9a98c5ada1a2d0ea2f4350812da4c5988

See more details on using hashes here.

File details

Details for the file llguidance-0.1.8-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for llguidance-0.1.8-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7f2393fda8ba5bd2f7dd84c9fbc95a0bb9b52118bc53667564c501884960bd9c
MD5 64eb7bd61ab8adf475005f4f39bc87b9
BLAKE2b-256 5505f11bef4ce6fe4a027e9be3e9ca57164d439dc3acc7fbd69f59cb9c27d599

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page