Skip to content

Conversation

@Seven-Streams
Copy link
Collaborator

This PR supports the structural tag templates, provides a method to generate a grammar from a structural tag template and the given values, and provides built-in structural tag templates for several models' tool-calling formats.

Signed-off-by: Yuchuan <[email protected]>

finish the basic structure.

Signed-off-by: Yuchuan <[email protected]>

feat:add a function to detect placeholder.

Signed-off-by: Yuchuan <[email protected]>

feat:add the visit functions.

Signed-off-by: Yuchuan <[email protected]>

update.

Signed-off-by: Yuchuan <[email protected]>

finish the basic design.

Signed-off-by: Yuchuan <[email protected]>

fix the design.

Signed-off-by: Yuchuan <[email protected]>

finish support for const string.

Signed-off-by: Yuchuan <[email protected]>

add fill functions for basic stags.

Signed-off-by: Yuchuan <[email protected]>

add to string functions.

Signed-off-by: Yuchuan <[email protected]>

add the detection for mingling.

Signed-off-by: Yuchuan <[email protected]>

fix apis.

Signed-off-by: Yuchuan <[email protected]>

fix mingle privacy.

Signed-off-by: Yuchuan <[email protected]>

finish support for sequence.

Signed-off-by: Yuchuan <[email protected]>

finish all the fillers except tagformat.

Signed-off-by: Yuchuan <[email protected]>

finish the template filler.

Signed-off-by: Yuchuan <[email protected]>

finish.

Signed-off-by: Yuchuan <[email protected]>

fix api.

Signed-off-by: Yuchuan <[email protected]>

finish python api.

Signed-off-by: Yuchuan <[email protected]>

fix api.

Signed-off-by: Yuchuan <[email protected]>

fix api.

Signed-off-by: Yuchuan <[email protected]>

finish the testing for const string.

Signed-off-by: Yuchuan <[email protected]>

fix:fix jsonschemaformat and qwenformat.

Signed-off-by: Yuchuan <[email protected]>

add tests for jsonschemaformat.

Signed-off-by: Yuchuan <[email protected]>

finish testing for qwen xml format.

Signed-off-by: Yuchuan <[email protected]>

finish the check for regex.

Signed-off-by: Yuchuan <[email protected]>

finish the testing for basic types.

Signed-off-by: Yuchuan <[email protected]>

finish basic tests.

Signed-off-by: Yuchuan <[email protected]>

add test for orformat.

Signed-off-by: Yuchuan <[email protected]>

fix testing for sequence.

Signed-off-by: Yuchuan <[email protected]>

add the testing for mingled or and sequence.

Signed-off-by: Yuchuan <[email protected]>

fix dummy placeholder name.

Signed-off-by: Yuchuan <[email protected]>

fix dummy test.

Signed-off-by: Yuchuan <[email protected]>

finish testing for mingled tagformat.

Signed-off-by: Yuchuan <[email protected]>

finish basic testing for triggered tag template.

Signed-off-by: Yuchuan <[email protected]>

finish all the combinatorial stags tests.

Signed-off-by: Yuchuan <[email protected]>

finish part of builtin templates.

Signed-off-by: Yuchuan <[email protected]>

finish qwen style template.

Signed-off-by: Yuchuan <[email protected]>

finish the templates.

Signed-off-by: Yuchuan <[email protected]>

fix.

Signed-off-by: Yuchuan <[email protected]>

format.

Signed-off-by: Yuchuan <[email protected]>

fix.

Signed-off-by: Yuchuan <[email protected]>

fix kimi format.

Signed-off-by: Yuchuan <[email protected]>

add tests for deepseek and qwen_coder.

Signed-off-by: Yuchuan <[email protected]>

finish testing for qwen.

Signed-off-by: Yuchuan <[email protected]>

finish the tests for harmony.

Signed-off-by: Yuchuan <[email protected]>

support no tools provided.

Signed-off-by: Yuchuan <[email protected]>
Copilot AI review requested due to automatic review settings November 21, 2025 12:03
Copilot finished reviewing on behalf of Seven-Streams November 21, 2025 12:08
Copy link

Copilot AI left a 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 introduces support for structural tag templates, enabling users to generate grammars from templates with dynamic values. The feature includes a template placeholder system, built-in templates for popular models' tool-calling formats (Llama, Kimi, Deepseek, Qwen, Harmony), and comprehensive test coverage.

  • Adds template placeholder syntax {placeholder_name[].field} for dynamic value substitution
  • Implements built-in structural tag templates for 6 model formats
  • Adds extensive test coverage for template expansion and validation

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/python/test_structural_tag_converter.py Adds 1600+ lines of comprehensive tests for template functionality including const string, JSON schema, regex, grammar, and builtin templates
python/xgrammar/structural_tag.py Implements template registry system and 6 builtin template functions for model-specific tool-calling formats
python/xgrammar/grammar.py Adds apply_structural_tag_template method to Grammar class for applying templates with values
cpp/structural_tag.h Adds C++ API declaration for template application with ToString methods for Format types
cpp/structural_tag.cc Implements core template detection, placeholder replacement, and format expansion logic (~1100 lines)
cpp/nanobind/nanobind.cc Adds Python binding for apply_structural_tag_template with kwargs handling
cpp/nanobind/python_methods.h Adds necessary includes for template functionality
cpp/nanobind/python_methods.cc Adds include for structural_tag.h
cpp/json_schema_converter.cc Enhances enum handling to support both JSON and XML formats with proper quote stripping
Comments suppressed due to low confidence (1)

python/xgrammar/grammar.py:450

  • Nested for statement uses loop variable 'key' of enclosing for statement.
                for key, value in item.items():

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant