Skip to content

Commit 571167c

Browse files
committed
initial commit
1 parent f0ab69d commit 571167c

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed

articles/ai-services/openai/includes/chatgpt-dotnet.md

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,22 @@ using static System.Environment;
5050
string endpoint = GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
5151
string key = GetEnvironmentVariable("AZURE_OPENAI_API_KEY");
5252

53-
OpenAIClient client = new(new Uri(endpoint), new AzureKeyCredential(key));
54-
55-
var chatCompletionsOptions = new ChatCompletionsOptions()
56-
{
57-
DeploymentName = "gpt-35-turbo", //This must match the custom deployment name you chose for your model
58-
Messages =
59-
{
60-
new ChatRequestSystemMessage("You are a helpful assistant."),
61-
new ChatRequestUserMessage("Does Azure OpenAI support customer managed keys?"),
62-
new ChatRequestAssistantMessage("Yes, customer managed keys are supported by Azure OpenAI."),
63-
new ChatRequestUserMessage("Do other Azure AI services support this too?"),
64-
},
65-
MaxTokens = 100
66-
};
67-
68-
Response<ChatCompletions> response = client.GetChatCompletions(chatCompletionsOptions);
69-
70-
Console.WriteLine(response.Value.Choices[0].Message.Content);
71-
72-
Console.WriteLine();
53+
AzureOpenAIClient azureClient = new(
54+
new Uri(endpoint),
55+
new AzureKeyCredential(key));
56+
57+
// This must match the custom deployment name you chose for your model
58+
ChatClient chatClient = azureClient.GetChatClient("gpt-35-turbo");
59+
60+
ChatCompletion completion = chatClient.CompleteChat(
61+
[
62+
new SystemChatMessage("You are a helpful assistant that talks like a pirate."),
63+
new UserChatMessage("Does Azure OpenAI support customer managed keys?"),
64+
new AssistantChatMessage("Yes, customer managed keys are supported by Azure OpenAI"),
65+
new UserChatMessage("Do other Azure AI services support this too?")
66+
]);
67+
68+
Console.WriteLine($"{completion.Role}: {completion.Content[0].Text}");
7369
```
7470

7571
> [!IMPORTANT]
@@ -97,30 +93,31 @@ using static System.Environment;
9793
string endpoint = GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
9894
string key = GetEnvironmentVariable("AZURE_OPENAI_API_KEY");
9995

100-
OpenAIClient client = new(new Uri(endpoint), new AzureKeyCredential(key));
96+
AzureOpenAIClient azureClient = new(
97+
new Uri(endpoint),
98+
new AzureKeyCredential(key));
10199

102-
var chatCompletionsOptions = new ChatCompletionsOptions()
103-
{
104-
DeploymentName= "gpt-35-turbo", //This must match the custom deployment name you chose for your model
105-
Messages =
106-
{
107-
new ChatRequestSystemMessage("You are a helpful assistant."),
108-
new ChatRequestUserMessage("Does Azure OpenAI support customer managed keys?"),
109-
new ChatRequestAssistantMessage("Yes, customer managed keys are supported by Azure OpenAI."),
110-
new ChatRequestUserMessage("Do other Azure AI services support this too?"),
111-
},
112-
MaxTokens = 100
113-
};
114-
115-
await foreach (StreamingChatCompletionsUpdate chatUpdate in client.GetChatCompletionsStreaming(chatCompletionsOptions))
100+
// This must match the custom deployment name you chose for your model
101+
ChatClient chatClient = azureClient.GetChatClient("trubo");
102+
103+
var chatUpdates = chatClient.CompleteChatStreamingAsync(
104+
[
105+
new SystemChatMessage("You are a helpful assistant that talks like a pirate."),
106+
new UserChatMessage("Does Azure OpenAI support customer managed keys?"),
107+
new AssistantChatMessage("Yes, customer managed keys are supported by Azure OpenAI"),
108+
new UserChatMessage("Do other Azure AI services support this too?")
109+
]);
110+
111+
await foreach(var chatUpdate in chatUpdates)
116112
{
117113
if (chatUpdate.Role.HasValue)
118114
{
119-
Console.Write($"{chatUpdate.Role.Value.ToString().ToUpperInvariant()}: ");
115+
Console.Write($"{chatUpdate.Role} : ");
120116
}
121-
if (!string.IsNullOrEmpty(chatUpdate.ContentUpdate))
117+
118+
foreach(var contentPart in chatUpdate.ContentUpdate)
122119
{
123-
Console.Write(chatUpdate.ContentUpdate);
120+
Console.Write(contentPart.Text);
124121
}
125122
}
126123
```

articles/ai-services/openai/includes/dotnet.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ms.date: 07/26/2023
1919
- Access granted to the Azure OpenAI service in the desired Azure subscription.
2020
Currently, access to this service is granted only by application. You can apply for access to Azure OpenAI Service by completing the form at [https://aka.ms/oai/access](https://aka.ms/oai/access?azure-portal=true).
2121
- The current version of <a href="https://dotnet.microsoft.com/download/dotnet-core" target="_blank">.NET Core</a>
22-
- An Azure OpenAI Service resource with the `gpt-35-turbo-instruct` model deployed. For more information about model deployment, see the [resource deployment guide](../how-to/create-resource.md).
22+
- An Azure OpenAI Service resource with the `gpt-35-turbo` model deployed. For more information about model deployment, see the [resource deployment guide](../how-to/create-resource.md).
2323

2424
> [!div class="nextstepaction"]
2525
> [I ran into an issue with the prerequisites.](https://microsoft.qualtrics.com/jfe/form/SV_0Cl5zkG3CnDjq6O?PLanguage=DOTNET&Pillar=AOAI&Product=gpt&Page=quickstart&Section=Prerequisites)
@@ -48,17 +48,20 @@ using static System.Environment;
4848
string endpoint = GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
4949
string key = GetEnvironmentVariable("AZURE_OPENAI_API_KEY");
5050

51-
var client = new OpenAIClient(new Uri(endpoint), new AzureKeyCredential(key));
51+
AzureOpenAIClient azureClient = new(
52+
new Uri(endpoint),
53+
new AzureKeyCredential(key));
54+
ChatClient chatClient = azureClient.GetChatClient("gpt-35-turbo");
5255

53-
CompletionsOptions completionsOptions = new()
54-
{
55-
DeploymentName = "gpt-35-turbo-instruct",
56-
Prompts = { "When was Microsoft founded?" },
57-
};
56+
ChatCompletion completion = chatClient.CompleteChat(
57+
[
58+
// System messages represent instructions or other guidance about how the assistant should behave
59+
new SystemChatMessage("You are a helpful assistant that talks like a pirate."),
60+
// User messages represent user input, whether historical or the most recen tinput
61+
new UserChatMessage("When was Microsoft founded?")
62+
]);
5863

59-
Response<Completions> completionsResponse = client.GetCompletions(completionsOptions);
60-
string completion = completionsResponse.Value.Choices[0].Text;
61-
Console.WriteLine($"Chatbot: {completion}");
64+
Console.WriteLine($"{completion.Role}: {completion.Content[0].Text}");
6265
```
6366

6467
> [!IMPORTANT]

0 commit comments

Comments
 (0)