Skip to content

Commit 009933b

Browse files
committed
updates
1 parent aaece61 commit 009933b

File tree

4 files changed

+114
-87
lines changed

4 files changed

+114
-87
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ dotnet run program.cs
7878
## Output
7979

8080
```output
81-
Yes, many of the Azure AI services support customer managed keys. Some examples include Text Analytics, Speech Services, and Translator. However, it's important to note that not all services support customer managed keys, so it's best to check the documentation for each individual service to see if it is supported.
81+
Assistant : Yes, many other Azure AI services also support customer managed keys, including Azure Cognitive Services, Azure Machine Learning, and Azure Databricks. By using customer managed keys, you can retain complete control over your encryption keys and provide an additional layer of security for your AI assets.
8282
```
8383

8484
This will wait until the model has generated its entire response before printing the results. Alternatively, if you want to asynchronously stream the response and print the results, you can replace the contents of *program.cs* with the code in the next example.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ dotnet run
108108
The URL of the generated image is printed to the console.
109109

110110
```console
111-
https://dalleproduse.blob.core.windows.net/private/images/552c5522-af4a-4877-a19c-400fac04a422/generated_00.png?se=2023-08-17T16%3A54%3A40Z&sig=XGCIx9r0WvWTJ0LL%2FJGymo2WYp4FDbSQNNrGRUnnUzI%3D&ske=2023-08-19T01%3A10%3A14Z&skoid=09ba021e-c417-441c-b203-c81e5dcd7b7f&sks=b&skt=2023-08-12T01%3A10%3A14Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02
111+
https://dalleproduse.blob.core.windows.net/private/images/b7ac5e55-f1f8-497a-8d0e-8f51446bf538/generated_00.png?se=2024-07-12T13%3A47%3A56Z&sig=Zri37iYVTVtc52qzTFBOqPgSHvXwEhcO86Smv2ojB%2FE%3D&ske=2024-07-17T12%3A15%3A44Z&skoid=09ba021e-c417-441c-b203-c81e5dcd7b7f&sks=b&skt=2024-07-10T12%3A15%3A44Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02
112112
```
113113

114114
> [!NOTE]

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

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,53 @@ ms.date: 07/26/2023
2626
2727
## Set up
2828

29-
[!INCLUDE [Create a new .NET application](./dotnet-new-application.md)]
29+
### Create a new .NET Core application
30+
31+
In a console window (such as cmd, PowerShell, or Bash), use the `dotnet new` command to create a new console app with the name `azure-openai-quickstart`. This command creates a simple "Hello World" project with a single C# source file: *Program.cs*.
32+
33+
```dotnetcli
34+
dotnet new console -n azure-openai-quickstart
35+
```
36+
37+
Change your directory to the newly created app folder. You can build the application with:
38+
39+
```dotnetcli
40+
dotnet build
41+
```
42+
43+
The build output should contain no warnings or errors.
44+
45+
```output
46+
...
47+
Build succeeded.
48+
0 Warning(s)
49+
0 Error(s)
50+
...
51+
```
52+
53+
Install the OpenAI .NET client library with:
54+
55+
```console
56+
dotnet add package Azure.AI.OpenAI --version 1.0.0-beta.17
57+
```
58+
59+
> [!NOTE]
60+
> The completions API is only available in version `1.0.0-beta.17` and earlier of the `Azure.AI.OpenAI` client library. For the latest `2.0.0` and higher version of `Azure.AI.OpenAI`, the recommended approach to generate completions is to use the [chat completions API](chatgpt-dotnet).
3061
3162
[!INCLUDE [get-key-endpoint](get-key-endpoint.md)]
3263

3364
[!INCLUDE [environment-variables](environment-variables.md)]
3465

35-
3666
> [!div class="nextstepaction"]
3767
> [I ran into an issue with the setup.](https://microsoft.qualtrics.com/jfe/form/SV_0Cl5zkG3CnDjq6O?PLanguage=DOTNET&Pillar=AOAI&Product=gpt&Page=quickstart&Section=Set-up)
3868
3969
## Create a sample application
4070

4171
From the project directory, open the *program.cs* file and replace with the following code:
4272

73+
> [!NOTE]
74+
> The completions API is only available
75+
4376
```csharp
4477
using Azure;
4578
using Azure.AI.OpenAI;
@@ -48,20 +81,19 @@ using static System.Environment;
4881
string endpoint = GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
4982
string key = GetEnvironmentVariable("AZURE_OPENAI_API_KEY");
5083

51-
AzureOpenAIClient azureClient = new(
84+
var client = new OpenAIClient(
5285
new Uri(endpoint),
5386
new AzureKeyCredential(key));
54-
ChatClient chatClient = azureClient.GetChatClient("gpt-35-turbo");
5587

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-
]);
88+
CompletionsOptions completionsOptions = new()
89+
{
90+
DeploymentName = "gpt-35-turbo-instruct",
91+
Prompts = { "When was Microsoft founded?" },
92+
};
6393

64-
Console.WriteLine($"{completion.Role}: {completion.Content[0].Text}");
94+
Response<Completions> completionsResponse = client.GetCompletions(completionsOptions);
95+
string completion = completionsResponse.Value.Choices[0].Text;
96+
Console.WriteLine($"Chatbot: {completion}");
6597
```
6698

6799
> [!IMPORTANT]

articles/ai-services/openai/includes/use-your-data-dotnet.md

Lines changed: 68 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -29,57 +29,37 @@ string searchEndpoint = GetEnvironmentVariable("AZURE_AI_SEARCH_ENDPOINT");
2929
string searchKey = GetEnvironmentVariable("AZURE_AI_SEARCH_API_KEY");
3030
string searchIndex = GetEnvironmentVariable("AZURE_AI_SEARCH_INDEX");
3131

32+
#pragma warning disable AOAI001
33+
AzureOpenAIClient azureClient = new(
34+
new Uri(azureOpenAIEndpoint),
35+
new AzureKeyCredential(azureOpenAIKey));
36+
ChatClient chatClient = azureClient.GetChatClient(deploymentName);
37+
38+
ChatCompletionOptions options = new();
39+
options.AddDataSource(new AzureSearchChatDataSource()
40+
{
41+
Endpoint = new Uri(searchEndpoint),
42+
IndexName = searchIndex,
43+
Authentication = DataSourceAuthentication.FromApiKey(searchKey),
44+
});
3245

33-
var client = new OpenAIClient(new Uri(azureOpenAIEndpoint), new AzureKeyCredential(azureOpenAIKey));
46+
ChatCompletion completion = chatClient.CompleteChat(
47+
[
48+
new UserChatMessage("What are my available health plans?"),
49+
], options);
50+
51+
Console.WriteLine(completion.Content[0].Text);
52+
53+
AzureChatMessageContext onYourDataContext = completion.GetAzureMessageContext();
3454

35-
var chatCompletionsOptions = new ChatCompletionsOptions()
55+
if (onYourDataContext?.Intent is not null)
3656
{
37-
Messages =
38-
{
39-
new ChatRequestUserMessage("What are my available health plans?"),
40-
},
41-
AzureExtensionsOptions = new AzureChatExtensionsOptions()
42-
{
43-
Extensions =
44-
{
45-
new AzureCognitiveSearchChatExtensionConfiguration()
46-
{
47-
SearchEndpoint = new Uri(searchEndpoint),
48-
Key = searchKey,
49-
IndexName = searchIndex,
50-
},
51-
}
52-
},
53-
DeploymentName = deploymentName
54-
};
55-
56-
Response<ChatCompletions> response = client.GetChatCompletions(chatCompletionsOptions);
57-
58-
ChatResponseMessage responseMessage = response.Value.Choices[0].Message;
59-
60-
Console.WriteLine($"Message from {responseMessage.Role}:");
61-
Console.WriteLine("===");
62-
Console.WriteLine(responseMessage.Content);
63-
Console.WriteLine("===");
64-
65-
Console.WriteLine($"Context information (e.g. citations) from chat extensions:");
66-
Console.WriteLine("===");
67-
foreach (ChatResponseMessage contextMessage in responseMessage.AzureExtensionsContext.Messages)
57+
Console.WriteLine($"Intent: {onYourDataContext.Intent}");
58+
}
59+
foreach (AzureChatCitation citation in onYourDataContext?.Citations ?? [])
6860
{
69-
string contextContent = contextMessage.Content;
70-
try
71-
{
72-
var contextMessageJson = JsonDocument.Parse(contextMessage.Content);
73-
contextContent = JsonSerializer.Serialize(contextMessageJson, new JsonSerializerOptions()
74-
{
75-
WriteIndented = true,
76-
});
77-
}
78-
catch (JsonException)
79-
{}
80-
Console.WriteLine($"{contextMessage.Role}: {contextContent}");
61+
Console.WriteLine($"Citation: {citation.Content}");
8162
}
82-
Console.WriteLine("===");
8363
```
8464

8565
> [!IMPORTANT]
@@ -92,30 +72,16 @@ dotnet run program.cs
9272
## Output
9373

9474
```output
95-
Answer from assistant:
96-
===
97-
The available health plans in the Contoso Electronics plan and benefit packages are the Northwind Health Plus and Northwind Standard plans [^1^].
98-
===
99-
Context information (e.g. citations) from chat extensions:
100-
===
101-
tool: {
102-
"citations": [
103-
{
104-
"content": "...",
105-
"id": null,
106-
"title": "...",
107-
"filepath": "...",
108-
"url": "...",
109-
"metadata": {
110-
"chunking": "orignal document size=1011. Scores=3.6390076 and None.Org Highlight count=38."
111-
},
112-
"chunk_id": "2"
113-
},
114-
...
115-
],
116-
"intent": "[\u0022What are my available health plans?\u0022]"
117-
}
118-
===
75+
Contoso Electronics offers two health plans: Northwind Health Plus and Northwind Standard [doc1]. Northwind Health Plus is a comprehensive plan that provides coverage for medical, vision, and dental services, prescription drug coverage, mental health and substance abuse coverage, and coverage for preventive care services. It also offers coverage for emergency services, both in-network and out-of-network. On the other hand, Northwind Standard is a basic plan that provides coverage for medical, vision, and dental services, prescription drug coverage, and coverage for preventive care services. However, it does not offer coverage for emergency services, mental health and substance abuse coverage, or out-of-network services [doc1].
76+
77+
Intent: ["What are the available health plans?", "List of health plans available", "Health insurance options", "Types of health plans offered"]
78+
79+
Citation:
80+
Contoso Electronics plan and benefit packages
81+
82+
Thank you for your interest in the Contoso electronics plan and benefit packages. Use this document to
83+
84+
learn more about the various options available to you...// Omitted for brevity
11985
```
12086

12187
This will wait until the model has generated its entire response before printing the results. Alternatively, if you want to asynchronously stream the response and print the results, you can replace the contents of *Program.cs* with the code in the next example.
@@ -136,6 +102,8 @@ string searchEndpoint = GetEnvironmentVariable("AZURE_AI_SEARCH_ENDPOINT");
136102
string searchKey = GetEnvironmentVariable("AZURE_AI_SEARCH_API_KEY");
137103
string searchIndex = GetEnvironmentVariable("AZURE_AI_SEARCH_INDEX");
138104

105+
#pragma warning disable AOAI001
106+
139107
AzureOpenAIClient azureClient = new(
140108
new Uri(azureOpenAIEndpoint),
141109
new AzureKeyCredential(azureOpenAIKey));
@@ -149,12 +117,39 @@ options.AddDataSource(new AzureSearchChatDataSource()
149117
Authentication = DataSourceAuthentication.FromApiKey(searchKey),
150118
});
151119

152-
ChatCompletion completion = chatClient.CompleteChat(
120+
var chatUpdates = chatClient.CompleteChatStreamingAsync(
153121
[
154-
new UserChatMessage("What are the best-selling Contoso products this month?"),
122+
new UserChatMessage("What are my available health plans?"),
155123
], options);
156124

157-
Console.WriteLine(completion.Content[0].Text);
125+
AzureChatMessageContext onYourDataContext = null;
126+
await foreach (var chatUpdate in chatUpdates)
127+
{
128+
if (chatUpdate.Role.HasValue)
129+
{
130+
Console.WriteLine($"{chatUpdate.Role}: ");
131+
}
132+
133+
foreach (var contentPart in chatUpdate.ContentUpdate)
134+
{
135+
Console.Write(contentPart.Text);
136+
}
137+
138+
if (onYourDataContext == null)
139+
{
140+
onYourDataContext = chatUpdate.GetAzureMessageContext();
141+
}
142+
}
143+
144+
Console.WriteLine();
145+
if (onYourDataContext?.Intent is not null)
146+
{
147+
Console.WriteLine($"Intent: {onYourDataContext.Intent}");
148+
}
149+
foreach (AzureChatCitation citation in onYourDataContext?.Citations ?? [])
150+
{
151+
Console.Write($"Citation: {citation.Content}");
152+
}
158153
```
159154

160155
> [!div class="nextstepaction"]

0 commit comments

Comments
 (0)