Introduce @huggingface/transformers-llguidance#1721
Open
nico-martin wants to merge 5 commits into
Open
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a new
@huggingface/transformers-llguidancepackage that wrapsllguidanceresponse formats into the generation hooks already supported by Transformers.js:logits_processorto mask invalid next tokens during generationstopping_criteriato stop once the llguidance interpreter reaches completionThe package currently exposes
LlguidanceConstraint.fromResponseFormat(tokenizer, response_format, loadOptions?), which accepts llguidance response formats such asjson_schema,json_object, andregex, then returns the objects that can be passed directly into Transformers.js generation.Closes #1328.
Why
This keeps constrained generation outside the core
@huggingface/transformerspackage while still integrating with its existing generation extension points. It also gives us a small package boundary for the llguidance dependency and its WASM loading behavior.Demo
Loading And Caching
The package delegates to
llguidancefor creating the interpreter, but preloads the llguidance WASM assets through Transformers.js WASM helpers when possible. This means browser-like runtimes can reuse the same cache path controlled byenv.useWasmCacheinstead of forcing llguidance to fetch its WASM assets independently.The loading behavior is:
useWasmCacheis disabled, the runtime is Node-like, or the caller provideswasmFactory, load directly throughllguidance.Open Question
llguidance-jscurrently lives under my own user:Should we keep it there for now, move it into the Transformers.js package/workspace, or publish/maintain it under the Hugging Face org?