@@ -5,7 +5,7 @@ author: travisw
5
5
ms.author : travisw
6
6
ms.service : azure-ai-openai
7
7
ms.topic : include
8
- ms.date : 03/07/2024
8
+ ms.date : 01/09/2025
9
9
---
10
10
11
11
[ !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
17
17
### Without response streaming
18
18
19
19
``` csharp
20
- using Azure ;
20
+ using System ;
21
21
using Azure .AI .OpenAI ;
22
+ using System .ClientModel ;
22
23
using Azure .AI .OpenAI .Chat ;
23
24
using OpenAI .Chat ;
24
- using System .Text .Json ;
25
25
using static System .Environment ;
26
26
27
27
string azureOpenAIEndpoint = GetEnvironmentVariable (" AZURE_OPENAI_ENDPOINT" );
@@ -31,36 +31,38 @@ string searchEndpoint = GetEnvironmentVariable("AZURE_AI_SEARCH_ENDPOINT");
31
31
string searchKey = GetEnvironmentVariable (" AZURE_AI_SEARCH_API_KEY" );
32
32
string searchIndex = GetEnvironmentVariable (" AZURE_AI_SEARCH_INDEX" );
33
33
34
- #pragma warning disable AOAI001
35
34
AzureOpenAIClient azureClient = new (
36
- new Uri (azureOpenAIEndpoint ),
37
- new AzureKeyCredential (azureOpenAIKey ));
35
+ new Uri (azureOpenAIEndpoint ),
36
+ new ApiKeyCredential (azureOpenAIKey ));
38
37
ChatClient chatClient = azureClient .GetChatClient (deploymentName );
39
38
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
+
40
43
ChatCompletionOptions options = new ();
41
44
options .AddDataSource (new AzureSearchChatDataSource ()
42
45
{
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 ),
46
49
});
47
50
48
51
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 );
52
56
53
- Console .WriteLine (completion .Content [0 ].Text );
54
-
55
- AzureChatMessageContext onYourDataContext = completion .GetAzureMessageContext ();
57
+ ChatMessageContext onYourDataContext = completion .GetMessageContext ();
56
58
57
59
if (onYourDataContext ? .Intent is not null )
58
60
{
59
- Console .WriteLine ($" Intent: {onYourDataContext .Intent }" );
61
+ Console .WriteLine ($" Intent: {onYourDataContext .Intent }" );
60
62
}
61
- foreach (AzureChatCitation citation in onYourDataContext ? .Citations ?? [])
63
+ foreach (ChatCitation citation in onYourDataContext ? .Citations ?? [])
62
64
{
63
- Console .WriteLine ($" Citation: {citation .Content }" );
65
+ Console .WriteLine ($" Citation: {citation .Content }" );
64
66
}
65
67
```
66
68
0 commit comments