Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adrienbrault/json-schema-to-gbnf
Converts JSON-Schema to GBNF grammar to use with llama.cpp
https://github.com/adrienbrault/json-schema-to-gbnf
Last synced: about 2 months ago
JSON representation
Converts JSON-Schema to GBNF grammar to use with llama.cpp
- Host: GitHub
- URL: https://github.com/adrienbrault/json-schema-to-gbnf
- Owner: adrienbrault
- License: mit
- Created: 2023-11-23T21:55:47.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-27T16:56:43.000Z (about 1 year ago)
- Last Synced: 2024-10-14T06:30:15.958Z (2 months ago)
- Language: TypeScript
- Homepage: https://adrienbrault.github.io/json-schema-to-gbnf/
- Size: 50.8 KB
- Stars: 51
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Introduction
Convert a [JSON-Schema][json_schema] to a [GBNF grammar][gbnf_grammar], to use with [llama.cpp][llama.cpp_contrained_output].
This implementation aims to support more of the JSON-Schema specification than [alternatives](#alternatives).
See [src/convert.test.ts](src/convert.test.ts) and [src/regexp-convert.test.ts](src/regexp-convert.test.ts) for examples of supported features.
Use it online: [adrienbrault.github.io/json-schema-to-gbnf][web_url]
# Development
To install dependencies:
```bash
bun install
```To run:
```bash
bun run src/index.ts ""
```To build and run the website:
```bash
bun run build-site
bunx serve build
```To run tests in watch mode when developing:
```bash
bun test --watch
```# Resources
- [GBNF Spec][gbnf_grammar]
- [json.gbnf](https://github.com/ggerganov/llama.cpp/blob/master/grammars/json.gbnf)
- [json_arr.gbnf](https://github.com/ggerganov/llama.cpp/blob/master/grammars/json_arr.gbnf)## Alternatives
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## llama.cpp alternatives for JSON constrained output
- https://github.com/outlines-dev/outlines
- https://github.com/jmorganca/ollama/pull/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[json_schema]: https://json-schema.org
[gbnf_grammar]: https://github.com/ggerganov/llama.cpp/blob/master/grammars/README.md
[llama.cpp_contrained_output]: https://github.com/ggerganov/llama.cpp#constrained-output-with-grammars
[web_url]: https://adrienbrault.github.io/json-schema-to-gbnf/