Closed redclock closed 7 months ago
Supports specifying the response return format, either JSON or text. Address #105
See OpenAI API document of response_format parameter GPT-4-turbo and GPT-3.5-turbo-1106 support this parameter.
Specifying the return result as JSON is useful for workflows.
Code sample:
_task = _openAi.CreateChatCompletion(new CreateChatCompletionRequest() { Model = "gpt-3.5-turbo", Messages = new List<ChatMessage>() { new() {Role = "system", Content = "Output JSON"}, new() {Role = "user", Content = "What's US and China's population?"} }, ResponseFormat = ResponseFormat.JsonObject });
Response:
{ "country_populations": { "United States": "331.9 million", "China": "1.41 billion" } }
If you removed the ResponseFormat = ResponseFormat.JsonObject, the response becomes:
ResponseFormat = ResponseFormat.JsonObject
As of September 2021, the population of the United States is approximately 331 million and the population of China is approximately 1.4 billion.
Note: According to the document, when using JSON mode, you must also instruct the model to produce JSON yourself via a system or user message.
I pushed one more commit in this branch mistakenly, so I closed this PR.
New PR here: https://github.com/srcnalt/OpenAI-Unity/pull/116
Supports specifying the response return format, either JSON or text. Address #105
See OpenAI API document of response_format parameter GPT-4-turbo and GPT-3.5-turbo-1106 support this parameter.
Specifying the return result as JSON is useful for workflows.
Code sample:
Response:
If you removed the
ResponseFormat = ResponseFormat.JsonObject
, the response becomes:Note: According to the document, when using JSON mode, you must also instruct the model to produce JSON yourself via a system or user message.