Feat: Implement JSON Mode (response_format.type="json_object") (#4733)

Co-authored-by: Kyle Pena <kylepena@kyles-macbook-pro.turkey-marlin.ts.net>
This commit is contained in:
kyle-pena-kuzco
2025-04-20 20:41:22 -04:00
committed by GitHub
parent 8de53da989
commit 9f3bd2ad39
3 changed files with 140 additions and 0 deletions

View File

@@ -158,6 +158,7 @@ class XGrammarGrammarBackend(BaseGrammarBackend):
def dispatch_json(self, key_string: str) -> Optional[XGrammarGrammar]:
try:
if key_string == "$$ANY$$":
# Note: This builtin JSON grammar includes *all* valid JSON (including, for example, arrays at the root)
ctx = self.grammar_compiler.compile_builtin_json_grammar()
else:
ctx = self.grammar_compiler.compile_json_schema(schema=key_string)