Skip to content

Commit 6468b00

Browse files
authored
fix quickstart (#46003)
1 parent 5dd1ad8 commit 6468b00

File tree

14 files changed

+98
-138
lines changed

14 files changed

+98
-138
lines changed

docs/ai/index.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ landingContent:
2121
# Card
2222
- title: Get started
2323
linkLists:
24-
- linkListType: get-started
24+
- linkListType: overview
2525
links:
2626
- text: Develop .NET apps with AI features
2727
url: overview.md
28-
- text: Connect to and prompt an AI model
29-
url: quickstarts/prompt-model.md
3028
- text: Microsoft.Extensions.AI libraries
3129
url: microsoft-extensions-ai.md
30+
- linkListType: get-started
31+
links:
32+
- text: Connect to and prompt an AI model
33+
url: quickstarts/prompt-model.md
3234
- text: Build an Azure AI chat app
33-
url: quickstarts/get-started-openai.md
34-
- text: Summarize text using an Azure OpenAI chat app
35-
url: quickstarts/quickstart-openai-summarize-text.md
35+
url: quickstarts/build-chat-app.md
3636
- text: Generate images using Azure AI
37-
url: quickstarts/quickstart-openai-generate-images.md
37+
url: quickstarts/generate-images.md
3838

3939
# Card
4040
- title: Essential concepts

docs/ai/quickstarts/evaluate-ai-response.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ ms.custom: devx-track-dotnet, devx-track-dotnet-ai
1111
In this quickstart, you create an MSTest app to evaluate the chat response of an OpenAI model. The test app uses the [Microsoft.Extensions.AI.Evaluation](https://www.nuget.org/packages/Microsoft.Extensions.AI.Evaluation) libraries.
1212

1313
> [!NOTE]
14-
> This quickstart demonstrates the simplest usage of the evaluation API. Notably, it doesn't demonstrate use of the [response caching](../conceptual/evaluation-libraries.md#cached-responses) and [reporting](../conceptual/evaluation-libraries.md#reporting) functionality, which are important if you're authoring unit tests that run as part of an "offline" evaluation pipeline. The scenario shown in this quickstart is suitable in use cases such as "online" evaluation of AI responses within production code and logging scores to telemetry, where caching and reporting aren't relevant. For a tutorial that demonstrates the caching and reporting functionality, see [Tutorial: Evaluate a model's response with response caching and reporting](../tutorials/evaluate-with-reporting.md)
14+
>
15+
> - The `Microsoft.Extensions.AI.Evaluation` library is currently in Preview.
16+
> - This quickstart demonstrates the simplest usage of the evaluation API. Notably, it doesn't demonstrate use of the [response caching](../conceptual/evaluation-libraries.md#cached-responses) and [reporting](../conceptual/evaluation-libraries.md#reporting) functionality, which are important if you're authoring unit tests that run as part of an "offline" evaluation pipeline. The scenario shown in this quickstart is suitable in use cases such as "online" evaluation of AI responses within production code and logging scores to telemetry, where caching and reporting aren't relevant. For a tutorial that demonstrates the caching and reporting functionality, see [Tutorial: Evaluate a model's response with response caching and reporting](../tutorials/evaluate-with-reporting.md)
1517
1618
## Prerequisites
1719

docs/ai/quickstarts/generate-images.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Complete the following steps to create a .NET console app to connect to an AI mo
9898
9999
## Add the app code
100100
101-
1. In the **Program.cs** file, add the following code to connect and authenticate to the AI model.
101+
1. In the `Program.cs` file, add the following code to connect and authenticate to the AI model.
102102
103103
:::zone target="docs" pivot="azure-openai"
104104
@@ -117,12 +117,12 @@ Complete the following steps to create a .NET console app to connect to an AI mo
117117
118118
The preceding code:
119119
120-
- Reads essential configuration values from the project user secrets to connect to the AI model
121-
- Creates an `ImageClient` to connect to the AI model
122-
- Sends a prompt to the model that describes the desired image
123-
- Prints the URL of the generated image to the console output
120+
- Reads essential configuration values from the project user secrets to connect to the AI model.
121+
- Creates an `OpenAI.Images.ImageClient` to connect to the AI model.
122+
- Sends a prompt to the model that describes the desired image.
123+
- Prints the URL of the generated image to the console output.
124124
125-
1. Use the `dotnet run` command to run the app:
125+
1. Run the app:
126126
127127
```dotnetcli
128128
dotnet run

docs/ai/quickstarts/includes/clone-sample-repo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ms.date: 07/03/2024
55
ms.topic: include
66
---
77

8-
## Clone the sample repository
8+
## (Optional) Clone the sample repository
99

1010
You can create your own app using the steps in the sections ahead, or you can clone the GitHub repository that contains the completed sample apps for all of the quickstarts. If you plan to use Azure OpenAI, the sample repo is also structured as an Azure Developer CLI template that can provision an Azure OpenAI resource for you.
1111

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
## Create the AI service
22

3-
# [Azure Developer CLI](#tab/azd)
4-
5-
[!INCLUDE [deploy-azd](deploy-azd.md)]
6-
7-
# [Azure CLI](#tab/azure-cli)
3+
# [Azure Portal or Azure CLI](#tab/azure-cli)
84

9-
1. To provision an Azure OpenAI service and model using the Azure CLI, complete the steps in the [Create and deploy an Azure OpenAI Service resource](/azure/ai-services/openai/how-to/create-resource?pivots=cli) article.
5+
1. To provision an Azure OpenAI service and model, complete the steps in the [Create and deploy an Azure OpenAI Service resource](/azure/ai-services/openai/how-to/create-resource) article.
106

117
1. From a terminal or command prompt, navigate to the root of your project directory.
128

@@ -18,18 +14,8 @@
1814
dotnet user-secrets set AZURE_OPENAI_GPT_NAME <your-azure-openai-model-name>
1915
```
2016

21-
# [Azure Portal](#tab/azure-portal)
22-
23-
1. To provision an Azure OpenAI service and model using the Azure portal, complete the steps in the [Create and deploy an Azure OpenAI Service resource](/azure/ai-services/openai/how-to/create-resource?pivots=web-portal) article.
24-
25-
1. From a terminal or command prompt, navigate to the root of your project directory.
26-
27-
1. Run the following commands to configure your Azure OpenAI endpoint and model name for the sample app:
17+
# [Azure Developer CLI](#tab/azd)
2818

29-
```bash
30-
dotnet user-secrets init
31-
dotnet user-secrets set AZURE_OPENAI_ENDPOINT <your-openai-key>
32-
dotnet user-secrets set AZURE_OPENAI_GPT_NAME <your-azure-openai-model-name>
33-
```
19+
[!INCLUDE [deploy-azd](deploy-azd.md)]
3420

3521
---

docs/ai/quickstarts/prompt-model.md

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: Quickstart - Summarize text using an AI chat app with .NET
2+
title: Quickstart - Connect to and prompt an AI model with .NET
33
description: Create a simple chat app using Microsoft.Extensions.AI to summarize a text.
4-
ms.date: 04/09/2025
4+
ms.date: 05/02/2025
55
ms.topic: quickstart
66
ms.custom: devx-track-dotnet, devx-track-dotnet-ai
77
author: fboucher
@@ -10,12 +10,12 @@ zone_pivot_groups: openai-library
1010
# CustomerIntent: As a .NET developer new to OpenAI, I want deploy and use sample code to interact to learn from the sample code to summarize text.
1111
---
1212

13-
# Connect to and prompt an AI model using .NET
13+
# Connect to and prompt an AI model
1414

1515
In this quickstart, you learn how to create a .NET console chat app to connect to and prompt an OpenAI or Azure OpenAI model. The app uses the <xref:Microsoft.Extensions.AI> library so you can write code using AI abstractions rather than a specific SDK. AI abstractions enable you to change the underlying AI model with minimal code changes.
1616

1717
> [!NOTE]
18-
> The [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Microsoft.Extensions.AI/) library is currently in Preview.
18+
> The <xref:Microsoft.Extensions.AI> library is currently in Preview.
1919
2020
:::zone target="docs" pivot="openai"
2121

@@ -54,9 +54,9 @@ Complete the following steps to create a .NET console app to connect to an AI mo
5454
:::zone target="docs" pivot="azure-openai"
5555
5656
```bash
57-
dotnet add package Azure.Identity
5857
dotnet add package Azure.AI.OpenAI
59-
dotnet add package Microsoft.Extensions.AI.OpenAI
58+
dotnet add package Azure.Identity
59+
dotnet add package Microsoft.Extensions.AI.OpenAI --prerelease
6060
dotnet add package Microsoft.Extensions.Configuration
6161
dotnet add package Microsoft.Extensions.Configuration.UserSecrets
6262
```
@@ -67,18 +67,14 @@ Complete the following steps to create a .NET console app to connect to an AI mo
6767
6868
```bash
6969
dotnet add package OpenAI
70-
dotnet add package Microsoft.Extensions.AI.OpenAI
70+
dotnet add package Microsoft.Extensions.AI.OpenAI --prerelease
7171
dotnet add package Microsoft.Extensions.Configuration
7272
dotnet add package Microsoft.Extensions.Configuration.UserSecrets
7373
```
7474
7575
:::zone-end
7676
77-
1. Open the app in Visual Studio code or your editor of choice
78-
79-
```bash
80-
code .
81-
```
77+
1. Open the app in Visual Studio Code or your editor of choice.
8278
8379
:::zone target="docs" pivot="azure-openai"
8480
@@ -94,50 +90,52 @@ Complete the following steps to create a .NET console app to connect to an AI mo
9490
9591
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
9692
97-
```bash
98-
dotnet user-secrets init
99-
dotnet user-secrets set OpenAIKey <your-openai-key>
100-
dotnet user-secrets set ModelName <your-openai-model-name>
101-
```
93+
```bash
94+
dotnet user-secrets init
95+
dotnet user-secrets set OpenAIKey <your-openai-key>
96+
dotnet user-secrets set ModelName <your-openai-model-name>
97+
```
10298

10399
:::zone-end
104100

105101
## Add the app code
106102

107103
The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Microsoft.Extensions.AI/) package to send and receive requests to the AI model.
108104

109-
1. In the **Program.cs** file, add the following code to connect and authenticate to the AI model.
105+
1. Copy the [benefits.md](https://raw.githubusercontent.com/dotnet/docs/refs/heads/main/docs/ai/quickstarts/snippets/prompt-completion/azure-openai/benefits.md) file to your project directory. Configure the project to copy this file to the output directory. If you're using Visual Studio, right-click on the file in Solution Explorer, select **Properties**, and then set **Copy to Output Directory** to **Copy if newer**.
110106

111-
:::zone target="docs" pivot="azure-openai"
107+
1. In the `Program.cs` file, add the following code to connect and authenticate to the AI model.
112108

113-
:::code language="csharp" source="snippets/prompt-completion/azure-openai/program.cs" range="1-12":::
109+
:::zone target="docs" pivot="azure-openai"
114110

115-
> [!NOTE]
116-
> <xref:Azure.Identity.DefaultAzureCredential> searches for authentication credentials from your local tooling. If you aren't using the `azd` template to provision the Azure OpenAI resource, you'll need to assign the `Azure AI Developer` role to the account you used to sign-in to Visual Studio or the Azure CLI. For more information, see [Authenticate to Azure AI services with .NET](../azure-ai-services-authentication.md).
111+
:::code language="csharp" source="snippets/prompt-completion/azure-openai/program.cs" id="CreateChatClient":::
117112

118-
:::zone-end
113+
> [!NOTE]
114+
> <xref:Azure.Identity.DefaultAzureCredential> searches for authentication credentials from your local tooling. If you aren't using the `azd` template to provision the Azure OpenAI resource, you'll need to assign the `Azure AI Developer` role to the account you used to sign-in to Visual Studio or the Azure CLI. For more information, see [Authenticate to Azure AI services with .NET](../azure-ai-services-authentication.md).
119115
120-
:::zone target="docs" pivot="openai"
116+
:::zone-end
121117

122-
:::code language="csharp" source="snippets/prompt-completion/openai/program.cs" range="1-11":::
118+
:::zone target="docs" pivot="openai"
123119

124-
:::zone-end
120+
:::code language="csharp" source="snippets/prompt-completion/openai/program.cs" id="CreateChatClient":::
125121

126-
1. Read the *benefits.md* file content and use it to create a prompt for the model. The prompt instructs the model to summarize the file text content.
122+
:::zone-end
127123

128-
:::code language="csharp" source="snippets/prompt-completion/openai/program.cs" range="13-19":::
124+
1. Add code to read the `benefits.md` file content and then create a prompt for the model. The prompt instructs the model to summarize the file's text content in 20 words or less.
129125

130-
1. Call the `InvokePromptAsync` function to send the prompt to the model to generate a response.
126+
:::code language="csharp" source="snippets/prompt-completion/openai/program.cs" id="CreatePrompt":::
131127

132-
:::code language="csharp" source="snippets/prompt-completion/openai/program.cs" range="21-23":::
128+
1. Call the `GetResponseAsync` method to send the prompt to the model to generate a response.
133129

134-
1. Use the `dotnet run` command to run the app:
130+
:::code language="csharp" source="snippets/prompt-completion/openai/program.cs" id="GetResponse":::
135131

136-
```dotnetcli
137-
dotnet run
138-
```
132+
1. Run the app:
133+
134+
```dotnetcli
135+
dotnet run
136+
```
139137

140-
The app prints out the completion response from the AI model. Customize the text content of the `benefits.md` file or the length of the summary to see the differences in the responses.
138+
The app prints out the completion response from the AI model. Customize the text content of the `benefits.md` file or the length of the summary to see the differences in the responses.
141139

142140
:::zone target="docs" pivot="azure-openai"
143141

docs/ai/quickstarts/snippets/image-generation/azure-openai/benefits.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

docs/ai/quickstarts/snippets/image-generation/openai/benefits.md

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
1-
using Microsoft.Extensions.Configuration;
1+
// <SnippetCreateChatClient>
2+
using Microsoft.Extensions.Configuration;
23
using Microsoft.Extensions.AI;
34
using Azure.AI.OpenAI;
45
using Azure.Identity;
56

6-
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
7+
var config = new ConfigurationBuilder()
8+
.AddUserSecrets<Program>()
9+
.Build();
710
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
811
string deployment = config["AZURE_OPENAI_GPT_NAME"];
912

1013
IChatClient client =
1114
new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
1215
.GetChatClient(deployment)
1316
.AsIChatClient();
17+
// </SnippetCreateChatClient>
1418

15-
// Create and print out the prompt
19+
// <SnippetCreatePrompt>
20+
string text = File.ReadAllText("benefits.md");
1621
string prompt = $"""
17-
summarize the the following text in 20 words or less:
18-
{File.ReadAllText("benefits.md")}
22+
Summarize the the following text in 20 words or less:
23+
{text}
1924
""";
25+
// </SnippetCreatePrompt>
2026

21-
Console.WriteLine($"user >>> {prompt}");
22-
23-
// Submit the prompt and print out the response
24-
ChatResponse response = await client.GetResponseAsync(prompt, new ChatOptions { MaxOutputTokens = 400 });
25-
Console.WriteLine($"assistant >>> {response}");
27+
// <SnippetGetResponse>
28+
// Submit the prompt and print out the response.
29+
ChatResponse response = await client.GetResponseAsync(
30+
prompt,
31+
new ChatOptions { MaxOutputTokens = 400 });
32+
Console.WriteLine(response);
33+
// </SnippetGetResponse>
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1-
using Microsoft.Extensions.AI;
1+
// <SnippetCreateChatClient>
2+
using Microsoft.Extensions.AI;
23
using Microsoft.Extensions.Configuration;
34
using OpenAI;
45

5-
IConfigurationRoot config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
6+
IConfigurationRoot config = new ConfigurationBuilder()
7+
.AddUserSecrets<Program>()
8+
.Build();
69
string? model = config["ModelName"];
710
string? key = config["OpenAIKey"];
811

9-
// Create the IChatClient
1012
IChatClient client =
1113
new OpenAIClient(key).GetChatClient(model).AsIChatClient();
14+
// </SnippetCreateChatClient>
1215

13-
// Create and print out the prompt
16+
// <SnippetCreatePrompt>
17+
string text = File.ReadAllText("benefits.md");
1418
string prompt = $"""
15-
summarize the the following text in 20 words or less:
16-
{File.ReadAllText("benefits.md")}
19+
Summarize the the following text in 20 words or less:
20+
{text}
1721
""";
22+
// </SnippetCreatePrompt>
1823

19-
Console.WriteLine($"user >>> {prompt}");
20-
21-
// Submit the prompt and print out the response
22-
ChatResponse response = await client.GetResponseAsync(prompt, new ChatOptions { MaxOutputTokens = 400 });
23-
Console.WriteLine($"assistant >>> {response}");
24+
// <SnippetGetResponse>
25+
// Submit the prompt and print out the response.
26+
ChatResponse response = await client.GetResponseAsync(
27+
prompt,
28+
new ChatOptions { MaxOutputTokens = 400 });
29+
Console.WriteLine(response);
30+
// </SnippetGetResponse>

0 commit comments

Comments
 (0)