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/hudson-ai/guidance/issues/5
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/hudson-ai/guidance/issues/13
- implement
.forced_byte()
method inderivre
- use this for cheap
.forced_byte()
impl inllguidance
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file llguidance-0.1.5.tar.gz
.
File metadata
- Download URL: llguidance-0.1.5.tar.gz
- Upload date:
- Size: 57.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a912ae38ae3726b1aaf4a33981acad8ceed7a99649fbf00fd9bc8a31134bc04d |
|
MD5 | 704a1b9582a00cf2eeff1c72ff7b3041 |
|
BLAKE2b-256 | a6554eb2cf48fad537ed6115a76458c906191c24369167abb1c6dd460c9c0b7c |
File details
Details for the file llguidance-0.1.5-cp39-abi3-win_amd64.whl
.
File metadata
- Download URL: llguidance-0.1.5-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 677.4 kB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0959d589b0fd1b52d67d3f93e6bd74e4e26d417406b9322fd7b6853b9dd5bd00 |
|
MD5 | 2ed313d8b3439e9e661f1c75753b073c |
|
BLAKE2b-256 | 1e77391522d1a9ec152067dad4d2da241e9e566f5ef1ae8c1ccd60704765d129 |
File details
Details for the file llguidance-0.1.5-cp39-abi3-win32.whl
.
File metadata
- Download URL: llguidance-0.1.5-cp39-abi3-win32.whl
- Upload date:
- Size: 641.3 kB
- Tags: CPython 3.9+, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2627fd22ae81d46b790f74d1ff698f71164dfc2d65dca2db994274539a457f26 |
|
MD5 | f180939531966dfca7ff0b82a81ffff3 |
|
BLAKE2b-256 | 9efcbe0530f8f1101d244c64f5a37e2a4bf00940728f53fea02545ffc3ad0c69 |
File details
Details for the file llguidance-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: llguidance-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 797.3 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b7dce76c7eac2604cbccee5a94ec3c211e0ce36bc5b841f4565a931b0d4e489 |
|
MD5 | bf49939b6d9c519ccc55416dca3d2364 |
|
BLAKE2b-256 | d445669e7cad6cff046ce2183df8c22a50c531b87b9b42b1922fae5dc295d5b9 |
File details
Details for the file llguidance-0.1.5-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: llguidance-0.1.5-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 850.3 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ i686
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5deddf6f2b1c83cee5e4651657d1591649a71b6cd3321023a409b68f05df670e |
|
MD5 | 9d4af07467328b8e3ab414309f19e76b |
|
BLAKE2b-256 | 0a05602b1df755746e9a7eb1697972b1f8a18c5f5547993c6f583fe953a6e6b8 |
File details
Details for the file llguidance-0.1.5-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: llguidance-0.1.5-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 758.1 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68fc6c7af496cd350712a88f9f74018e7e9085d79a38309bcd4ab0365462d6c7 |
|
MD5 | 6569d8313c658f8430294323e173751c |
|
BLAKE2b-256 | 7377981d198687bdde50fa120d399eceba22e708837712c69e01364ce0430596 |
File details
Details for the file llguidance-0.1.5-cp39-abi3-macosx_11_0_arm64.whl
.
File metadata
- Download URL: llguidance-0.1.5-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 799.3 kB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4995e56cbc62e72432fbd8054fd2c5c2d17245b9a85817f99f9c8700ca6ac72 |
|
MD5 | 636728a5928a0e3d850c40bfd6993cb1 |
|
BLAKE2b-256 | 97054b52ffafedb9cd1f2a7b1bf97b0dae1585a8d04836747b04d8ad6b7f4b4d |
File details
Details for the file llguidance-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: llguidance-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 808.2 kB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdece5c6c740b1185b7d2488e9c0336bb5273715879ace69b1c1fd09ae536c84 |
|
MD5 | 8e0f69f51c74c5927fbbeb146ade1023 |
|
BLAKE2b-256 | e00a0a57e86a4f854e0c3de2316b88d2e9f665263f11382a8eb6b8886dd3ce18 |