JSON structured output is good, but the user has to wait until the ENTIRE response is complete in order to parse the response and use it in an application. I want to update the user as SOON as data is available, rather than showing a loading ui for them while we get the full output. To solve this issue, I think Jsonl/NDJson (newline-delimited json) would be a really good fit, however, I’m getting mixed results from chat GPT, some lines return just fine, while others miss the last “}” which fails parsing. Here is my config, using the javascript package:
const stream = await openAI.chat.completions.create({
model: 'gpt-4o-mini',
messages,
stream: true,
max_tokens: 2500,
})
Here is the prompt
I want you to act as a landing page copy generator, who can create persuasive and compelling copy that effectively communicates the value of a product or service, encourages visitors to take action, and ultimately converts them into leads or customers. Ensure the copy is concise, clear, and targeted towards the intended audience in the tone of voice that resonates most with them. Use the users prompt for all the generated results. The business description is as follows:
“A mobile app for wood workers to journal their projects”
Use the json below for getting prompts for the section of the page. The values of the fields in following json object on each are the the prompts I want you to answer:
{
“cbe4e030-80b0-44bf-b05d-312afe75b924”: “Write a headline for for the company. The headline should emphasize the value, result or transformation that the customer will receive from this service. This will be the first thing the customer sees so it must be compelling and captivating.”,
“515d097b-08b2-4f3f-b971-debbc660eeed”: “create a list of 3 items for the following prompt "Write a question and answer for the FAQ section. It should be a frequently asked question by customers for this company along with the answers to those questions." and this value should be a a list of json objects using this these keys for each object [question,answer].”,
“6847b0a7-8914-49b7-9823-ce9ce051a1c9”: “Write a title for a benefit/features section.”
}
Please provide your response in the NDJSON (newline delimited json) format. Each line should be a complete JSON object with key and value fields. This will be used by code to parse the json output of each line, don’t add any extra words, comments, or extra syntax that would break a json parser. Here is an example:
Example Input:
{“key1FromJson”:“question 0 here”,“key2FromJson”:“create a list of 2 items for the following prompt "write and FAQ question and answer" and this value should as a list of json objects using this these keys for each object.”}
Example Output:
{“key1FromJson”:“answer 0 here”}
{“key2FromJson”:[{“question”:“phone home?”,“answer”:“yes ET does that.”},{“question”:“where do i go?”,“answer”:“go home.”}]}