c21edb6908
* Do not set `grammar` to `None` for new `LlamaGrammar` objects The `grammar` attribute is written by `init()`, but that method always returns `None`, so `__init__()` would then discard the previously written object. * Add minimal test for grammar parsing
13 lines
296 B
Python
13 lines
296 B
Python
import llama_cpp
|
|
|
|
tree = """
|
|
leaf ::= "."
|
|
node ::= leaf | "(" node node ")"
|
|
root ::= node
|
|
"""
|
|
|
|
def test_grammar_from_string():
|
|
grammar = llama_cpp.LlamaGrammar.from_string(tree)
|
|
assert grammar._n_rules == 3
|
|
assert grammar._start_rule_index == 2
|
|
assert grammar.grammar is not None
|