Skip to content

Commit 2d75e96

Browse files
committed
restructure
1 parent 6512975 commit 2d75e96

File tree

4 files changed

+181
-138
lines changed

4 files changed

+181
-138
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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. 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.
99

1010
```bash
1111
git clone https://github.com/dotnet/ai-samples.git
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
## Create the app
3+
4+
1. In an empty directory on your computer, use the `dotnet new` command to create a new console app:
5+
6+
```dotnetcli
7+
dotnet new console -o ExtensionsAI
8+
```
9+
10+
1. Change directory into the app folder:
11+
12+
```dotnetcli
13+
cd ExtensionsAI
14+
```
15+
16+
1. Install the required packages:
17+
18+
# [Azure OpenAI](#tab/azure-openai)
19+
20+
```bash
21+
dotnet add package OpenAI
22+
dotnet add package Microsoft.Extensions.AI
23+
dotnet add package Microsoft.Extensions.Configuration
24+
dotnet add package Microsoft.Extensions.Configuration.UserSecrets
25+
```
26+
27+
# [OpenAI](#tab/openai)
28+
29+
```bash
30+
dotnet add package Azure.AI.OpenAI
31+
dotnet add package Microsoft.Extensions.AI
32+
dotnet add package Microsoft.Extensions.Configuration
33+
dotnet add package Microsoft.Extensions.Configuration.UserSecrets
34+
```
35+
36+
---
37+
38+
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.
54+
55+
:::code language="csharp" source="./snippets/prompt-completion/extensions-ai/azure-openai/program.cs" range="6-8":::
56+
57+
# [OpenAI](#tab/openai)
58+
59+
:::code language="csharp" source="./snippets/prompt-completion/extensions-ai/openai/program.cs" range="5-7":::
60+
61+
---
62+
63+
1. Add the following code to create an `IChatClient` service configured to connect to the AI Model:
64+
65+
# [Azure OpenAI](#tab/azure-openai)
66+
67+
:::code language="csharp" source="./snippets/prompt-completion/extensions-ai/azure-openai/program.cs" range="10-12":::
68+
69+
# [OpenAI](#tab/openai)
70+
71+
:::code language="csharp" source="./snippets/prompt-completion/extensions-ai/openai/program.cs" range="10-11":::
72+
73+
---
74+
75+
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.
78+
79+
:::code language="csharp" source="./snippets/prompt-completion/extensions-ai/openai/program.cs" range="14-22":::
80+
81+
Customize the text content of the `benefits.md` file or the length of the summary to see the differences in the responses.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
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.
2+
3+
## Prerequisites
4+
5+
# [Azure OpenAI](#tab/azure-openai)
6+
7+
[!INCLUDE [azure-openai-prereqs](includes/prerequisites-azure-openai.md)]
8+
9+
# [OpenAI](#tab/openai)
10+
11+
[!INCLUDE [openai-prereqs](includes/prerequisites-openai.md)]
12+
13+
---
14+
15+
## Get the sample project
16+
17+
[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)]
18+
19+
## Try the hiking benefits sample
20+
21+
# [OpenAI](#tab/openai)
22+
23+
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.
60+
61+
# [OpenAI](#tab/openai)
62+
63+
:::code language="csharp" source="./snippets/prompt-completion/semantic-kernel/openai/program.cs" range="5-13":::
64+
65+
# [Azure OpenAI](#tab/azure-openai)
66+
67+
> [!NOTE]
68+
> `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.
69+
70+
:::code language="csharp" source="./snippets/prompt-completion/semantic-kernel/azure-openai/program.cs" range="6-14":::
71+
72+
---
73+
74+
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.
75+
76+
:::code language="csharp" source="./snippets/prompt-completion/semantic-kernel/openai/program.cs" range="15-20":::
77+
78+
The `InvokePromptAsync` function sends the `prompt` to the model to generate a response.
79+
80+
:::code language="csharp" source="./snippets/prompt-completion/semantic-kernel/openai/program.cs" range="22-24":::
81+
82+
Customize the text content of the `benefits.md` file or the length of the summary to see the differences in the responses.

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

Lines changed: 17 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ zone_pivot_groups: dotnet-ai-library
1212

1313
# Connect to and prompt an AI model using .NET
1414

15-
:::zone target="docs" pivot="microsoft-extensions-ai"
16-
1715
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.
1816

1917
## Prerequisites
@@ -28,160 +26,43 @@ In this quickstart, get started with AI by creating a .NET console chat app to c
2826

2927
---
3028

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:
34-
35-
```dotnetcli
36-
dotnet new console -o ExtensionsAI
37-
```
38-
39-
1. Change directory into the app folder:
40-
41-
```dotnetcli
42-
cd ExtensionsAI
43-
```
44-
45-
1. Install the required packages:
46-
47-
```bash
48-
dotnet add package Azure.AI.OpenAI
49-
dotnet add package Microsoft.Extensions.AI.OpenAI
50-
dotnet add package Microsoft.Extensions.Configuration
51-
dotnet add package Microsoft.Extensions.Configuration.UserSecrets
52-
```
53-
54-
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:
65-
66-
# [OpenAI](#tab/openai)
67-
68-
:::code language="csharp" source="./snippets/prompt-completion/extensions-ai/openai/program.cs" range="5-7":::
69-
70-
# [Azure OpenAI](#tab/azure-openai)
71-
72-
> [!NOTE]
73-
> `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.
74-
75-
:::code language="csharp" source="./snippets/prompt-completion/extensions-ai/azure-openai/program.cs" range="6-8":::
76-
77-
---
78-
79-
1. Add the following code to create an `IChatClient` service configured to connect to the AI Model:
80-
81-
# [OpenAI](#tab/openai)
82-
83-
:::code language="csharp" source="./snippets/prompt-completion/extensions-ai/openai/program.cs" range="10-11":::
84-
85-
# [Azure OpenAI](#tab/azure-openai)
86-
87-
:::code language="csharp" source="./snippets/prompt-completion/extensions-ai/azure-openai/program.cs" range="10-12":::
88-
89-
---
90-
91-
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.
94-
95-
:::code language="csharp" source="./snippets/prompt-completion/extensions-ai/openai/program.cs" range="14-22":::
96-
97-
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.
104-
105-
## Prerequisites
106-
107-
# [OpenAI](#tab/openai)
108-
109-
[!INCLUDE [openai-prereqs](includes/prerequisites-openai.md)]
110-
111-
# [Azure OpenAI](#tab/azure-openai)
112-
113-
[!INCLUDE [azure-openai-prereqs](includes/prerequisites-azure-openai.md)]
114-
115-
---
116-
117-
## Get the sample project
29+
## Clone the sample repository
11830

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

121-
## Try the hiking benefits sample
33+
## Create the AI service
12234

123-
# [OpenAI](#tab/openai)
35+
# [Azure OpenAI](#tab/azd)
12436

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

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
12840

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)]
14142

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
14344

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

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

16349
# [OpenAI](#tab/openai)
16450

165-
:::code language="csharp" source="./snippets/prompt-completion/semantic-kernel/openai/program.cs" range="5-13":::
166-
167-
# [Azure OpenAI](#tab/azure-openai)
168-
169-
> [!NOTE]
170-
> `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.
171-
172-
:::code language="csharp" source="./snippets/prompt-completion/semantic-kernel/azure-openai/program.cs" range="6-14":::
51+
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.
17352

17453
---
17554

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.
55+
:::zone target="docs" pivot="microsoft-extensions-ai"
56+
57+
[!INCLUDE [extensions-ai](includes/connect-prompt/extensions-ai.md)]
17758

178-
:::code language="csharp" source="./snippets/prompt-completion/semantic-kernel/openai/program.cs" range="15-20":::
59+
:::zone-end
17960

180-
The `InvokePromptAsync` function sends the `prompt` to the model to generate a response.
61+
:::zone target="docs" pivot="semantic-kernel"
18162

182-
:::code language="csharp" source="./snippets/prompt-completion/semantic-kernel/openai/program.cs" range="22-24":::
63+
[!INCLUDE [extensions-ai](includes/connect-prompt/semantic-kernel.md)]
18364

184-
Customize the text content of the `benefits.md` file or the length of the summary to see the differences in the responses.
65+
:::zone-end
18566

18667
## Clean up resources
18768

@@ -191,7 +72,6 @@ When you no longer need the sample application or resources, remove the correspo
19172
azd down
19273
```
19374

194-
:::zone-end
19575

19676
## Next steps
19777

0 commit comments

Comments
 (0)