You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ChatCompletioncompletion=client.CompleteChat("Say 'this is a test.'");
56
+
57
+
Console.WriteLine($"[ASSISTANT]: {completion}");
59
58
```
60
59
61
60
While you can pass your API key directly as a string, it is highly recommended to keep it in a secure location and instead access it via an environment variable or configuration file as shown above to avoid storing it in source control.
@@ -83,10 +82,7 @@ The library is organized into several namespaces corresponding to OpenAI feature
83
82
Every client method that performs a synchronous API call has an asynchronous variant in the same client class. For instance, the asynchronous variant of the `ChatClient`'s `CompleteChat` method is `CompleteChatAsync`. To rewrite the call above using the asynchronous counterpart, simply `await` the call to the corresponding async variant:
ChatCompletioncompletion=awaitclient.CompleteChatAsync("Say 'this is a test.'");
90
86
```
91
87
92
88
### Using the `OpenAIClient` class
@@ -119,41 +115,35 @@ When you request a chat completion, the default behavior is for the server to ge
119
115
The client library offers a convenient approach to working with streaming chat completions. If you wanted to re-write the example from the previous section using streaming, rather than calling the `ChatClient`'s `CompleteChat` method, you would call its `CompleteChatStreaming` method instead:
=client.CompleteChatStreaming("Say 'this is a test.'");
127
120
```
128
121
129
122
Notice that the returned value is a `ResultCollection<StreamingChatCompletionUpdate>` instance, which can be enumerated to process the streaming response chunks as they arrive:
Alternatively, you can do this asynchronously by calling the `CompleteChatStreamingAsync` method to get an `AsyncResultCollection<StreamingChatCompletionUpdate>` and enumerate it using `await foreach`:
0 commit comments