xgrammar icon indicating copy to clipboard operation
xgrammar copied to clipboard

[Web] Support structural tag for web-xgrammar package, update web to 0.1.18

Open CharlieFRuan opened this issue 8 months ago • 0 comments

This PR updates the web-xgrammar TypeScript package, mainly adding support for Structural Tag. There are two components to this PR:

  1. Address trivial changes to the APIs, including adding any_whitespace and ebnfToGrammarNoNormalization(), and fixing any failed unit tests due to changes in the C++ source (see first commit 6bccf6d)
  2. Add structural tag support. Specifically, we export StructuralTagItem, fromStructuralTag(), and compileStructuralTag(). In addition, we add isGrammarAcceptString() for testing. Necessary changes are made to xgrammar_binding.cc

No change is needed outside of the web/ folder.

The structural tag feature is tested with TypeScript unit tests equivalent to test_grammar_matcher_structural_tag.py, and an E2E example in web/example/.

We subsequently publish 0.1.18 npm package https://www.npmjs.com/package/@mlc-ai/web-xgrammar

CharlieFRuan avatar Apr 27 '25 02:04 CharlieFRuan