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.

Guidance branch: https://github.com/hudson-ai/guidance/tree/lazy_grammars

Guidance PR: https://github.com/guidance-ai/guidance/pull/951

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

Uploaded Source

Built Distributions

llguidance-0.1.6-cp39-abi3-win_amd64.whl (671.2 kB view details)

Uploaded CPython 3.9+ Windows x86-64

llguidance-0.1.6-cp39-abi3-win32.whl (637.2 kB view details)

Uploaded CPython 3.9+ Windows x86

llguidance-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (789.6 kB view details)

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

llguidance-0.1.6-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (841.5 kB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ i686

llguidance-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (752.4 kB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ ARM64

llguidance-0.1.6-cp39-abi3-macosx_11_0_arm64.whl (792.4 kB view details)

Uploaded CPython 3.9+ macOS 11.0+ ARM64

llguidance-0.1.6-cp39-abi3-macosx_10_12_x86_64.whl (797.3 kB view details)

Uploaded CPython 3.9+ macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for llguidance-0.1.6.tar.gz
Algorithm Hash digest
SHA256 5e97f6e6b4178919a60d01eec6d0a03f8ee447f38f8b1cb670c5a20241fd9252
MD5 546e5815264ad1262f450e325083a264
BLAKE2b-256 30c7b969cc0950e094b3bfc2143b9b9468babc55254080056cefd77462402026

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.1.6-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 200555eeddd77b3795240d324f2afc953f4d808d3051fb522827c01a1d1e22b4
MD5 005d936a75fa4815870e971317847986
BLAKE2b-256 c2bb3be1ef377080f315a081a0568475f01d6abf8c17284777b3c7f3bf5a93ea

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for llguidance-0.1.6-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 94cdb35b08657a88b611a87209098359d1968e128c753ebaa6c2a690ff06f3f6
MD5 4b866bc9ff67f78d70b74d01c07a6a1f
BLAKE2b-256 fd81f713eab4bfc04d53e295fa79b43da61e84816a1281d1ed5b8b526dda5354

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.1.6-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a35058e77e08d48ff3724824e5c957baaa7d74467da626084511565ca363a930
MD5 f8ff0639cdd7608d4bda4d7d228cf9f5
BLAKE2b-256 5c60ab5d215d097511f6a26a10220cf34e4fb1a510be11b264e239773bf8d2a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.1.6-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4368b69dab91ffff4d57c6c7d720885cbaa9be70880b98fef00cbb5f4661c18a
MD5 84edf9c2e2b2eb71f7ca5982e0fa403c
BLAKE2b-256 1dec4b004b1385e9c23f36685f176f851267eb55aa0f2f72f61ef81613ebfb8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.1.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fee54e9df0271ce612cc460afd8d6bf661af55ec1590bf35864fc5e50bab4435
MD5 23cff405aa62e0cae63e5e7537ff66c4
BLAKE2b-256 c7da9ae321ee30cec6cf23837d0535f7854a98e5f6c21d4285c1123bbc0d7bd5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.1.6-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5176913b9d5d32899f0194d72cb3a01c1536e2d2a6434bd96e5f09b611074051
MD5 523a7221870c0bbd3df6d2db04bbadcf
BLAKE2b-256 b1ad55da24e15c31bed81b206069a675f173b5ea05a48c3ed2b77164f1897853

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llguidance-0.1.6-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 414e4c2fc92615956681704d38032afe846840621f02bc45a2746faec56523f5
MD5 c7a949af552b0f821bacc6e167d56368
BLAKE2b-256 65b018a141c628670cf259dc17c9346da02cfc74d3b895ff39ce1191258db396

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