Return a specific prompted JSON object via API

Hi there,

i am trying to get gpt via api call to return a specific json object.
in the webinterface this is working. but with an api call its not working.
Currently i am accessing gpt with this code in js:

try {
      const openAiStoryObject = await openai.chat.completions.create({
        messages: [
          {
            role: "user",
            content: squeezeStoryPrompt,
          },
        ],
        model: "gpt-4-1106-preview",
      });

can somebody help?

Hi and welcome to the Developer Forum!

If you want a specific JSON object returning, I create an example JSON structure with placeholders for the data as an example and place that in ### markers top and bottom to seperate it from the main prompt, then in the prompot say something to the effect of

"
###
{
  Some example JSON object 
}
###
Using the template above in ### markers, produce a JSON object that represents this data : 
{data_you_need_processed}"
2 Likes