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.7.tar.gz (63.9 kB view details)

Uploaded Source

Built Distributions

llguidance-0.1.7-cp39-abi3-win_amd64.whl (686.1 kB view details)

Uploaded CPython 3.9+ Windows x86-64

llguidance-0.1.7-cp39-abi3-win32.whl (651.2 kB view details)

Uploaded CPython 3.9+ Windows x86

llguidance-0.1.7-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (803.7 kB view details)

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

llguidance-0.1.7-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (859.6 kB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ i686

llguidance-0.1.7-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (763.6 kB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ ARM64

llguidance-0.1.7-cp39-abi3-macosx_11_0_arm64.whl (805.6 kB view details)

Uploaded CPython 3.9+ macOS 11.0+ ARM64

llguidance-0.1.7-cp39-abi3-macosx_10_12_x86_64.whl (820.3 kB view details)

Uploaded CPython 3.9+ macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: llguidance-0.1.7.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.7.tar.gz
Algorithm Hash digest
SHA256 65251b40168c5e083d7b4aeb7dacce27add34c5c43ad89b6e56d6411b68ac13b
MD5 be02fe2030b3318bfadd89c5e354805e
BLAKE2b-256 fe6e795766ad7e2232e94fd7771886ea6d9a41e7a75ba439a916b9bbd9c919d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.1.7-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5418e3c1118cb777455a46d11f6201dce8f3ed084dad35e63375a72158c00bb4
MD5 a384ef4b61933cbfc67a3f90424c5d56
BLAKE2b-256 dbd4449fd98c0c877b07201fcb54f41a5f9752efe264b5029b98ff1fd4aebe50

See more details on using hashes here.

File details

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

File metadata

  • Download URL: llguidance-0.1.7-cp39-abi3-win32.whl
  • Upload date:
  • Size: 651.2 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.7-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 deb7e784afc5909696737d2d07cf25887795cac5e83aaa25ceda84a058a98907
MD5 be187ac8bd20146709909e54426ab0d5
BLAKE2b-256 8fc90c814c1df057633fe1b6aeeb37da1e8edc09e67211f03c47550218f2b54d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.1.7-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f25738d69479d069b099cd97677bc6ca09eb56ba5454a2e866b019610d5b38af
MD5 1d2586b2db0f4d4b023792017b74a796
BLAKE2b-256 d6f483f7e1ad2ac8a9b92e190b153c23eb10d43bf214c7ff12f171e9030fcac2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.1.7-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b9196018d87e7901e95976ae9dcf6fd3bf13cf6b24df6d685537c5ba4e60bea6
MD5 fa0aa8196058de5275877de2897f62d8
BLAKE2b-256 dd7e73625b21ebba44e13acf76b9d0617453f0d4bc64bec8d991a436cef75abf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.1.7-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 35b3e4a1c9a04e2d4938360ff6a2a3d374c41ad106dc9b27a551b6ce14d01d2c
MD5 2c9ee820bcb3b67520febdd053934cbd
BLAKE2b-256 80376a72b0cc5eecb3b04d5119db87bb861b5169c72fc8aafc6aadccf4946e7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.1.7-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9a9f2ef75df8d03b0a449a6e1d7687fe48d513513e0f7b7d6f458c6c9bdfb045
MD5 5d2369895cc314a2b247aa4641ed6902
BLAKE2b-256 888c968c4271a7d08a7c4b4ed38770fd799a95a4a211232ee9feeb5c02d402fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.1.7-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1bdb1b2ab7e81a93c13fdfb8f7b0f812e98d47ae9231c680cc6908d3037832cc
MD5 2d7e4fa7b9f49ba910133bb59f2042ad
BLAKE2b-256 32fb5ffe413601e85678c458d0fa80126e3e685c2b5c78c85036d2d557402676

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