File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
Filter options
Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ def __init__(
64
64
65
65
@classmethod
66
66
def from_string (cls , grammar : str , verbose : bool = True ) -> "LlamaGrammar" :
67
+ """Convert a GBNF grammar to a Llama grammar."""
67
68
parsed_grammar = parse (const_char_p (grammar )) # type: parse_state
68
69
if parsed_grammar .rules .empty ():
69
70
raise ValueError (
@@ -75,6 +76,15 @@ def from_string(cls, grammar: str, verbose: bool = True) -> "LlamaGrammar":
75
76
print (file = sys .stderr )
76
77
return cls (parsed_grammar )
77
78
79
+ @classmethod
80
+ def from_json_schema (
81
+ cls ,
82
+ json_schema : str ,
83
+ verbose : bool = True ,
84
+ ) -> "LlamaGrammar" :
85
+ """Convert a JSON schema to a Llama grammar."""
86
+ return cls .from_string (json_schema_to_gbnf (json_schema ), verbose = verbose )
87
+
78
88
@classmethod
79
89
def from_file (cls , file : Union [str , Path ], verbose : bool = True ) -> "LlamaGrammar" :
80
90
try :
You can’t perform that action at this time.
0 commit comments