-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[XGrammar] Add structural tag support and example #756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds “structural tag” as a new response_format mode backed by @mlc-ai/web-xgrammar, including request validation, pipeline support, and a new browser example demonstrating MCP-style <tool_call> blocks.
Changes:
- Extend
ResponseFormatto supporttype: "structural_tag"and validate its required fields. - Update
LLMChatPipelineto compile/apply structural-tag constraints via XGrammar. - Add a new
examples/structural-tag-tool-usedemo and bump@mlc-ai/web-xgrammarto0.1.27.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/openai_api_protocols/chat_completion.ts | Adds structural-tag type to ResponseFormat and enforces request invariants in postInitAndCheckFields. |
| src/llm_chat.ts | Adds structural-tag handling for constrained decoding, plus caching refactor for matcher reuse. |
| src/error.ts | Introduces InvalidResponseFormatStructuralTagError. |
| package.json | Bumps @mlc-ai/web-xgrammar to 0.1.27. |
| package-lock.json | Updates lockfile to reflect new xgrammar version (and refreshed transitive versions). |
| cleanup-index-js.sh | Adds an additional post-build rewrite to make Parcel packaging work with scriptDirectory initialization. |
| examples/structural-tag-tool-use/src/mcp_structural_tag.ts | New demo that requests structural-tag constrained tool calls and runs stub tools. |
| examples/structural-tag-tool-use/src/mcp_structural_tag.html | Minimal demo page wiring up the example. |
| examples/structural-tag-tool-use/package.json | Parcel-based build/run config for the new example. |
| examples/structural-tag-tool-use/README.md | Usage instructions and explanation for the example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…uctural tag to ResponseFormat interface
CharlieFRuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
No description provided.