[V1] Add structural_tag support using xgrammar (#17085)

This commit is contained in:
Russell Bryant
2025-04-26 14:06:37 +00:00
committed by GitHub
parent c48334d405
commit f8acd01ff7
10 changed files with 270 additions and 15 deletions
@@ -27,14 +27,15 @@ class GuidedDecodingRequest:
guided_decoding_backend: Optional[str] = None
guided_whitespace_pattern: Optional[str] = None
guided_json_object: Optional[bool] = None
structural_tag: Optional[str] = None
def __post_init__(self):
"""Validate that some fields are mutually exclusive."""
guide_count = sum([
self.guided_json is not None, self.guided_regex is not None,
self.guided_choice is not None, self.guided_grammar is not None,
self.guided_json_object is not None
])
guide_count = sum(x is not None
for x in (self.guided_json, self.guided_regex,
self.guided_choice, self.guided_grammar,
self.guided_json_object,
self.structural_tag))
if guide_count > 1:
raise ValueError(
"You can only use one kind of guided decoding but multiple are "