server : implement json-schema-to-grammar.mjs & add grammar param in the UI#2588
Merged
jhen0409 merged 8 commits intoggml-org:masterfrom Aug 14, 2023
Merged
server : implement json-schema-to-grammar.mjs & add grammar param in the UI#2588jhen0409 merged 8 commits intoggml-org:masterfrom
jhen0409 merged 8 commits intoggml-org:masterfrom
Conversation
|
This is very useful for integrating llama and traditional programming |
ejones
approved these changes
Aug 14, 2023
Collaborator
ejones
left a comment
There was a problem hiding this comment.
Nice conversion! Code looks good.
4 tasks
Seunghhon
pushed a commit
to Seunghhon/llama.cpp
that referenced
this pull request
Apr 26, 2026
…the UI (ggml-org#2588) * server : implement json-schema-to-grammar.mjs by follow python impl * server : add grammar support in chat.mjs * server : implement grammer param in the UI * server : generate .hpp * server : remove trailing whitespaces * server : generate .hpp * server : fix sort of prop pairs * server : optimize regex & iteration
phuongncn
pushed a commit
to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4
that referenced
this pull request
Apr 28, 2026
…the UI (ggml-org#2588) * server : implement json-schema-to-grammar.mjs by follow python impl * server : add grammar support in chat.mjs * server : implement grammer param in the UI * server : generate .hpp * server : remove trailing whitespaces * server : generate .hpp * server : fix sort of prop pairs * server : optimize regex & iteration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements json-schema-to-grammar.mjs by followed the Python implementation, it can be used in Web & Node.js.
I'm looking for a simple way to use JSON schema and gbnf, but I'm mostly using JS not Python for both client or server, so I thought it might be possible to have a JS implementation here, it should help others too.
Demo
Use a json schema as
functions.json(From PR #2532):{ "oneOf": [ { "type": "object", "properties": { "function": {"const": "create_event"}, "arguments": { "type": "object", "properties": { "title": {"type": "string"}, "date": {"type": "string"}, "time": {"type": "string"} } } } }, { "type": "object", "properties": { "function": {"const": "image_search"}, "arguments": { "type": "object", "properties": { "query": {"type": "string"} } } } } ] }Usage in Node.js:
Usage in the UI, we can just use gbnf or put JSON schema and press the convert button:
Completions
