Skip to content

Commit 10c985a

Browse files
committed
fixes
1 parent 00bdd89 commit 10c985a

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

articles/ai-services/openai/includes/assistants-csharp.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ ms.date: 9/27/2024
5656
5757
[!INCLUDE [environment-variables](environment-variables.md)]
5858
59+
### Passwordless authentication is recommended
60+
61+
Passwordless authentication is more secure than key-based alternatives and is the recommended approach for connecting to Azure services. If you choose Passwordless authentication, you'll need to complete the following:
62+
63+
1. Add the [`Azure.Identity`](https://www.nuget.org/packages/Azure.Identity) package.
64+
65+
```dotnetcli
66+
dotnet add package Azure.Identity
67+
```
68+
69+
1. Assign the `Cognitive Services User` role to your user account. This can be done in the Azure portal on your OpenAI resource under **Access control (IAM)** > **Add role assignment**.
70+
1. Sign-in to Azure using Visual Studio or the Azure CLI via `az login`.
71+
5972
### Create the assistant
6073
6174
Update the `Program.cs` file with the following code to create an assistant:
@@ -64,7 +77,8 @@ Update the `Program.cs` file with the following code to create an assistant:
6477
using Azure;
6578
using Azure.AI.OpenAI.Assistants;
6679
67-
// Assistants is a beta API and subject to change; acknowledge its experimental status by suppressing the matching warning.
80+
// Assistants is a beta API and subject to change
81+
// Acknowledge its experimental status by suppressing the matching warning.
6882
string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
6983
string key = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY");
7084
@@ -138,7 +152,7 @@ AssistantCreationOptions assistantOptions = new()
138152
139153
Assistant assistant = await assistantClient.CreateAssistantAsync(deploymentName, assistantOptions);
140154
141-
// Now we'll create a thread with a user query about the data already associated with the assistant, then run it
155+
// Create and run a thread with a user query about the data already associated with the assistant
142156
ThreadCreationOptions threadOptions = new()
143157
{
144158
InitialMessages = { "How well did product 113045 sell in February? Graph its trend over time." }
@@ -155,7 +169,9 @@ do
155169
156170
// Finally, we'll print out the full history for the thread that includes the augmented generation
157171
AsyncCollectionResult<ThreadMessage> messages
158-
= assistantClient.GetMessagesAsync(threadRun.ThreadId, new MessageCollectionOptions() { Order = MessageCollectionOrder.Ascending });
172+
= assistantClient.GetMessagesAsync(
173+
threadRun.ThreadId,
174+
new MessageCollectionOptions() { Order = MessageCollectionOrder.Ascending });
159175
160176
await foreach (ThreadMessage message in messages)
161177
{

0 commit comments

Comments
 (0)