Is it possible to ensure the same output format on different API calls?

I have a list of emotions. I need to get colors related to those emotions. I’ve tested several different prompts, and found one that works best for my needs.

Prompt:
'Create TypeScript emotionColor array that stores colors associated with emotions joy, anger.'

Response:

const emotionColor = {
  joy: ['yellow', 'orange', 'green'],
  anger: ['red', 'black']
};

I am testing this in the Playground with gpt-3.5.-turbo model.

The thing is, the response format will not always be the same. Sometimes I get just the code, and other times I get explanations and console logs. I only need the code.

Are there any ways to ensure same format response, or my best guess is to extract the code from text?

Thanks in advance.

Ah, just figured out that if I set the temperature to lower value, it will return the same response.

1 Like