[Feature] Support new parameter - EBNF in xgrammar (#2526)

This commit is contained in:
Adarsh Shirawalmath
2024-12-26 18:42:41 +05:30
committed by GitHub
parent 08effbff35
commit acb340728c
8 changed files with 384 additions and 2 deletions

View File

@@ -126,6 +126,12 @@ class XGrammarGrammarBackend(BaseGrammarBackend):
f"Skip invalid json_schema: json_schema={key_string}, {e=}"
)
return None
elif key_type == "ebnf":
try:
ctx = self.grammar_compiler.compile_grammar(key_string)
except RuntimeError as e:
logging.warning(f"Skip invalid ebnf: ebnf={key_string}, {e=}")
return None
elif key_type == "regex":
logger.warning(
"regex hasn't been supported by xgrammar yet. This is skipped."