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
The sample code in this quickstart uses Microsoft Entra ID for the recommended keyless authentication. If you prefer to use an API key, you can replace the `DefaultAzureCredential` object with a`AzureKeyCredential` object.
67
+
The sample code in this quickstart uses Microsoft Entra ID for the recommended keyless authentication. If you prefer to use an API key, you can replace the `DefaultAzureCredential` object with an`AzureKeyCredential` object.
68
68
69
69
#### [Microsoft Entra ID](#tab/keyless)
70
70
@@ -79,9 +79,9 @@ AzureOpenAIClient openAIClient = new AzureOpenAIClient(new Uri(endpoint), new Az
79
79
```
80
80
---
81
81
82
-
To create an assistant, you need to:
82
+
To run the quickstart, follow these steps:
83
83
84
-
1. Update the `Program.cs`file with the following code to create an assistant:
84
+
1. Replace the contents of `Program.cs` with the following code and update the placeholder values with your own.
The sample code in this quickstart uses Microsoft Entra ID for the recommended keyless authentication. If you prefer to use an API key, you can replace the `DefaultAzureCredential` object with a`AzureKeyCredential` object.
65
+
The sample code in this quickstart uses Microsoft Entra ID for the recommended keyless authentication. If you prefer to use an API key, you can replace the `DefaultAzureCredential` object with an`AzureKeyCredential` object.
66
66
67
67
#### [Microsoft Entra ID](#tab/keyless)
68
68
@@ -81,9 +81,9 @@ You can use streaming or non-streaming to get the chat completion. The following
81
81
82
82
### Without response streaming
83
83
84
-
To use the non-streaming method:
84
+
To run the quickstart, follow these steps:
85
85
86
-
1. Update the `Program.cs`file with the following code:
86
+
1. Replace the contents of `Program.cs` with the following code and update the placeholder values with your own.
87
87
88
88
```csharp
89
89
using Azure;
@@ -127,12 +127,13 @@ To use the non-streaming method:
127
127
Assistant: Arrr, ye be askin’ a fine question, matey! Aye, several Azure AI services support customer-managed keys (CMK)! This lets ye take the wheel and secure yer data with encryption keys stored in Azure Key Vault. Services such as Azure Machine Learning, Azure Cognitive Search, and others also offer CMK fer data protection. Always check the specific service's documentation fer the latest updates, as features tend to shift swifter than the tides, aye!
128
128
```
129
129
130
-
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.
130
+
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.
131
131
132
132
### Async with streaming
133
133
134
-
To use the streaming method:
135
-
1. Update the `Program.cs` file with the following code:
134
+
To run the quickstart, follow these steps:
135
+
136
+
1. Replace the contents of `Program.cs` with the following code and update the placeholder values with your own.
Copy file name to clipboardExpand all lines: articles/ai-services/openai/includes/dall-e-dotnet.md
+74-56Lines changed: 74 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ ms.service: azure-ai-openai
8
8
ms.topic: include
9
9
author: PatrickFarley
10
10
ms.author: pafarley
11
-
ms.date: 06/26/2024
11
+
ms.date: 3/11/2025
12
12
---
13
13
14
14
Use this guide to get started generating images with the Azure OpenAI SDK for C#.
@@ -21,83 +21,101 @@ Use this guide to get started generating images with the Azure OpenAI SDK for C#
21
21
- The [.NET 7 SDK](https://dotnet.microsoft.com/download/dotnet/7.0)
22
22
- An Azure OpenAI resource created in a supported region (see [Region availability](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability)). For more information, see [Create a resource and deploy a model with Azure OpenAI](../how-to/create-resource.md).
23
23
24
+
### Microsoft Entra ID prerequisites
24
25
25
-
## Setup
26
+
For the recommended keyless authentication with Microsoft Entra ID, you need to:
27
+
- Install the [Azure CLI](/cli/azure/install-azure-cli) used for keyless authentication with Microsoft Entra ID.
28
+
- Assign the `Cognitive Services User` role to your user account. You can assign roles in the Azure portal under **Access control (IAM)** > **Add role assignment**.
1. Create a new folder `vision-quickstart` to contain the application and open Visual Studio Code in that folder with the following command:
30
33
34
+
```shell
35
+
mkdir vision-quickstart &&cd vision-quickstart
36
+
```
31
37
32
-
##Create a new .NET Core application
38
+
1. Create a new console application with the following command:
33
39
34
-
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*.
40
+
```shell
41
+
dotnet new console
42
+
```
35
43
36
-
```dotnetcli
37
-
dotnet new console -n azure-openai-quickstart
38
-
```
44
+
3. Install the [OpenAI .NET client library](https://www.nuget.org/packages/Azure.AI.OpenAI/) with the [dotnet add package](/dotnet/core/tools/dotnet-add-package) command:
39
45
40
-
Change your directory to the newly created app folder. You can build the application with:
1. For the **recommended** keyless authentication with Microsoft Entra ID, install the [Azure.Identity](https://www.nuget.org/packages/Azure.Identity) package with:
45
51
46
-
The build output should contain no warnings or errors.
52
+
```console
53
+
dotnet add package Azure.Identity
54
+
```
47
55
48
-
```output
49
-
...
50
-
Build succeeded.
51
-
0 Warning(s)
52
-
0 Error(s)
53
-
...
54
-
```
56
+
1. For the **recommended** keyless authentication with Microsoft Entra ID, sign in to Azure with the following command:
From the project directory, open the *program.cs* file and replace the contents with the following code:
68
+
The sample code in this quickstart uses Microsoft Entra ID for the recommended keyless authentication. If you prefer to use an API key, you can replace the `DefaultAzureCredential` object with an `AzureKeyCredential` object.
> For production, use a secure way of storing and accessing your credentials like [Azure Key Vault](/azure/key-vault/general/overview). For more information about credential security, see the Azure AI services [security](../../security-features.md) article.
0 commit comments