Hello, Iām looking for a response_format doing this:
response_format: { type: ājson_listā },
Any ideas on how to do it? The purpose is to return list with consistently valid JSON format to be parsed after, for now Iām just adding tokens in the prompt to achieve this result.
Iām not aware that ājson_listā is a valid response format.
I think if you want to do what youāre asking, youāll need to try one of these approaches:
Use json_object and prompt for an array in the result. For example, include something like, āReturn a list of Xā in your prompt. Then you should get an array object in your JSON.
Use function call. This will give you more control. You can define JSON Schema that specifies an array attribute to guarantee getting back an array.
thanks, implicite description of the expected result in the system and user prompt still seems to be an ideal solution at the moment, without the use of the json_object param.
I have been using response_format={ātypeā: ājson_objectā},
but it ends up adding a bunch of new line and tab characters (\n and \t) in the end.
This is too unclean and not really a valid json object. I am using gpt-4-1106-preview
\n \t are whitespace and valid in json, if you use a parser it will just remove it if its within the syntax (outside of the actual data), if its in the data, \n is newline, \t is tab, just do string replacements if you donāt want those characters in your data.