Skip to content

Commit be4b7ad

Browse files
committed
updating C# code
1 parent 4f0ecd8 commit be4b7ad

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: travisw
55
ms.author: travisw
66
ms.service: azure-ai-openai
77
ms.topic: include
8-
ms.date: 03/07/2024
8+
ms.date: 01/09/2025
99
---
1010

1111
[!INCLUDE [Set up required variables](./use-your-data-common-variables.md)]
@@ -17,11 +17,11 @@ From the project directory, open the *Program.cs* file and replace its contents
1717
### Without response streaming
1818

1919
```csharp
20-
using Azure;
20+
using System;
2121
using Azure.AI.OpenAI;
22+
using System.ClientModel;
2223
using Azure.AI.OpenAI.Chat;
2324
using OpenAI.Chat;
24-
using System.Text.Json;
2525
using static System.Environment;
2626

2727
string azureOpenAIEndpoint = GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
@@ -31,36 +31,38 @@ string searchEndpoint = GetEnvironmentVariable("AZURE_AI_SEARCH_ENDPOINT");
3131
string searchKey = GetEnvironmentVariable("AZURE_AI_SEARCH_API_KEY");
3232
string searchIndex = GetEnvironmentVariable("AZURE_AI_SEARCH_INDEX");
3333

34-
#pragma warning disable AOAI001
3534
AzureOpenAIClient azureClient = new(
36-
new Uri(azureOpenAIEndpoint),
37-
new AzureKeyCredential(azureOpenAIKey));
35+
new Uri(azureOpenAIEndpoint),
36+
new ApiKeyCredential(azureOpenAIKey));
3837
ChatClient chatClient = azureClient.GetChatClient(deploymentName);
3938

39+
// Extension methods to use data sources with options are subject to SDK surface changes. Suppress the
40+
// warning to acknowledge and this and use the subject-to-change AddDataSource method.
41+
#pragma warning disable AOAI001
42+
4043
ChatCompletionOptions options = new();
4144
options.AddDataSource(new AzureSearchChatDataSource()
4245
{
43-
Endpoint = new Uri(searchEndpoint),
44-
IndexName = searchIndex,
45-
Authentication = DataSourceAuthentication.FromApiKey(searchKey),
46+
Endpoint = new Uri(searchEndpoint),
47+
IndexName = searchIndex,
48+
Authentication = DataSourceAuthentication.FromApiKey(searchKey),
4649
});
4750

4851
ChatCompletion completion = chatClient.CompleteChat(
49-
[
50-
new UserChatMessage("What are my available health plans?"),
51-
], options);
52+
[
53+
new UserChatMessage("What health plans are available?"),
54+
],
55+
options);
5256

53-
Console.WriteLine(completion.Content[0].Text);
54-
55-
AzureChatMessageContext onYourDataContext = completion.GetAzureMessageContext();
57+
ChatMessageContext onYourDataContext = completion.GetMessageContext();
5658

5759
if (onYourDataContext?.Intent is not null)
5860
{
59-
Console.WriteLine($"Intent: {onYourDataContext.Intent}");
61+
Console.WriteLine($"Intent: {onYourDataContext.Intent}");
6062
}
61-
foreach (AzureChatCitation citation in onYourDataContext?.Citations ?? [])
63+
foreach (ChatCitation citation in onYourDataContext?.Citations ?? [])
6264
{
63-
Console.WriteLine($"Citation: {citation.Content}");
65+
Console.WriteLine($"Citation: {citation.Content}");
6466
}
6567
```
6668

articles/ai-services/openai/use-your-data-quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.custom: devx-track-dotnet, devx-track-extended-java, devx-track-js, devx-trac
88
ms.topic: quickstart
99
author: aahill
1010
ms.author: aahi
11-
ms.date: 10/22/2024
11+
ms.date: 01/09/2025
1212
recommendations: false
1313
zone_pivot_groups: openai-use-your-data
1414
---

0 commit comments

Comments
 (0)