Hi,
I am having a tough time getting the API to return back consistent JSON when I provide it some key/value pairs and a JSON template.
These are the models and settings I’ve tried:
model: "gpt-4",
//model: "gpt-4-0125-preview",
//model: "gpt-3.5-turbo",
//model: "gpt-3.5-turbo-0125",
temperature: 0.1,
max_tokens: 512,
top_p: 1,
frequency_penalty: 0.75,
presence_penalty: 0,
};
My instructions to GPT are straight forward and the values do conform to the JSON, however, the JSON the API generates has issues most of the time, whereas the web GPT returns accurate results and valid JSON every time.
I typically request something like this:
Using this data: ${data}, make it conform to this JSON template. ${templateString}. Do not add any extra notes or comments to the json. Wrap all non null values in standard double quotes.
For example:
A subset of the data may look like this:
fname: john
lname: doe
dob: 01/01/2000
The template would look like this:
{
“firstname” : null,
“lastname”: null,
“dob”: null
}
The results are all over the place…
- sometimes it mixes straight quotes with curly quotes
- sometimes it mixes single quotes and double quotes
- some values it leaves unquoted
- braces or brackets can sometimes get surrounded by quotes
- extra commas
- extra quotes (mixed ones too)
- id numbers or zip codes starting with 0 are unquoted
etc…
So even if the JSON is bad, I take that bad JSON and pass it back into the API and tell it to correct any JSON formatting issues and return valid JSON.
The web GPT does it perfectly fine.
The API mangles it even more.
I’m confused and stuck here. I’ve tried a few different models and played with the temperature value to try to get it less ‘creative’. Still not consistent enough where I can depend on it to format some data into simple JSON. I’ve even made all the properties root level to avoid any complex nesting.
Any help or guidance appreciated.
Thanks
A