Skip to content

Commit f5224df

Browse files
committed
readme updates
1 parent 60e4c78 commit f5224df

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

README.md

+38-1
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,23 @@ Console.WriteLine(result);
2323
* [GPT Vision](#gpt-vision)
2424
* [Chat Endpoint](#chat-endpoint-requests)
2525
* [Conversation History Context Length Management](#Conversation-History-Context-Length-Management)
26+
* [JSON Mode](#json-mode)
2627
* [Completions API](#completions)
2728
* [Streaming completion results](#streaming)
2829
* [Embeddings API](#embeddings)
2930
* [Moderation API](#moderation)
3031
* [Files API](#files-for-fine-tuning)
3132
* [Image APIs (DALL-E)](#images)
33+
* [DALLE-E 3](#dall-e-3)
3234
* [Azure](#azure)
3335
* [Additional Documentation](#documentation)
3436
* [License](#license)
3537

3638
## Status
3739
[![OpenAI](https://badgen.net/nuget/v/OpenAI)](https://www.nuget.org/packages/OpenAI/)
3840

39-
Added and updated models as of December 11, 2023, including the new GPT-4 Vision, GPT-4 Turbo, and DALL-E 3. Support for text-to-speech, and the other new features shown at OpenAI DevDay will be coming soon, but are not yet implemented.
41+
Adds updated models as of December 11, 2023, including the new [GPT-4 Vision](#gpt-vision), GPT-4 Turbo, and [DALL-E 3](#dall-e-3). Adds [json result format](#json-mode). Fixes chat result streaming bug.
42+
Support for text-to-speech, and the other new features shown at OpenAI DevDay will be coming soon, but are not yet implemented.
4043

4144
## Requirements
4245

@@ -225,6 +228,38 @@ It returns a `ChatResult` which is mostly metadata, so use its `.ToString()` met
225228

226229
There's also an async streaming API which works similarly to the [Completions endpoint streaming results](#streaming).
227230

231+
#### JSON Mode
232+
233+
With the new `Model.GPT4_Turbo` or `gpt-3.5-turbo-1106` models, you can set the `ChatRequest.ResponseFormat` to `ChatRequest.ResponseFormats.JsonObject` to enable JSON mode.
234+
When JSON mode is enabled, the model is constrained to only generate strings that parse into valid JSON object.
235+
See https://platform.openai.com/docs/guides/text-generation/json-mode for more details.
236+
237+
```csharp
238+
ChatRequest chatRequest = new ChatRequest()
239+
{
240+
Model = model,
241+
Temperature = 0.0,
242+
MaxTokens = 500,
243+
ResponseFormat = ChatRequest.ResponseFormats.JsonObject,
244+
Messages = new ChatMessage[] {
245+
new ChatMessage(ChatMessageRole.System, "You are a helpful assistant designed to output JSON."),
246+
new ChatMessage(ChatMessageRole.User, "Who won the world series in 2020? Return JSON of a 'wins' dictionary with the year as the numeric key and the winning team as the string value.")
247+
}
248+
};
249+
250+
var results = await api.Chat.CreateChatCompletionAsync(chatRequest);
251+
Console.WriteLine(results);
252+
/* prints:
253+
{
254+
"wins": {
255+
2020: "Los Angeles Dodgers"
256+
}
257+
}
258+
*/
259+
```
260+
261+
262+
228263
### Completions API
229264
Completions are considered legacy by OpenAI. The Completion API is accessed via `OpenAIAPI.Completions`:
230265

@@ -339,6 +374,8 @@ Console.WriteLine(result.Data[0].Url);
339374

340375
The image result contains a URL for an online image or a base64-encoded image, depending on the ImageGenerationRequest.ResponseFormat (url is the default).
341376

377+
#### DALL-E 3
378+
342379
Use DALL-E 3 like this:
343380

344381
```csharp

0 commit comments

Comments
 (0)