Skip to content

Commit 4d51f31

Browse files
Merge pull request #46077 from dotnet/main
Merge main into live
2 parents e0c4348 + d7d2696 commit 4d51f31

File tree

23 files changed

+173
-106
lines changed

23 files changed

+173
-106
lines changed

docs/ai/quickstarts/build-chat-app.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Quickstart - Build an AI chat app with .NET
3-
description: Create a simple AI powered chat app using Semantic Kernel SDK for .NET and the OpenAI or Azure OpenAI SDKs
3+
description: Create a simple AI powered chat app using Microsoft.Extensions.AI and the OpenAI or Azure OpenAI SDKs
44
ms.date: 04/09/2025
55
ms.topic: quickstart
66
ms.custom: devx-track-dotnet, devx-track-dotnet-ai
@@ -31,8 +31,6 @@ In this quickstart, you learn how to create a conversational .NET console chat a
3131

3232
[!INCLUDE [semantic-kernel](includes/semantic-kernel.md)]
3333

34-
[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)]
35-
3634
## Create the app
3735

3836
Complete the following steps to create a .NET console app to connect to an AI model.
@@ -104,13 +102,13 @@ Complete the following steps to create a .NET console app to connect to an AI mo
104102
105103
## Add the app code
106104
107-
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 and is designed to provide users with information about hiking trails.
105+
This app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Microsoft.Extensions.AI/) package to send and receive requests to the AI model. The app provides users with information about hiking trails.
108106
109-
1. In the **Program.cs** file, add the following code to connect and authenticate to the AI model.
107+
1. In the `Program.cs` file, add the following code to connect and authenticate to the AI model.
110108
111109
:::zone target="docs" pivot="azure-openai"
112110
113-
:::code language="csharp" source="snippets/build-chat-app/azure-openai/program.cs" range="1-12":::
111+
:::code language="csharp" source="snippets/build-chat-app/azure-openai/program.cs" id="GetChatClient":::
114112
115113
> [!NOTE]
116114
> <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).
@@ -119,17 +117,17 @@ The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Micr
119117
120118
:::zone target="docs" pivot="openai"
121119
122-
:::code language="csharp" source="snippets/build-chat-app/openai/program.cs" range="1-11":::
120+
:::code language="csharp" source="snippets/build-chat-app/openai/program.cs" id="GetChatClient":::
123121
124122
:::zone-end
125123
126124
1. Create a system prompt to provide the AI model with initial role context and instructions about hiking recommendations:
127125
128-
:::code language="csharp" source="snippets/build-chat-app/openai/program.cs" range="13-30":::
126+
:::code language="csharp" source="snippets/build-chat-app/openai/program.cs" id="FirstMessage":::
129127
130128
1. Create a conversational loop that accepts an input prompt from the user, sends the prompt to the model, and prints the response completion:
131129
132-
:::code language="csharp" source="snippets/build-chat-app/openai/program.cs" range="32-51":::
130+
:::code language="csharp" source="snippets/build-chat-app/openai/program.cs" id="ChatLoop":::
133131
134132
1. Use the `dotnet run` command to run the app:
135133
@@ -143,11 +141,10 @@ The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Micr
143141
144142
## Clean up resources
145143
146-
When you no longer need the sample application or resources, remove the corresponding deployment and all resources.
144+
If you no longer need them, delete the Azure OpenAI resource and GPT-4 model deployment.
147145
148-
```azdeveloper
149-
azd down
150-
```
146+
1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource.
147+
1. Select the Azure OpenAI resource, and then select **Delete**.
151148
152149
:::zone-end
153150

docs/ai/quickstarts/build-vector-search-app.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ In this quickstart, you create a .NET console app to perform semantic search on
2626

2727
:::zone-end
2828

29-
[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)]
30-
3129
## Interact with your data using vector stores
3230

3331
Vector stores or vector databases are essential for tasks like semantic search, Retrieval Augmented Generation (RAG), and other scenarios that require grounding generative AI responses. While relational databases and document databases are optimized for structured and semi-structured data, vector databases are built to efficiently store, index, and manage data represented as embedding vectors. As a result, the indexing and search algorithms used by vector databases are optimized to efficiently retrieve data that can be used downstream in your applications.
@@ -171,7 +169,7 @@ Complete the following steps to create a .NET console app that can:
171169
172170
:::zone target="docs" pivot="openai"
173171
174-
:::code language="csharp" source="snippets/chat-with-data/openai/program.cs" range="49-57":::
172+
:::code language="csharp" source="snippets/chat-with-data/openai/program.cs" id="EmbeddingGenerator":::
175173
176174
:::zone-end
177175
@@ -197,11 +195,10 @@ Complete the following steps to create a .NET console app that can:
197195
198196
## Clean up resources
199197
200-
When you no longer need the sample application or resources, remove the corresponding deployment and all resources.
198+
If you no longer need them, delete the Azure OpenAI resource and GPT-4 model deployment.
201199
202-
```azdeveloper
203-
azd down
204-
```
200+
1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource.
201+
1. Select the Azure OpenAI resource, and then select **Delete**.
205202
206203
:::zone-end
207204

docs/ai/quickstarts/chat-local-model.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ The Semantic Kernel SDK provides many services and features to connect to AI mod
8484
8585
The preceding code accomplishes the following:
8686
87-
- Creates an `OllamaChatClient` that implements the `IChatClient` interface.
88-
- This interface provides a loosely coupled abstraction you can use to chat with AI Models.
89-
- You can later change the underlying chat client implementation to another model, such as Azure OpenAI, without changing any other code.
90-
- Creates a `ChatHistory` object to store the messages between the user and the AI model.
91-
- Retrieves a prompt from the user and stores it in the `ChatHistory`.
92-
- Sends the chat data to the AI model to generate a response.
87+
* Creates an `OllamaChatClient` that implements the `IChatClient` interface.
88+
* This interface provides a loosely coupled abstraction you can use to chat with AI Models.
89+
* You can later change the underlying chat client implementation to another model, such as Azure OpenAI, without changing any other code.
90+
* Creates a `ChatHistory` object to store the messages between the user and the AI model.
91+
* Retrieves a prompt from the user and stores it in the `ChatHistory`.
92+
* Sends the chat data to the AI model to generate a response.
9393
9494
> [!NOTE]
9595
> Ollama runs on port 11434 by default, which is why the AI model endpoint is set to `http://localhost:11434`.
@@ -146,4 +146,4 @@ The Semantic Kernel SDK provides many services and features to connect to AI mod
146146

147147
## Next steps
148148

149-
- [Generate text and conversations with .NET and Azure OpenAI Completions](/training/modules/open-ai-dotnet-text-completions/)
149+
* [Generate text and conversations with .NET and Azure OpenAI Completions](/training/modules/open-ai-dotnet-text-completions/)

docs/ai/quickstarts/create-assistant.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,27 @@ Complete the following steps to create a .NET console app and add the package ne
107107
108108
## Create the AI assistant client
109109
110-
1. Open the _Program.cs_ file and replace the contents of the file with the following code to create the required clients:
110+
1. Open the `Program.cs` file and replace the contents of the file with the following code to create the required clients:
111111
112-
:::code language="csharp" source="snippets/assistants/program.cs" range="0-17" :::
112+
:::code language="csharp" source="snippets/assistants/program.cs" id="CreateClient" :::
113113
114114
1. Create an in-memory sample document and upload it to the `OpenAIFileClient`:
115115
116-
:::code language="csharp" source="snippets/assistants/program.cs" range="19-53" :::
116+
:::code language="csharp" source="snippets/assistants/program.cs" id="CreateDocument" :::
117117
118118
1. Enable file search and code interpreter tooling capabilities via the `AssistantCreationOptions`:
119119
120-
:::code language="csharp" source="snippets/assistants/program.cs" range="55-78" :::
120+
:::code language="csharp" source="snippets/assistants/program.cs" id="EnableTools" :::
121121
122122
1. Create the `Assistant` and a thread to manage interactions between the user and the assistant:
123123
124-
:::code language="csharp" source="snippets/assistants/program.cs" range="80-105" :::
124+
:::code language="csharp" source="snippets/assistants/program.cs" id="CreateAssistant" :::
125125
126126
1. Print the messages and save the generated image from the conversation with the assistant:
127127
128-
:::code language="csharp" source="snippets/assistants/program.cs" range="107-147" :::
128+
:::code language="csharp" source="snippets/assistants/program.cs" id="ProcessMessages" :::
129129
130-
Locate and open the saved image in the app *bin* directory, which should resemble the following:
130+
Locate and open the saved image in the app `bin` directory, which should resemble the following:
131131
132132
:::image type="content" source="../media/assistants/generated-sales-graph.png" alt-text="A graph showing the visualization generated by the AI model.":::
133133

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ Complete the following steps to create an MSTest project that connects to the `g
9696
9797
Run the test using your preferred test workflow, for example, by using the CLI command `dotnet test` or through [Test Explorer](/visualstudio/test/run-unit-tests-with-test-explorer).
9898
99+
## Clean up resources
100+
101+
If you no longer need them, delete the Azure OpenAI resource and GPT-4 model deployment.
102+
103+
1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource.
104+
1. Select the Azure OpenAI resource, and then select **Delete**.
105+
99106
## Next steps
100107
101108
- Evaluate the responses from different OpenAI models.

docs/ai/quickstarts/generate-images.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ In this quickstart, you learn how to create a .NET console app to generate image
2828

2929
[!INCLUDE [semantic-kernel](includes/semantic-kernel.md)]
3030

31-
[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)]
32-
3331
## Create the app
3432

3533
Complete the following steps to create a .NET console app to connect to an AI model.
@@ -134,11 +132,10 @@ Complete the following steps to create a .NET console app to connect to an AI mo
134132
135133
## Clean up resources
136134
137-
When you no longer need the sample application or resources, remove the corresponding deployment and all resources.
135+
If you no longer need them, delete the Azure OpenAI resource and GPT-4 model deployment.
138136
139-
```azdeveloper
140-
azd down
141-
```
137+
1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource.
138+
1. Select the Azure OpenAI resource, and then select **Delete**.
142139
143140
:::zone-end
144141

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

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
## Create the AI service
22

3-
# [Azure Portal or Azure CLI](#tab/azure-cli)
4-
53
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.
64

75
1. From a terminal or command prompt, navigate to the root of your project directory.
@@ -13,9 +11,3 @@
1311
dotnet user-secrets set AZURE_OPENAI_ENDPOINT <your-azure-openai-endpoint>
1412
dotnet user-secrets set AZURE_OPENAI_GPT_NAME <your-azure-openai-model-name>
1513
```
16-
17-
# [Azure Developer CLI](#tab/azd)
18-
19-
[!INCLUDE [deploy-azd](deploy-azd.md)]
20-
21-
---

docs/ai/quickstarts/includes/deploy-azd.md

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

docs/ai/quickstarts/prompt-model.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ In this quickstart, you learn how to create a .NET console chat app to connect t
3131

3232
[!INCLUDE [semantic-kernel](includes/semantic-kernel.md)]
3333

34-
[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)]
35-
3634
## Create the app
3735

3836
Complete the following steps to create a .NET console app to connect to an AI model.
@@ -141,11 +139,10 @@ The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Micr
141139

142140
## Clean up resources
143141

144-
When you no longer need the sample application or resources, remove the corresponding deployment and all resources.
142+
If you no longer need them, delete the Azure OpenAI resource and GPT-4 model deployment.
145143

146-
```azdeveloper
147-
azd down
148-
```
144+
1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource.
145+
1. Select the Azure OpenAI resource, and then select **Delete**.
149146

150147
:::zone-end
151148

docs/ai/quickstarts/snippets/assistants/Program.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using OpenAI;
1+
// <SnippetCreateClient>
2+
using OpenAI;
23
using OpenAI.Assistants;
34
using OpenAI.Files;
45
using Azure.AI.OpenAI;
@@ -15,7 +16,9 @@
1516
#pragma warning disable OPENAI001
1617
AssistantClient assistantClient = openAIClient.GetAssistantClient();
1718
OpenAIFileClient fileClient = openAIClient.GetOpenAIFileClient();
19+
// </SnippetCreateClient>
1820

21+
// <SnippetCreateDocument>
1922
// Create an in-memory document to upload to the file client
2023
using Stream document = BinaryData.FromBytes("""
2124
{
@@ -51,7 +54,9 @@
5154
document,
5255
"monthly_sales.json",
5356
FileUploadPurpose.Assistants);
57+
// </SnippetCreateDocument>
5458

59+
// <SnippetEnableTools>
5560
// Configure the assistant options
5661
AssistantCreationOptions assistantOptions = new()
5762
{
@@ -76,7 +81,9 @@
7681
}
7782
},
7883
};
84+
// </SnippetEnableTools>
7985

86+
// <SnippetCreateAssistant>
8087
// Create the assistant
8188
Assistant assistant = assistantClient.CreateAssistant("gpt-4o", assistantOptions);
8289

@@ -100,10 +107,13 @@
100107
var messages = assistantClient.GetMessagesAsync(
101108
threadRun.ThreadId,
102109
new MessageCollectionOptions()
103-
{
110+
{
104111
Order = MessageCollectionOrder.Ascending
105112
});
113+
// </SnippetCreateAssistant>
106114

115+
// <SnippetProcessMessages>
116+
// Process the messages from the assistant
107117
await foreach (ThreadMessage message in messages)
108118
{
109119
// Print out the messages from the assistant
@@ -144,4 +154,5 @@
144154
}
145155
}
146156
Console.WriteLine();
147-
}
157+
}
158+
// </SnippetProcessMessages>

docs/ai/quickstarts/snippets/build-chat-app/azure-openai/Program.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Azure.AI.OpenAI;
44
using Azure.Identity;
55

6+
// <SnippetGetChatClient>
67
IConfigurationRoot config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
78
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
89
string deployment = config["AZURE_OPENAI_GPT_NAME"];
@@ -11,7 +12,9 @@
1112
new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
1213
.GetChatClient(deployment)
1314
.AsIChatClient();
15+
// </SnippetGetChatClient>
1416

17+
// <SnippetFirstMessage>
1518
// Start the conversation with context for the AI model
1619
List<ChatMessage> chatHistory =
1720
[
@@ -30,7 +33,9 @@ the local nature on the hikes when making a recommendation. At the end of your
3033
response, ask if there is anything else you can help with.
3134
""")
3235
];
36+
// </SnippetFirstMessage>
3337

38+
// <SnippetChatLoop>
3439
while (true)
3540
{
3641
// Get user prompt and add to chat history
@@ -50,3 +55,4 @@ the local nature on the hikes when making a recommendation. At the end of your
5055
chatHistory.Add(new ChatMessage(ChatRole.Assistant, response));
5156
Console.WriteLine();
5257
}
58+
// </SnippetChatLoop>

0 commit comments

Comments
 (0)