Closed Saibo-creator closed 5 months ago
The script examples/json-schema-to-grammar.py in llama-cpp provides a way to convert a JSON schema to a grammar. This can be seen in the usage example with the student.json schema:
student.json
% cat ../schemas/student.json { "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "number"}, "is_student": {"type": "boolean"}, "courses": { "type": "array", "items": {"type": "string"} } } } % ./main -m $L13B -p 'Hermione Granger ' --grammar "$(python3 examples/json-schema-to-grammar.py ../schemas/student.json --prop-order 'is_student,name,age,courses')" ... {"is_student":true, "name":"Hermione","age":12,"courses":[ "Arithmancy", "Defense Against the Dark Arts", "Divination", "Muggle Studies", "Herbology", "Potions" ]}
This allows users to directly generate JSON data that adheres to a predefined schema.
This feature would be largely reduce users's workload of writing a grammar themselves!
Here is a very nice online tool which does the same conversion. It was shared in the llama-cpp discussion
Description
The script examples/json-schema-to-grammar.py in llama-cpp provides a way to convert a JSON schema to a grammar. This can be seen in the usage example with the
student.json
schema:This allows users to directly generate JSON data that adheres to a predefined schema.
This feature would be largely reduce users's workload of writing a grammar themselves!
Here is a very nice online tool which does the same conversion. It was shared in the llama-cpp discussion