Convert a JSON-Schema to a GBNF grammar, to use with llama.cpp.
This implementation aims to support more of the JSON-Schema specification than alternatives.
See src/convert.test.ts and src/regexp-convert.test.ts for examples of supported features.
Use it online: adrienbrault.github.io/json-schema-to-gbnf
To install dependencies:
bun install
To run:
bun run src/index.ts "<json schema>"
To build and run the website:
bun run build-site
bunx serve build
To run tests in watch mode when developing:
bun test --watch
The following are alternative JSON-Schema to GBNF converters:
- https://github.com/ggerganov/llama.cpp/blob/master/examples/json-schema-to-grammar.py
- https://github.com/intrinsiclabsai/gbnfgen
- https://github.com/mudler/LocalAI/blob/v1.40.0/pkg/grammar/json_schema.go
- https://github.com/outlines-dev/outlines
- ollama/ollama#830
- https://github.com/1rgs/jsonformer
- https://github.com/guidance-ai/guidance#context-free-grammars
- https://localai.io/features/openai-functions/
- https://github.com/noamgat/lm-format-enforcer
- https://github.com/thiggle/api#context-free-grammar-completion-api
- https://github.com/rizerphe/local-llm-function-calling