Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples : support minLength and maxLength in JSON schema grammar converter #5039

Merged
merged 2 commits into from
Feb 19, 2024

Conversation

nopperl
Copy link
Contributor

@nopperl nopperl commented Jan 19, 2024

Changes the JSON schema to BNF grammar converter to restrict the length of output arrays to minItems and maxItems if specified in the JSON schema.

Example

echo '{"type": "object", "properties": {"tags": {"type": "array", "items": {"type": "string"}, "minItems": 2, "maxItems": 5}}}' > length.json
./main -m $MODEL_FILE --grammar "$( python examples/json-schema-to-grammar.py length.json )"

Output:

{"tags":["php","laravel"]}  [end of text]

examples/json-schema-to-grammar.py Outdated Show resolved Hide resolved
@ggerganov ggerganov merged commit 9d679f0 into ggerganov:master Feb 19, 2024
21 checks passed
Nexesenex pushed a commit to Nexesenex/croco.cpp that referenced this pull request Feb 19, 2024
…anov#5039)

* support minLength and maxLength in JSON schema grammar converter

* Update examples/json-schema-to-grammar.py

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
jordankanter pushed a commit to jordankanter/llama.cpp that referenced this pull request Mar 13, 2024
…anov#5039)

* support minLength and maxLength in JSON schema grammar converter

* Update examples/json-schema-to-grammar.py

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
hodlen pushed a commit to hodlen/llama.cpp that referenced this pull request Apr 1, 2024
…anov#5039)

* support minLength and maxLength in JSON schema grammar converter

* Update examples/json-schema-to-grammar.py

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants