Skip to content

Commit 2a1467c

Browse files
Meai conversion (#43405)
* Update quickstart to use the Microsoft Extensions AI library Co-authored-by: Genevieve Warren <[email protected]> --------- Co-authored-by: Genevieve Warren <[email protected]>
1 parent 1cddcb9 commit 2a1467c

17 files changed

+255
-143
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Get started with OpenAI and [Semantic Kernel](../semantic-kernel-dotnet-overview
4848

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

51-
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\02-HikerAI` directory.
51+
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\semantic-kernel\02-HikerAI` directory.
5252

5353
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
5454

@@ -60,7 +60,7 @@ Get started with OpenAI and [Semantic Kernel](../semantic-kernel-dotnet-overview
6060

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

63-
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\02-HikerAI` directory.
63+
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\semantic-kernel\02-HikerAI` directory.
6464

6565
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
6666

@@ -77,7 +77,7 @@ Get started with OpenAI and [Semantic Kernel](../semantic-kernel-dotnet-overview
7777
<!-- markdownlint-disable MD029 MD044 -->
7878
:::zone target="docs" pivot="openai"
7979
80-
1. From a terminal or command prompt, navigate to the `openai\02-HikerAI` directory.
80+
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\semantic-kernel\02-HikerAI` directory.
8181
8282
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
8383
@@ -96,7 +96,7 @@ Get started with OpenAI and [Semantic Kernel](../semantic-kernel-dotnet-overview
9696

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

99-
1. From a terminal or command prompt, navigate to the `azure-openai\02-HikerAI` directory.
99+
1. From a terminal or command prompt, navigate to the `semantic-kernel\02-HikerAI` directory.
100100

101101
2. Use the `dotnet run` command to run the app:
102102

@@ -147,14 +147,13 @@ The entire application is contained within the **Program.cs** file. The first se
147147
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
148148
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
149149
string deployment = config["AZURE_OPENAI_GPT_NAME"];
150-
string key = config["AZURE_OPENAI_KEY"];
151150
```
152151

153152
The `AzureOpenAIChatCompletionService` service facilitates the requests and responses.
154153

155154
```csharp
156155
// Create the Azure OpenAI Chat Completion Service
157-
AzureOpenAIChatCompletionService service = new(deployment, endpoint, key);
156+
AzureOpenAIChatCompletionService service = new(deployment, endpoint, new DefaultAzureCredential());
158157
```
159158
160159
:::zone-end

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

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

8-
Clone the GitHub repository that contains the sample apps for all of the quickstarts:
8+
## Clone the sample repository
9+
10+
You can create your own app and follow along the steps in the sections ahead, or you can clone the GitHub repository that contains the completed sample apps for all of the quickstarts. The sample repo is also structured as an Azure Developer CLI template that can provision an Azure OpenAI resource for you.
911

1012
```bash
1113
git clone https://github.com/dotnet/ai-samples.git
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## Create the AI service
2+
3+
# [Azure Developer CLI](#tab/azd)
4+
5+
[!INCLUDE [deploy-azd](deploy-azd.md)]
6+
7+
# [Azure CLI](#tab/azure-cli)
8+
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.
10+
11+
1. From a terminal or command prompt, navigate to the root of your project directory.
12+
13+
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
14+
15+
```bash
16+
dotnet user-secrets init
17+
dotnet user-secrets set AZURE_OPENAI_ENDPOINT <your-azure-openai-endpoint>
18+
dotnet user-secrets set AZURE_OPENAI_GPT_NAME <your-azure-openai-model-name>
19+
```
20+
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 OpenAI API key as a secret for the sample app:
28+
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+
```
34+
35+
---

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ ms.topic: include
77

88
The sample GitHub repository is structured as an Azure Developer CLI (`azd`) template, which `azd` can use to provision the Azure OpenAI service and model for you.
99

10-
1. From a terminal or command prompt, navigate to the _src\quickstarts\azure-openai_ directory of the sample repo.
10+
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai` directory of the sample repo.
1111
1. Run the `azd up` command to provision the Azure OpenAI resources. It might take several minutes to create the Azure OpenAI service and deploy the model.
1212

1313
```azdeveloper
1414
azd up
1515
```
1616

17-
`azd` also configures the required user secrets for the sample app, such as the OpenAI access key.
18-
19-
> [!NOTE]
20-
> If you encounter an error during the `azd up` deployment, visit the [troubleshooting](#troubleshoot) section.
17+
`azd` also configures the required user secrets for the sample app, such as the Azure OpenAI endpoint and model name.

docs/ai/quickstarts/includes/prerequisites-azure-openai.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ ms.topic: include
99

1010
- .NET 8 SDK - [Install the .NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0).
1111
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free).
12-
- Azure Developer CLI - [Install or update the Azure Developer CLI](/azure/developer/azure-developer-cli/install-azd).
1312
- Access to [Azure OpenAI service](/azure/ai-services/openai/overview#how-do-i-get-access-to-azure-openai).
14-
- On Windows, PowerShell `v7+` is required. To validate your version, run `pwsh` in a terminal. It should return the current version. If it returns an error, execute the following command: `dotnet tool update --global PowerShell`.
13+
- Azure Developer CLI (Optional) - [Install or update the Azure Developer CLI](/azure/developer/azure-developer-cli/install-azd).

docs/ai/quickstarts/quickstart-ai-chat-with-data.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Get started with AI development using a .NET 8 console app to connect to an Open
4646

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

49-
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\03-ChattingAboutMyHikes` directory.
49+
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\semantic-kernel\03-ChattingAboutMyHikes` directory.
5050

5151
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
5252

@@ -58,7 +58,7 @@ Get started with AI development using a .NET 8 console app to connect to an Open
5858

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

61-
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\03-ChattingAboutMyHikes` directory.
61+
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\semantic-kernel\03-ChattingAboutMyHikes` directory.
6262

6363
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
6464

@@ -75,7 +75,7 @@ Get started with AI development using a .NET 8 console app to connect to an Open
7575
<!-- markdownlint-disable MD029 MD044 -->
7676
:::zone target="docs" pivot="openai"
7777
78-
1. From a terminal or command prompt, navigate to the `openai\03-ChattingAboutMyHikes` directory.
78+
1. From a terminal or command prompt, navigate to the `src\quickstarts\openai\semantic-kernel\03-ChattingAboutMyHikes` directory.
7979
8080
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
8181
@@ -94,7 +94,7 @@ Get started with AI development using a .NET 8 console app to connect to an Open
9494

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

97-
1. From a terminal or command prompt, navigate to the `azure-openai\02-HikerAI` directory.
97+
1. From a terminal or command prompt, navigate to the `semantic-kernel\02-HikerAI` directory.
9898

9999
2. Use the `dotnet run` command to run the app:
100100

@@ -145,14 +145,13 @@ The entire application is contained within the **Program.cs** file. The first se
145145
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
146146
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
147147
string deployment = config["AZURE_OPENAI_GPT_NAME"];
148-
string key = config["AZURE_OPENAI_KEY"];
149148
```
150149

151150
The `AzureOpenAIChatCompletionService` service facilitates the requests and responses.
152151

153152
```csharp
154153
// == Create the Azure OpenAI Chat Completion Service ==========
155-
AzureOpenAIChatCompletionService service = new(deployment, endpoint, key);
154+
AzureOpenAIChatCompletionService service = new(deployment, endpoint, new DefaultAzureCredential());
156155
```
157156
158157
Once the `OpenAIChatCompletionService` client is created, the app reads the content of the file `hikes.md` and uses it to provide more context to the model by adding a system prompt. This influences model behavior and the generated completions during the conversation.

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap
4848

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

51-
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\04-HikerAIPro` directory.
51+
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\semantic-kernel\04-HikerAIPro` directory.
5252

5353
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
5454

@@ -60,7 +60,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap
6060

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

63-
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\04-HikerAIPro` directory.
63+
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\semantic-kernel\04-HikerAIPro` directory.
6464

6565
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
6666

@@ -77,7 +77,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap
7777
<!-- markdownlint-disable MD029 MD044 -->
7878
:::zone target="docs" pivot="openai"
7979
80-
1. From a terminal or command prompt, navigate to the `azure-openai\04-HikerAIPro` directory.
80+
1. From a terminal or command prompt, navigate to the `src\quickstarts\openai\semantic-kernel\04-HikerAIPro` directory.
8181
8282
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
8383
@@ -96,7 +96,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap
9696

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

99-
1. From a terminal or command prompt, navigate to the `azure-openai\04-HikerAIPro` directory.
99+
1. From a terminal or command prompt, navigate to the `semantic-kernel\04-HikerAIPro` directory.
100100

101101
2. Use the `dotnet run` command to run the app:
102102

@@ -149,7 +149,6 @@ The entire application is contained within the **Program.cs** file. The first se
149149
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
150150
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
151151
string deployment = config["AZURE_OPENAI_GPT_NAME"];
152-
string key = config["AZURE_OPENAI_KEY"];
153152
```
154153

155154
The `Kernel` class facilitates the requests and responses with the help of `AzureOpenAIChatCompletion` service.
@@ -159,7 +158,7 @@ The `Kernel` class facilitates the requests and responses with the help of `Azur
159158
IKernelBuilder b = Kernel.CreateBuilder();
160159
161160
Kernel kernel = b
162-
.AddAzureOpenAIChatCompletion(deployment, endpoint, key)
161+
.AddAzureOpenAIChatCompletion(deployment, endpoint, new DefaultAzureCredential())
163162
.Build();
164163
```
165164

docs/ai/quickstarts/quickstart-openai-generate-images.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap
4444

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

47-
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\05-HikeImages` directory.
47+
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\semantic-kernel\05-HikeImages` directory.
4848

4949
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
5050

@@ -56,7 +56,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap
5656

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

59-
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\05-HikeImages` directory.
59+
1. From a terminal or command prompt, navigate to the `src\quickstarts\azure-openai\semantic-kernel\05-HikeImages` directory.
6060

6161
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
6262

@@ -91,7 +91,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap
9191

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

94-
1. From a terminal or command prompt, navigate to the `azure-openai\05-HikeImages` directory.
94+
1. From a terminal or command prompt, navigate to the `azure-openai\semantic-kernel\05-HikeImages` directory.
9595

9696
2. Use the `dotnet run` command to run the app:
9797

@@ -136,13 +136,12 @@ The _Program.cs_ file contains all of the app code. The first several lines of c
136136
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
137137
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
138138
string deployment = config["AZURE_OPENAI_GPT_NAME"];
139-
string key = config["AZURE_OPENAI_KEY"];
140139
```
141140

142141
The `AzureOpenAITextToImageService` service facilitates the requests and responses.
143142

144143
```csharp
145-
AzureOpenAITextToImageService textToImageService = new(deployment, endpoint, key, null);
144+
AzureOpenAITextToImageService textToImageService = new(deployment, endpoint, new DefaultAzureCredential(), null);
146145
```
147146
148147
:::zone-end

0 commit comments

Comments
 (0)