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

This commit is contained in:
Russell Bryant
2025-04-26 10:06:37 -04:00
committed by GitHub
parent c48334d405
commit f8acd01ff7
10 changed files with 270 additions and 15 deletions

View File

@@ -38,6 +38,7 @@ class GuidedDecodingParams:
"""These are other options that can be set"""
backend: Optional[str] = None
whitespace_pattern: Optional[str] = None
structural_tag: Optional[str] = None
@staticmethod
def from_optional(
@@ -48,9 +49,10 @@ class GuidedDecodingParams:
json_object: Optional[bool] = None,
backend: Optional[str] = None,
whitespace_pattern: Optional[str] = None,
structural_tag: Optional[str] = None,
) -> Optional["GuidedDecodingParams"]:
if all(arg is None
for arg in (json, regex, choice, grammar, json_object)):
if all(arg is None for arg in (json, regex, choice, grammar,
json_object, structural_tag)):
return None
# Extract json schemas from pydantic models
if isinstance(json, (BaseModel, type(BaseModel))):
@@ -63,6 +65,7 @@ class GuidedDecodingParams:
json_object=json_object,
backend=backend,
whitespace_pattern=whitespace_pattern,
structural_tag=structural_tag,
)
@property