You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ai/quickstarts/includes/clone-sample-repo.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ ms.date: 07/03/2024
5
5
ms.topic: include
6
6
---
7
7
8
-
Clone the GitHub repository that contains the sample apps for all of the quickstarts. You can also create your own app and follow along using the code snippets in the sections ahead.
8
+
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.
1. Open the app in Visual Studio code or your editor of choice
39
+
40
+
```bash
41
+
code .
42
+
```
43
+
44
+
## Build the app
45
+
46
+
The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Microsoft.Extensions.AI) package to send and receive requests to the OpenAI service.
47
+
48
+
1. In the **Program.cs** file, add the following code to connect and authenticate to the AI model:
49
+
50
+
# [Azure OpenAI](#tab/azure-openai)
51
+
52
+
> [!NOTE]
53
+
> `DefaultAzureCredential` searches for credentials from your local environment and tooling. If you are not using the `azd` template to provision the Azure OpenAI resource, assign the `Azure AI Developer` role manually to the account you used to sign-in to Visual Studio or the Azure CLI.
The `OpenAI` and `Azure.AI.OpenAI` libraries implement types defined in the `Microsoft.Extensions.AI` library, which enables you to code using the `IChatClient` interface abstraction. This abstraction allows you to change the underlying AI provider to other services by updating only a few lines of code, such as Ollama or Azure Inference models.
76
+
77
+
1. Use the `CompleteAsync` function to send a `prompt` to the model to generate a response.
In this quickstart, get started with AI by creating a .NET console chat app to connect to and prompt an OpenAI or Azure OpenAI model. The app runs locally and uses the [Semantic Kernel](/semantic-kernel/overview/) SDK.
1. From a terminal or command prompt, navigate to the `src\quickstarts\semantic-kernel\openai\01-HikeBenefitsSummary` directory.
24
+
25
+
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
26
+
27
+
```bash
28
+
dotnet user-secrets init
29
+
dotnet user-secrets set OpenAIKey <your-openai-key>
30
+
```
31
+
32
+
1. Use the `dotnet run`command to run the app:
33
+
34
+
```dotnetcli
35
+
dotnet run
36
+
```
37
+
38
+
# [Azure OpenAI](#tab/azure-openai)
39
+
40
+
1. From a terminal or command prompt, navigate to the `src\quickstarts\semantic-kernel\azure-openai\01-HikeBenefitsSummary` directory.
41
+
42
+
> [!NOTE]
43
+
> The Azure OpenAI scenario assumes the use of `azd` to provision an Azure OpenAI resource and configure essential permissions. Your can also [provision an Azure OpenAI resource](/azure/ai-services/openai/how-to/create-resource) using another tool such as the Azure portal or Azure CLI.
44
+
45
+
1. Run the `azd up`command to provision the Azure OpenAI resource using the [Azure Developer CLI](/developer/azure-developer-cli/overview). `azd` provisions the Azure OpenAI resources and configures permissions for you.
46
+
47
+
1. Use the `dotnet run`command to run the app:
48
+
49
+
```dotnetcli
50
+
dotnet run
51
+
```
52
+
53
+
---
54
+
55
+
## Explore the code
56
+
57
+
The app uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to the OpenAI service.
58
+
59
+
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. The `Kernel` class facilitates the requests and responses and registers an `OpenAIChatCompletion` service.
>`DefaultAzureCredential` searches for credentials from your local tooling. If you are not 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.
Once the `Kernel` is created, the app code reads the `benefits.md` file content and uses it to create a `prompt` for model. The prompt instructs the model to summarize the file text content.
In this quickstart, get started with AI by creating a .NET console chat app to connect to and prompt an OpenAI or Azure OpenAI model. The app uses abstractions from the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Microsoft.Extensions.AI) library that allow you to easily update the underlying AI model without requiring changes to your app logic.
18
16
19
17
## Prerequisites
@@ -28,160 +26,43 @@ In this quickstart, get started with AI by creating a .NET console chat app to c
28
26
29
27
---
30
28
31
-
## Create the app
32
-
33
-
1. In an empty directory on your computer, use the `dotnet new` command to create a new console app:
1. Open the app in Visual Studio code or your editor of choice
55
-
56
-
```bash
57
-
code.
58
-
```
59
-
60
-
## Add the code
61
-
62
-
The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Microsoft.Extensions.AI) package to send and receive requests to the OpenAI service.
63
-
64
-
1. In the **Program.cs** file, add the following code to connect and authenticate to the AI model:
> `DefaultAzureCredential` searches for credentials from your local environment and tooling. If you are not using the `azd` template to provision the Azure OpenAI resource, assign the `Azure AI Developer` role manually to the account you used to sign-in to Visual Studio or the Azure CLI.
The `OpenAI` and `Azure.AI.OpenAI` libraries implement types defined in the `Microsoft.Extensions.AI` library, which enables you to code using the `IChatClient` interface abstraction. This abstraction allows you to change the underlying AI provider to other services by updating only a few lines of code, such as Ollama or Azure Inference models.
92
-
93
-
1. Use the `CompleteAsync` function to send a `prompt` to the model to generate a response.
Customize the text content of the `benefits.md` file or the length of the summary to see the differences in the responses.
98
-
99
-
:::zone-end
100
-
101
-
:::zone target="docs" pivot="semantic-kernel"
102
-
103
-
In this quickstart, get started with AI by creating a .NET console chat app to connect to and prompt an OpenAI or Azure OpenAI model. The app runs locally and uses the [Semantic Kernel](/semantic-kernel/overview/) SDK.
1. From a terminal or command prompt, navigate to the `src\quickstarts\semantic-kernel\openai\01-HikeBenefitsSummary` directory.
37
+
Choose of the options below to create an Azure OpenAI service.
126
38
127
-
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
39
+
### Use the Azure Developer CLI
128
40
129
-
```bash
130
-
dotnet user-secrets init
131
-
dotnet user-secrets set OpenAIKey <your-openai-key>
132
-
```
133
-
134
-
1. Use the `dotnet run`command to run the app:
135
-
136
-
```dotnetcli
137
-
dotnet run
138
-
```
139
-
140
-
# [Azure OpenAI](#tab/azure-openai)
41
+
[!INCLUDE [deploy-azd](includes/deploy-azd.md)]
141
42
142
-
1. From a terminal or command prompt, navigate to the `src\quickstarts\semantic-kernel\azure-openai\01-HikeBenefitsSummary` directory.
43
+
### Use the Azure portal or Azure CLI
143
44
144
-
> [!NOTE]
145
-
> The Azure OpenAI scenario assumes the use of `azd` to provision an Azure OpenAI resource and configure essential permissions. Your can also [provision an Azure OpenAI resource](/azure/ai-services/openai/how-to/create-resource) using another tool such as the Azure portal or Azure CLI.
45
+
1. To provision an Azure OpenAI service using another tool such as the Azure portal or 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.
146
46
147
-
1. Run the `azd up`command to provision the Azure OpenAI resource using the [Azure Developer CLI](/developer/azure-developer-cli/overview). `azd` provisions the Azure OpenAI resources and configures permissions for you.
148
-
149
-
1. Use the `dotnet run`command to run the app:
150
-
151
-
```dotnetcli
152
-
dotnet run
153
-
```
154
-
155
-
---
156
-
157
-
## Explore the code
158
-
159
-
The app uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to the OpenAI service.
160
-
161
-
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. The `Kernel` class facilitates the requests and responses and registers an `OpenAIChatCompletion` service.
47
+
1. Assign the `Azure AI Developer` role to the account you used to sign-in to Visual Studio or the Azure CLI. The sample app uses a secretless approach to connect to the Azure OpenAI service using Microsoft Entra ID.
>`DefaultAzureCredential` searches for credentials from your local tooling. If you are not 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.
If you plan to use an OpenAI Model, this quickstart assumes you already have a service setup and available. You'll need the access key and AI service endpoint to connect your code.
173
52
174
53
---
175
54
176
-
Once the `Kernel` is created, the app code reads the `benefits.md` file content and uses it to create a `prompt` for model. The prompt instructs the model to summarize the file text content.
0 commit comments