Skip to content

Commit a584126

Browse files
Merge pull request #43887 from dotnet/main
Merge main into live
2 parents 61e709b + 171d64c commit a584126

34 files changed

+875
-246
lines changed

.github/ISSUE_TEMPLATE/02-breaking-change.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ labels:
66
- Pri1
77
- doc-idea
88
assignees:
9-
- gewarren
9+
- camsoper
1010
body:
1111
- type: textarea
1212
id: description
@@ -21,15 +21,14 @@ body:
2121
label: Version
2222
description: What version of .NET introduced the breaking change?
2323
options:
24-
- .NET 8 GA
25-
- .NET 9 Preview 7
26-
- .NET 9 RC 1
27-
- .NET 9 RC 2
28-
- .NET 9 GA
24+
- .NET 8
25+
- .NET 9
2926
- .NET 10 Preview 1
3027
- .NET 10 Preview 2
3128
- .NET 10 Preview 3
3229
- .NET 10 Preview 4
30+
- .NET 10 Preview 5
31+
- .NET 10 Preview 6
3332
- Other (please put exact version in description textbox)
3433
validations:
3534
required: true

docs/ai/quickstarts/get-started-openai.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ In this quickstart, you learn how to create a conversational .NET console chat a
2929

3030
:::zone-end
3131

32-
[!INCLUDE [semantic-kernel](../../azure/includes/semantic-kernel.md)]
32+
[!INCLUDE [semantic-kernel](includes/semantic-kernel.md)]
3333

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

File renamed without changes.

docs/ai/quickstarts/quickstart-azure-openai-tool.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ In this quickstart, you create a .NET console AI chat app to connect to an AI mo
2929

3030
:::zone-end
3131

32-
[!INCLUDE [semantic-kernel](../../azure/includes/semantic-kernel.md)]
32+
[!INCLUDE [semantic-kernel](includes/semantic-kernel.md)]
3333

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

docs/ai/quickstarts/quickstart-local-ai.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
2-
title: Quickstart - Connect to and chat with a local AI using .NET and Semantic Kernel
3-
description: Set up a local AI model and chat with it using a .NET console app and the Semantic Kernel SDK
2+
title: Quickstart - Connect to and chat with a local AI using .NET
3+
description: Set up a local AI model and chat with it using a .NET console app and the Microsoft.Extensions.AI libraries
44
ms.date: 11/24/2024
55
ms.topic: quickstart
66
ms.custom: devx-track-dotnet, devx-track-dotnet-ai
77
author: alexwolfmsft
88
ms.author: alexwolf
99
---
1010

11-
# Chat with a local AI model using .NET and Semantic Kernel
11+
# Chat with a local AI model using .NET
1212

13-
Local AI models provide powerful and flexible options for building AI solutions. In this quickstart, you'll explore how to set up and connect to a local AI model using .NET and the Semantic Kernel SDK. For this example, you'll run the local AI model using Ollama.
13+
In this quickstart, you learn how to create a conversational .NET console chat app using an OpenAI or Azure OpenAI model. The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/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.
1414

1515
## Prerequisites
1616

@@ -51,14 +51,13 @@ Complete the following steps to create a .NET console app that will connect to y
5151
1. In a terminal window, navigate to an empty directory on your device and create a new app with the `dotnet new` command:
5252

5353
```dotnetcli
54-
dotnet new console
54+
dotnet new console -o LocalAI
5555
```
5656

57-
1. Add the [Semantic Kernel SDK](https://www.nuget.org/packages/Microsoft.SemanticKernel) and the [Semantic Kernel Ollama Connector](https://www.nuget.org/packages/Microsoft.SemanticKernel.Connectors.Ollama/1.25.0-alpha) packages to your app:
57+
1. Add the [Microsoft.Extensions.AI.Ollama](https://aka.ms/meai-ollama-nuget) packages to your app:
5858

5959
```dotnetcli
60-
dotnet add package Microsoft.SemanticKernel
61-
dotnet add package Microsoft.SemanticKernel.Connectors.Ollama
60+
dotnet add package Microsoft.Extensions.AI.Ollama --prerelease
6261
```
6362

6463
1. Open the new app in your editor of choice, such as Visual Studio Code.
@@ -75,8 +74,11 @@ The Semantic Kernel SDK provides many services and features to connect to AI mod
7574
7675
:::code language="csharp" source="snippets/local-ai/program.cs" :::
7776
78-
The preceding code accomplishes the following tasks:
79-
- Creates a `Kernel` object and uses it to retrieve a chat completion service.
77+
The preceding code accomplishes the following:
78+
79+
- Creates an `OllamaChatClient` that implements the `IChatClient` interface.
80+
- This interface provides a loosely coupled abstraction you can use to chat with AI Models.
81+
- You can later change the underlying chat client implementation to another model, such as Azure OpenAI, without changing any other code.
8082
- Creates a `ChatHistory` object to store the messages between the user and the AI model.
8183
- Retrieves a prompt from the user and stores it in the `ChatHistory`.
8284
- Sends the chat data to the AI model to generate a response.
Lines changed: 63 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,134 @@
11
---
22
title: Quickstart - Generate images using AI with .NET
3-
description: Create a simple app using OpenAI to generate postal card images.
3+
description: Create a simple app using to generate images using .NET and the OpenAI or Azure OpenAI models.
44
ms.date: 07/17/2024
55
ms.topic: quickstart
66
ms.custom: devx-track-dotnet, devx-track-dotnet-ai
77
author: fboucher
88
ms.author: frbouche
99
zone_pivot_groups: openai-library
10-
# CustomerIntent: As a .NET developer new to Azure OpenAI, I want deploy and use sample code to interact to learn how to generate images from the sample code.
10+
# CustomerIntent: As a .NET developer new to OpenAI, I want deploy and use sample code to interact to learn from the sample code to generate images.
1111
---
1212

1313
# Generate images using AI with .NET
1414

15-
:::zone target="docs" pivot="openai"
15+
In this quickstart, you learn how to create a .NET console app to generate images using an OpenAI or Azure OpenAI DALLe AI model, which are specifically designed to generate images based on text prompts.
1616

17-
Get started with AI by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `dall-e-3` model to generate postal card images so you can invite your friends for a hike! Follow these steps to get access to OpenAI and learn how to use Semantic Kernel.
17+
:::zone target="docs" pivot="openai"
1818

19-
[!INCLUDE [download-alert](includes/prerequisites-openai.md)]
19+
[!INCLUDE [openai-prereqs](includes/prerequisites-openai.md)]
2020

2121
:::zone-end
2222

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

25-
Get started with AI by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `dall-e-3` model to generate postal card images so you can invite your friends for a hike! Follow these steps to provision Azure OpenAI and learn how to use the .NET Azure OpenAI SDK.
26-
27-
[!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)]
25+
[!INCLUDE [azure-openai-prereqs](includes/prerequisites-azure-openai.md)]
2826

2927
:::zone-end
3028

31-
## Get the sample project
29+
[!INCLUDE [semantic-kernel](includes/semantic-kernel.md)]
3230

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

35-
:::zone target="docs" pivot="azure-openai"
33+
## Create the app
3634

37-
## Create the Azure OpenAI service
35+
Complete the following steps to create a .NET console app to connect to an AI model.
3836

39-
# [Azure Developer CLI](#tab/azd)
37+
1. In an empty directory on your computer, use the `dotnet new` command to create a new console app:
4038

41-
[!INCLUDE [deploy-azd](includes/deploy-azd.md)]
39+
```dotnetcli
40+
dotnet new console -o ImagesAI
41+
```
4242
43-
# [Azure CLI](#tab/azure-cli)
43+
1. Change directory into the app folder:
4444
45-
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.
45+
```dotnetcli
46+
cd ImagesAI
47+
```
4648
47-
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\semantic-kernel\05-HikeImages` directory.
49+
1. Install the required packages:
4850
49-
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
51+
:::zone target="docs" pivot="azure-openai"
5052
5153
```bash
52-
dotnet user-secrets init
53-
dotnet user-secrets set OpenAIKey <your-openai-key>
54+
dotnet add package Azure.AI.OpenAI
55+
dotnet add package Microsoft.Extensions.Configuration
56+
dotnet add package Microsoft.Extensions.Configuration.UserSecrets
57+
```
5458
55-
# [Azure Portal](#tab/azure-portal)
59+
:::zone-end
5660
57-
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.
61+
:::zone target="docs" pivot="openai"
5862
59-
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\semantic-kernel\05-HikeImages` directory.
63+
```bash
64+
dotnet add package OpenAI
65+
dotnet add package Microsoft.Extensions.Configuration
66+
dotnet add package Microsoft.Extensions.Configuration.UserSecrets
67+
```
6068
61-
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
69+
:::zone-end
70+
71+
1. Open the app in Visual Studio Code or your editor of choice.
6272
6373
```bash
64-
dotnet user-secrets init
65-
dotnet user-secrets set OpenAIKey <your-openai-key>
74+
code .
75+
```
6676
67-
---
77+
:::zone target="docs" pivot="azure-openai"
6878
69-
:::zone-end
79+
[!INCLUDE [create-ai-service](includes/create-ai-service.md)]
7080
71-
## Try the the hiking images sample
81+
:::zone-end
7282
7383
:::zone target="docs" pivot="openai"
7484
75-
1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples)
85+
## Configure the app
86+
87+
1. Navigate to the root of your .NET project from a terminal or command prompt.
7688
7789
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
7890
7991
```bash
8092
dotnet user-secrets init
8193
dotnet user-secrets set OpenAIKey <your-openai-key>
82-
```
83-
84-
1. Use the `dotnet run` command to run the app:
85-
86-
```dotnetcli
87-
dotnet run
94+
dotnet user-secrets set ModelName <your-openai-model-name>
8895
```
8996
9097
:::zone-end
9198
92-
:::zone target="docs" pivot="azure-openai"
99+
## Add the app code
93100
94-
1. From a terminal or command prompt, navigate to the `azure-openai\semantic-kernel\05-HikeImages` directory.
101+
1. In the **Program.cs** file, add the following code to connect and authenticate to the AI model.
95102
96-
2. Use the `dotnet run` command to run the app:
103+
:::zone target="docs" pivot="azure-openai"
97104
98-
```dotnetcli
99-
dotnet run
100-
```
101-
102-
> [!TIP]
103-
> If you get an error message, the Azure OpenAI resources might not have finished deploying. Wait a couple of minutes and try again.
104-
105-
:::zone-end
106-
107-
## Explore the code
108-
109-
:::zone target="docs" pivot="openai"
110-
111-
The application uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to the OpenAI service.
112-
113-
The _Program.cs_ file contains all of the app code. The first several lines of code set configuration values and get the OpenAI Key that was previously set using the `dotnet user-secrets` command.
114-
115-
```csharp
116-
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
117-
string key = config["OpenAIKey"];
118-
```
119-
120-
The `OpenAITextToImageService` service facilitates the requests and responses.
121-
122-
```csharp
123-
OpenAITextToImageService textToImageService = new(key, null);
124-
```
125-
126-
:::zone-end
127-
128-
:::zone target="docs" pivot="azure-openai"
105+
:::code language="csharp" source="snippets/image-generation/azure-openai/program.cs" :::
129106
130-
The application uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to the Azure OpenAI service.
107+
> [!NOTE]
108+
> <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](/dotnet/ai/azure-ai-services-authentication).
131109
132-
The _Program.cs_ file contains all of the app code. The first several lines of code load secrets and configuration values that were set in the `dotnet user-secrets` for you during the application provisioning.
110+
:::zone-end
133111
134-
```csharp
135-
// Retrieve the local secrets saved during the Azure deployment
136-
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
137-
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
138-
string deployment = config["AZURE_OPENAI_GPT_NAME"];
139-
```
112+
:::zone target="docs" pivot="openai"
140113
141-
The `AzureOpenAITextToImageService` service facilitates the requests and responses.
114+
:::code language="csharp" source="snippets/image-generation/openai/program.cs" :::
142115
143-
```csharp
144-
AzureOpenAITextToImageService textToImageService = new(deployment, endpoint, new DefaultAzureCredential(), null);
145-
```
116+
:::zone-end
146117
147-
:::zone-end
118+
The preceding code:
148119
149-
Provide context and instructions to the model by adding a system prompt. A good image generation prompt requires a clear description of what the image is, which colors to use, the intended style, and other descriptors.
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
150124
151-
The `GenerateImageAsync` function instructs the model to generate a response based on the user prompt and image size and quality configurations.
152-
153-
```csharp
154-
// Generate the image
155-
string imageUrl = await textToImageService.GenerateImageAsync("""
156-
A postal card with a happy hiker waving and a beautiful mountain in the background.
157-
There is a trail visible in the foreground.
158-
The postal card has text in red saying: 'You are invited for a hike!'
159-
""", 1024, 1024);
125+
1. Use the `dotnet run` command to run the app:
160126
161-
Console.WriteLine($"The generated image is ready at:\n{imageUrl}");
162-
```
127+
```dotnetcli
128+
dotnet run
129+
```
163130
164-
Customize the prompt to personalize the images generated by the model.
131+
Navigate to the image URL in the console output to view the generated image. Customize the text content of the prompt to create new images or modify the original.
165132
166133
:::zone target="docs" pivot="azure-openai"
167134
@@ -173,11 +140,9 @@ When you no longer need the sample application or resources, remove the correspo
173140
azd down
174141
```
175142

176-
[!INCLUDE [troubleshoot](includes/troubleshoot.md)]
177-
178143
:::zone-end
179144

180145
## Next steps
181146

182-
- [Quickstart - Summarize text using an AI chat app with .NET](quickstart-openai-summarize-text.md)
147+
- [Quickstart - Build an AI chat app with .NET](get-started-openai.md)
183148
- [Generate text and conversations with .NET and Azure OpenAI Completions](/training/modules/open-ai-dotnet-text-completions/)

docs/ai/quickstarts/quickstart-openai-summarize-text.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Quickstart - Summarize text using an AI chat app with .NET
3-
description: Create a simple chat app using Microsoft.Extensions.AI and the Semantic Kernel SDK to summarize a text.
3+
description: Create a simple chat app using Microsoft.Extensions.AI to summarize a text.
44
ms.date: 07/17/2024
55
ms.topic: quickstart
66
ms.custom: devx-track-dotnet, devx-track-dotnet-ai
@@ -29,7 +29,7 @@ In this quickstart, you learn how to create a .NET console chat app to connect t
2929

3030
:::zone-end
3131

32-
[!INCLUDE [semantic-kernel](../../azure/includes/semantic-kernel.md)]
32+
[!INCLUDE [semantic-kernel](includes/semantic-kernel.md)]
3333

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Azure.Identity" Version="1.13.1" />
12+
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0-beta.1" />
13+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
14+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
15+
16+
</ItemGroup>
17+
18+
</Project>

0 commit comments

Comments
 (0)