Skip to content

Instantly share code, notes, and snippets.

@Maximilian-Winter
Maximilian-Winter / gbnf_grammar_generator.py
Last active November 17, 2024 06:13
GBNF grammar generator for always valid function calls and object creation in JSON with llama.cpp
import inspect
import json
import re
import typing
from inspect import isclass, getdoc
from types import NoneType
from pydantic import BaseModel, Field
from pydantic.fields import FieldInfo
from typing import Any, Type, List, get_args, get_origin, Tuple, Union, Optional