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

Uploaded Source

Built Distributions

llguidance-0.3.0-cp39-abi3-win_amd64.whl (813.3 kB view details)

Uploaded CPython 3.9+ Windows x86-64

llguidance-0.3.0-cp39-abi3-win32.whl (761.2 kB view details)

Uploaded CPython 3.9+ Windows x86

llguidance-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (995.5 kB view details)

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

llguidance-0.3.0-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (1.1 MB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ i686

llguidance-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (936.4 kB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ ARM64

llguidance-0.3.0-cp39-abi3-macosx_11_0_arm64.whl (941.9 kB view details)

Uploaded CPython 3.9+ macOS 11.0+ ARM64

llguidance-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl (964.0 kB view details)

Uploaded CPython 3.9+ macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for llguidance-0.3.0.tar.gz
Algorithm Hash digest
SHA256 63d915f8107d44d3cef2c61dccf980fb650a4582790901f1a5a2d2042201166a
MD5 ba6ceb562c13092259050fa99c46bece
BLAKE2b-256 1a01b734e3379ca8884d9bc3867028a04c56b11b03381ffa4e72a6ef9daf2ce8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.3.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4367c07a365cfccca00648cdd3c246bb8e6ecf1e7a8fb0045f133e6226771573
MD5 b5101b179b6213998a311f216300d408
BLAKE2b-256 726b3a5839b60beae4a1d4eeba105ad81f1ed34bcb4a2574c14f2cd238dfa1db

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for llguidance-0.3.0-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 e009a7c0ca08c1a63d564ae6cf72fb5b8977f0da57b57388698746ba86ae2a1f
MD5 90ccbf633f5111326057ea24f6974001
BLAKE2b-256 5292ba0dd674afc78cb60446ac9c523b744fb3a14b1851537b5a39066ae62282

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c37543a085f749ca7813abdb1222609605c7218f5ddcffc515d0e49a46e9e415
MD5 67afeb62c13850d8e1f7000193b52286
BLAKE2b-256 8962c14a58289831c864d57e7133cbf0b1c019b201825fe0de243fb310ab9103

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.3.0-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ef776e1450bdb3a9f7f6fd5e3b9c75117ba11713921580c926d94f4b813d1085
MD5 590beddbd3b79ae1471170ae6b9933c3
BLAKE2b-256 156d396bfd3849ef013330655b919c1cde12f0c0f7f87f5b98514775f6cda9d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 33462d83c3ded6814f971a09df10807fea839e9e7de86ac067111fef804f6f04
MD5 b977913f74d1b3aa36dc65f1b84d7728
BLAKE2b-256 c2bc4af004685eb823d413e6bbee4fb7bfbfdb0611c5473086a6c5d95cc69696

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.3.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 19187bca40e11a5af5765bda9a5d42159d372ddaccd9853479cd63d3fa308137
MD5 ce25fa1a0453b1608b48b4fe3c2f143a
BLAKE2b-256 a9b7018b69f8b4fa497b4993c1330840d05b1228b24482c97974dbb4b6f97bb9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 76762847d657beb390120a7e8c5dc46c76a0cd7d18241490b2bea54423277bab
MD5 b6f90f78014d64f52d3b939c1e57e3ba
BLAKE2b-256 944a49934ded9f472270bbff875ad876fd72df0865a54c21b786f445af0a669f

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