Format output as json #614
Replies: 3 comments 2 replies
-
Any luck with this? having the same issue when trying to parse grammar from a string. |
Beta Was this translation helpful? Give feedback.
-
Try using a raw string: schema = r'''
<snip>
''' If it's not a raw string, the backslashes will be interpreted by Python instead of by the llama.cpp grammar parser. This is similar to how raw strings are used for regular expressions. |
Beta Was this translation helpful? Give feedback.
-
LM Format Enforcer is a library that may help, and it has llama.cpp python support: Disclosure: I am the author |
Beta Was this translation helpful? Give feedback.
-
I am trying to make sure that my output follow a json format every time, i stumbled upon jsonformer and from there i stumbled upon grammar-based sampling, I used json-schema-to-grammar.py to convert json schema.
I want to know if grammar based sampling is used for this specific purpose and if so then how do i use it.
Json schema
Llama grammar
Here is my code
This is the error i am getting
Beta Was this translation helpful? Give feedback.
All reactions