LLM Format
Introduction
LLM Format is a Large-language model formatter that constrain the outputs of language model to follow certain rules. Our design is to make this tool flexible and efficient to adapt to different use cases.
We currently supports vllm and any LALR(1) grammar including JSON format.
Different from other packages including lm-format-enforcer, jsonformer and guidance. This package ensures the generated text from LLM to be sound and complete.
Tutorial
Installation
pip install llmformat
Usage
To enforce a new type of grammar, a grammar file written in EBNF is needed. We provide the JSON example as here.
Once it is written, we can only need one-line code change to enforce the generation.
In vllm, add this option to sampling_param.
sampling_param.logits_processors=[llmformat.llminterface.build_vllm_logits_processor(model, "/root/llmformat/llmformat/json_min.bnf")]
Example
The example of working on Llama2 and vllm can be found here. Note that you may want to change the location of grammar file.
- Add support for customized JSON
- Add more integrations
Known Issues
We use cache to accelerate grammar parsing. The speed will becomes faster as it runns longer.
Metadata
Release files for llmformat 0.0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llmformat-0.0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Release files / llmformat-0.0.2.1-py3-none-any.whl
| Download URL | llmformat-0.0.2.1-py3-none-any.whl |
|---|---|
| Size | 19.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f505715c91c10faf9eec8bbed2c7f6c1890984b945d645fce40fb94c31b5ccea
|
|
BLAKE2b-256 checksum How to use checksums |
faf2dff80cf4179317fb3dc92917f93fd850caeb3a577f482029f44f25e2f597
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.0
|
Security for llmformat 0.0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.