Skip to content

Merge main into live #46077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions docs/ai/quickstarts/build-chat-app.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Quickstart - Build an AI chat app with .NET
description: Create a simple AI powered chat app using Semantic Kernel SDK for .NET and the OpenAI or Azure OpenAI SDKs
description: Create a simple AI powered chat app using Microsoft.Extensions.AI and the OpenAI or Azure OpenAI SDKs
ms.date: 04/09/2025
ms.topic: quickstart
ms.custom: devx-track-dotnet, devx-track-dotnet-ai
Expand Down Expand Up @@ -31,8 +31,6 @@ In this quickstart, you learn how to create a conversational .NET console chat a

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

[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)]

## Create the app

Complete the following steps to create a .NET console app to connect to an AI model.
Expand Down Expand Up @@ -104,13 +102,13 @@ Complete the following steps to create a .NET console app to connect to an AI mo

## Add the app code

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.
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.

1. In the **Program.cs** file, add the following code to connect and authenticate to the AI model.
1. In the `Program.cs` file, add the following code to connect and authenticate to the AI model.

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

:::code language="csharp" source="snippets/build-chat-app/azure-openai/program.cs" range="1-12":::
:::code language="csharp" source="snippets/build-chat-app/azure-openai/program.cs" id="GetChatClient":::

> [!NOTE]
> <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).
Expand All @@ -119,17 +117,17 @@ The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Micr

:::zone target="docs" pivot="openai"

:::code language="csharp" source="snippets/build-chat-app/openai/program.cs" range="1-11":::
:::code language="csharp" source="snippets/build-chat-app/openai/program.cs" id="GetChatClient":::

:::zone-end

1. Create a system prompt to provide the AI model with initial role context and instructions about hiking recommendations:

:::code language="csharp" source="snippets/build-chat-app/openai/program.cs" range="13-30":::
:::code language="csharp" source="snippets/build-chat-app/openai/program.cs" id="FirstMessage":::

1. Create a conversational loop that accepts an input prompt from the user, sends the prompt to the model, and prints the response completion:

:::code language="csharp" source="snippets/build-chat-app/openai/program.cs" range="32-51":::
:::code language="csharp" source="snippets/build-chat-app/openai/program.cs" id="ChatLoop":::

1. Use the `dotnet run` command to run the app:

Expand All @@ -143,11 +141,10 @@ The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Micr

## Clean up resources

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

```azdeveloper
azd down
```
1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource.
1. Select the Azure OpenAI resource, and then select **Delete**.

:::zone-end

Expand Down
11 changes: 4 additions & 7 deletions docs/ai/quickstarts/build-vector-search-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ In this quickstart, you create a .NET console app to perform semantic search on

:::zone-end

[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)]

## Interact with your data using vector stores

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.
Expand Down Expand Up @@ -171,7 +169,7 @@ Complete the following steps to create a .NET console app that can:

:::zone target="docs" pivot="openai"

:::code language="csharp" source="snippets/chat-with-data/openai/program.cs" range="49-57":::
:::code language="csharp" source="snippets/chat-with-data/openai/program.cs" id="EmbeddingGenerator":::

:::zone-end

Expand All @@ -197,11 +195,10 @@ Complete the following steps to create a .NET console app that can:

## Clean up resources

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

```azdeveloper
azd down
```
1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource.
1. Select the Azure OpenAI resource, and then select **Delete**.

:::zone-end

Expand Down
14 changes: 7 additions & 7 deletions docs/ai/quickstarts/chat-local-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ The Semantic Kernel SDK provides many services and features to connect to AI mod

The preceding code accomplishes the following:

- Creates an `OllamaChatClient` that implements the `IChatClient` interface.
- This interface provides a loosely coupled abstraction you can use to chat with AI Models.
- You can later change the underlying chat client implementation to another model, such as Azure OpenAI, without changing any other code.
- Creates a `ChatHistory` object to store the messages between the user and the AI model.
- Retrieves a prompt from the user and stores it in the `ChatHistory`.
- Sends the chat data to the AI model to generate a response.
* Creates an `OllamaChatClient` that implements the `IChatClient` interface.
* This interface provides a loosely coupled abstraction you can use to chat with AI Models.
* You can later change the underlying chat client implementation to another model, such as Azure OpenAI, without changing any other code.
* Creates a `ChatHistory` object to store the messages between the user and the AI model.
* Retrieves a prompt from the user and stores it in the `ChatHistory`.
* Sends the chat data to the AI model to generate a response.

> [!NOTE]
> Ollama runs on port 11434 by default, which is why the AI model endpoint is set to `http://localhost:11434`.
Expand Down Expand Up @@ -146,4 +146,4 @@ The Semantic Kernel SDK provides many services and features to connect to AI mod

## Next steps

- [Generate text and conversations with .NET and Azure OpenAI Completions](/training/modules/open-ai-dotnet-text-completions/)
* [Generate text and conversations with .NET and Azure OpenAI Completions](/training/modules/open-ai-dotnet-text-completions/)
14 changes: 7 additions & 7 deletions docs/ai/quickstarts/create-assistant.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,27 @@ Complete the following steps to create a .NET console app and add the package ne

## Create the AI assistant client

1. Open the _Program.cs_ file and replace the contents of the file with the following code to create the required clients:
1. Open the `Program.cs` file and replace the contents of the file with the following code to create the required clients:

:::code language="csharp" source="snippets/assistants/program.cs" range="0-17" :::
:::code language="csharp" source="snippets/assistants/program.cs" id="CreateClient" :::

1. Create an in-memory sample document and upload it to the `OpenAIFileClient`:

:::code language="csharp" source="snippets/assistants/program.cs" range="19-53" :::
:::code language="csharp" source="snippets/assistants/program.cs" id="CreateDocument" :::

1. Enable file search and code interpreter tooling capabilities via the `AssistantCreationOptions`:

:::code language="csharp" source="snippets/assistants/program.cs" range="55-78" :::
:::code language="csharp" source="snippets/assistants/program.cs" id="EnableTools" :::

1. Create the `Assistant` and a thread to manage interactions between the user and the assistant:

:::code language="csharp" source="snippets/assistants/program.cs" range="80-105" :::
:::code language="csharp" source="snippets/assistants/program.cs" id="CreateAssistant" :::

1. Print the messages and save the generated image from the conversation with the assistant:

:::code language="csharp" source="snippets/assistants/program.cs" range="107-147" :::
:::code language="csharp" source="snippets/assistants/program.cs" id="ProcessMessages" :::

Locate and open the saved image in the app *bin* directory, which should resemble the following:
Locate and open the saved image in the app `bin` directory, which should resemble the following:

:::image type="content" source="../media/assistants/generated-sales-graph.png" alt-text="A graph showing the visualization generated by the AI model.":::

Expand Down
7 changes: 7 additions & 0 deletions docs/ai/quickstarts/evaluate-ai-response.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ Complete the following steps to create an MSTest project that connects to the `g

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).

## Clean up resources

If you no longer need them, delete the Azure OpenAI resource and GPT-4 model deployment.

1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource.
1. Select the Azure OpenAI resource, and then select **Delete**.

## Next steps

- Evaluate the responses from different OpenAI models.
Expand Down
9 changes: 3 additions & 6 deletions docs/ai/quickstarts/generate-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ In this quickstart, you learn how to create a .NET console app to generate image

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

[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)]

## Create the app

Complete the following steps to create a .NET console app to connect to an AI model.
Expand Down Expand Up @@ -134,11 +132,10 @@ Complete the following steps to create a .NET console app to connect to an AI mo

## Clean up resources

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

```azdeveloper
azd down
```
1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource.
1. Select the Azure OpenAI resource, and then select **Delete**.

:::zone-end

Expand Down
14 changes: 0 additions & 14 deletions docs/ai/quickstarts/includes/clone-sample-repo.md

This file was deleted.

8 changes: 0 additions & 8 deletions docs/ai/quickstarts/includes/create-ai-service.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
## Create the AI service

# [Azure Portal or Azure CLI](#tab/azure-cli)

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.

1. From a terminal or command prompt, navigate to the root of your project directory.
Expand All @@ -13,9 +11,3 @@
dotnet user-secrets set AZURE_OPENAI_ENDPOINT <your-azure-openai-endpoint>
dotnet user-secrets set AZURE_OPENAI_GPT_NAME <your-azure-openai-model-name>
```

# [Azure Developer CLI](#tab/azd)

[!INCLUDE [deploy-azd](deploy-azd.md)]

---
17 changes: 0 additions & 17 deletions docs/ai/quickstarts/includes/deploy-azd.md

This file was deleted.

9 changes: 3 additions & 6 deletions docs/ai/quickstarts/prompt-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ In this quickstart, you learn how to create a .NET console chat app to connect t

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

[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)]

## Create the app

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

## Clean up resources

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

```azdeveloper
azd down
```
1. In the [Azure Portal](https://aka.ms/azureportal), navigate to the Azure OpenAI resource.
1. Select the Azure OpenAI resource, and then select **Delete**.

:::zone-end

Expand Down
17 changes: 14 additions & 3 deletions docs/ai/quickstarts/snippets/assistants/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OpenAI;
// <SnippetCreateClient>
using OpenAI;
using OpenAI.Assistants;
using OpenAI.Files;
using Azure.AI.OpenAI;
Expand All @@ -15,7 +16,9 @@
#pragma warning disable OPENAI001
AssistantClient assistantClient = openAIClient.GetAssistantClient();
OpenAIFileClient fileClient = openAIClient.GetOpenAIFileClient();
// </SnippetCreateClient>

// <SnippetCreateDocument>
// Create an in-memory document to upload to the file client
using Stream document = BinaryData.FromBytes("""
{
Expand Down Expand Up @@ -51,7 +54,9 @@
document,
"monthly_sales.json",
FileUploadPurpose.Assistants);
// </SnippetCreateDocument>

// <SnippetEnableTools>
// Configure the assistant options
AssistantCreationOptions assistantOptions = new()
{
Expand All @@ -76,7 +81,9 @@
}
},
};
// </SnippetEnableTools>

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

Expand All @@ -100,10 +107,13 @@
var messages = assistantClient.GetMessagesAsync(
threadRun.ThreadId,
new MessageCollectionOptions()
{
{
Order = MessageCollectionOrder.Ascending
});
// </SnippetCreateAssistant>

// <SnippetProcessMessages>
// Process the messages from the assistant
await foreach (ThreadMessage message in messages)
{
// Print out the messages from the assistant
Expand Down Expand Up @@ -144,4 +154,5 @@
}
}
Console.WriteLine();
}
}
// </SnippetProcessMessages>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Azure.AI.OpenAI;
using Azure.Identity;

// <SnippetGetChatClient>
IConfigurationRoot config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
string deployment = config["AZURE_OPENAI_GPT_NAME"];
Expand All @@ -11,7 +12,9 @@
new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
.GetChatClient(deployment)
.AsIChatClient();
// </SnippetGetChatClient>

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

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