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

Grammars are normally JSON-serialized. The following libraries produce llguidance grammars:

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

This builds the Python bindings for the library and runs the tests (which mostly live in the Guidance repo - it will clone it).

The Rust crate is called llguidance_parser. For usage see the README there.

TODO

  • to_regex_vec() in lexerspec.rs - non-contextual keywords
  • allow byte sequence to fast-forward through grammar at start (grammar derivative)
  • return {when_sampled:[EOS],ff:[]} as slice when EOS ends gen()

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

Uploaded Source

Built Distributions

llguidance-0.2.0-cp39-abi3-win_amd64.whl (736.5 kB view details)

Uploaded CPython 3.9+ Windows x86-64

llguidance-0.2.0-cp39-abi3-win32.whl (693.5 kB view details)

Uploaded CPython 3.9+ Windows x86

llguidance-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (914.2 kB view details)

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

llguidance-0.2.0-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (963.7 kB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ i686

llguidance-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (856.0 kB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ ARM64

llguidance-0.2.0-cp39-abi3-macosx_11_0_arm64.whl (861.4 kB view details)

Uploaded CPython 3.9+ macOS 11.0+ ARM64

llguidance-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl (876.3 kB view details)

Uploaded CPython 3.9+ macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for llguidance-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f64bcebdad2f6515b4d8f2f5e522f18fa585c06d557e76ca026ddf36f5926345
MD5 9973167af4de7ba7d617265317898606
BLAKE2b-256 84ed3972931d40f33c965bfd2cf596db1bcd9c67be3a85c3f9c88e7252ee0d63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f94e13c652c004422b5c1c0efed07bf17b1e5add9a6c51667c32d4014aae5b71
MD5 1dc3a742513f495507158a75d55153a4
BLAKE2b-256 4a8f74a97c2a907d9aaf0e75b642ca56cecaffc75707711d4d549f92ffed40f3

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for llguidance-0.2.0-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 9ff3ff6c401ad6e14236fd611ce3cf3cfc9dfd4f153896fa549cf2098998e2e1
MD5 02bae1edb7026f3caeb3d647d247044c
BLAKE2b-256 dab6e0ca56d3ce4e48fba562410c852517cfc561b5f5976f2c1c4315c0a8ef08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e26b8dddcd36b3b632ea657015a5cde59bbf6ae6e49998e4775414a679a02b45
MD5 f424ca4243375d833c1a9a41ab6c683b
BLAKE2b-256 a9c6b2a26d0dc06f6ec56ddb63c231605d8007fc4636405efd55b352c3167c83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.2.0-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 c8e8e05086593823e6250a3fee49ae07fe0f94ea0e1c067eeb4db2716b641db4
MD5 5c984eb2128cebafb040ab8931563896
BLAKE2b-256 1db5522628cf22a7e056b4efe803259f56ac9033438ef6c8a2b970895aeecb01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f189b94b5b7a3b5547e1f9655730ac73fc58d0c663fb4afce28d2d31af378947
MD5 233d1be8bdb8c574b7fc2cb4de382ade
BLAKE2b-256 6fde8942f719e9a4fe2df0e4032f673b8a6b6800766597da03ab9b026755ba61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 03385faf950b1643773e5c024af460727d848a1360c38c69e1cb8970d6f53e24
MD5 6c5ba318fd8a79402694b9666fa65e97
BLAKE2b-256 ce2cbf963b22cf481fe100458b24db54fdfa4650fedfcd043da77308bfaa2023

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 49d8d2a85de488bc6e41ba9aed79fb7b51ff150046ebb59fdc43e4ba15fefc8e
MD5 09173e2f64be1b92f7bc686a8874f016
BLAKE2b-256 f22a7630b068e080baaae910201be06c8e64b3db0a125c2846a1baf2449523e2

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