MCPcopy Create free account
hub / github.com/abetlen/llama-cpp-python / json_schema_to_gbnf

Function json_schema_to_gbnf

llama_cpp/llama_grammar.py:944–953  ·  view source on GitHub ↗
(schema: str, prop_order: Optional[List[str]] = None)

Source from the content-addressed store, hash-verified

942
943
944def json_schema_to_gbnf(schema: str, prop_order: Optional[List[str]] = None):
945 prop_order = prop_order or []
946 schema = json.loads(schema)
947 prop_order = {name: idx for idx, name in enumerate(prop_order)}
948 converter = SchemaConverter(
949 prop_order=prop_order, allow_fetch=False, dotall=False, raw_pattern=False
950 )
951 schema = converter.resolve_refs(schema, "stdin")
952 converter.visit(schema, "")
953 return converter.format_grammar()

Callers 1

from_json_schemaMethod · 0.85

Calls 4

resolve_refsMethod · 0.95
visitMethod · 0.95
format_grammarMethod · 0.95
SchemaConverterClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…