elysium / backend /grammar.py
pmrinal2005's picture
Upload folder using huggingface_hub
a521353 verified
Raw
History Blame Contribute Delete
609 Bytes
"""GBNF loader. We use the built-in JSON grammar from llama.cpp because the
full Pydantic schema produces a very large GBNF that slows sampling.
For production we keep a moderate JSON grammar; the fine-tuned model is the
real guarantee of schema-correctness."""
from llama_cpp import LlamaGrammar
import pathlib
_GBNF = pathlib.Path(__file__).parent / "elysium_schema.gbnf"
def load_grammar():
if _GBNF.exists():
try:
return LlamaGrammar.from_string(_GBNF.read_text())
except Exception as e:
print(f"[grammar] load failed: {e}")
return None