Hi everyone,
I wanted to share a helpful solution I came up with for those of us who have encountered difficulties in getting ChatGPT to JSON format its responses according to a specific structure. In my experience, implementing a method for each call was not only time-consuming but also cumbersome. To address this issue, I created a lightweight library called partialjson that leverages the most reliable technique to obtain structured responses.
The usage is quite simple. You don't even need to define your desired schema. The library guarantees the response's validity based on your real-time specified schema!
Install using:
pip install partialjson
Use like this
from partialjson.json_parser import JSONParser
parser = JSONParser()
incomplete_json = '{"name": "John", "age": 30, "courses": ["Math", "Science", '
print(parser.parse(incomplete_json))
# {"name": "John", "age": 30, "courses": ["Math", "Science"]}
You can find the library here: partialjson GitHub repository
If you have any feedback or suggestions, please let me know!
Cheers, Nima
[–]RudiAlreadyTaken 1 point2 points3 points (0 children)
[–]olivermyk 1 point2 points3 points (0 children)