Skip to content

Commit 13b0e0a

Browse files
committed
progress
1 parent c510dbe commit 13b0e0a

File tree

7 files changed

+129
-43
lines changed

7 files changed

+129
-43
lines changed

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

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ The `CompleteAsync` function sends the `prompt` to the model to generate a respo
107107
108108
:::code language="csharp" source="./snippets/prompt-completion/extensions-ai/azure-openai/program.cs" range="15-23":::
109109
110-
Customize the text content of the file or the length of the summary to see the differences in the responses.
111-
112110
:::zone-end
113111
112+
Customize the text content of the file or the length of the summary to see the differences in the responses.
113+
114114
:::zone target="docs" pivot="semantic-kernel"
115115
116116
Get started with AI by creating a simple .NET 8.0 console chat application to summarize text. The application runs locally and uses the OpenAI `gpt-3.5-turbo` model. Follow these steps to get access to OpenAI and learn how to use Semantic Kernel.
@@ -168,61 +168,28 @@ Get started with AI by creating a simple .NET 8.0 console chat application to su
168168
169169
The app uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to the OpenAI service.
170170
171-
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.
171+
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.
172172
173173
# [OpenAI](#tab/openai)
174174
175-
```csharp
176-
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
177-
string model = "gpt-3.5-turbo";
178-
string key = config["OpenAIKey"];
179-
```
175+
:::code language="csharp" source="./snippets/prompt-completion/semantic-kernel/openai/program.cs" range="5-13":::
180176
181177
# [Azure OpenAI](#tab/azure-openai)
182178
183-
```csharp
184-
// Retrieve the local secrets saved during the Azure deployment
185-
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
186-
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
187-
string deployment = config["AZURE_OPENAI_GPT_NAME"];
188-
string key = config["AZURE_OPENAI_KEY"];
189-
```
190-
191-
---
179+
> [!NOTE]
180+
> `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.
192181

193-
The `Kernel` class facilitates the requests and responses and registers an `OpenAIChatCompletion` service.
182+
:::code language="csharp" source="./snippets/prompt-completion/semantic-kernel/azure-openai/program.cs" range="6-14":::
194183

195-
```csharp
196-
// Create a Kernel containing the OpenAI Chat Completion Service
197-
Kernel kernel = Kernel.CreateBuilder()
198-
.AddOpenAIChatCompletion(model, key)
199-
.Build();
200-
```
184+
---
201185

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

204-
```csharp
205-
// Create and print out the prompt
206-
string prompt = $"""
207-
Please summarize the the following text in 20 words or less:
208-
{File.ReadAllText("benefits.md")}
209-
""";
210-
Console.WriteLine($"user >>> {prompt}");
211-
```
188+
:::code language="csharp" source="./snippets/prompt-completion/semantic-kernel/openai/program.cs" range="15-20":::
212189

213190
The `InvokePromptAsync` function sends the `prompt` to the model to generate a response.
214191

215-
```csharp
216-
// Submit the prompt and print out the response
217-
string response = await kernel.InvokePromptAsync<string>(
218-
prompt,
219-
new(new OpenAIPromptExecutionSettings()
220-
{
221-
MaxTokens = 400
222-
})
223-
);
224-
Console.WriteLine($"assistant >>> {response}");
225-
```
192+
:::code language="csharp" source="./snippets/prompt-completion/semantic-kernel/openai/program.cs" range="22-24":::
226193

227194
Customize the text content of the file or the length of the summary to see the differences in the responses.
228195

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Microsoft.Extensions.Configuration;
2+
using Microsoft.SemanticKernel;
3+
using Microsoft.SemanticKernel.Connectors.OpenAI;
4+
using Azure.Identity;
5+
6+
// Retrieve the Azure OpenAI endpoint and model name
7+
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
8+
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
9+
string deployment = config["AZURE_OPENAI_GPT_NAME"];
10+
11+
// Create a Kernel containing the Azure OpenAI Chat Completion Service
12+
Kernel kernel = Kernel.CreateBuilder()
13+
.AddAzureOpenAIChatCompletion(deployment, endpoint, new DefaultAzureCredential())
14+
.Build();
15+
16+
// Create and print out the prompt
17+
string prompt = $"""
18+
Please summarize the the following text in 20 words or less:
19+
{File.ReadAllText("benefits.md")}
20+
""";
21+
Console.WriteLine($"user >>> {prompt}");
22+
23+
// Submit the prompt and print out the response
24+
string response = await kernel.InvokePromptAsync<string>(prompt, new(new OpenAIPromptExecutionSettings() { MaxTokens = 400 }));
25+
Console.WriteLine($"assistant >>> {response}");
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
11+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
12+
<PackageReference Include="Microsoft.SemanticKernel" Version="1.6.2" />
13+
<PackageReference Include="Azure.Identity" Version="1.13.1" />
14+
</ItemGroup>
15+
16+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Hiking Benefits
2+
3+
**Hiking** is a wonderful activity that offers a plethora of benefits for both your body and mind. Here are some compelling reasons why you should consider starting hiking:
4+
5+
1. **Physical Fitness**:
6+
- **Cardiovascular Health**: Hiking gets your heart pumping, improving cardiovascular fitness. The varied terrain challenges your body and burns calories.
7+
- Strength and Endurance: Uphill climbs and uneven trails engage different muscle groups, enhancing strength and endurance.
8+
- Weight Management: Regular hiking can help you maintain a healthy weight.
9+
2. Mental Well-Being:
10+
- Stress Reduction: Nature has a calming effect. Hiking outdoors reduces stress, anxiety, and promotes relaxation.
11+
- Improved Mood: Fresh air, sunlight, and natural surroundings boost your mood and overall happiness.
12+
- Mindfulness: Disconnect from screens and immerse yourself in the present moment. Hiking encourages mindfulness.
13+
3. Connection with Nature:
14+
- Scenic Views: Explore breathtaking landscapes, from lush forests to mountain peaks. Nature's beauty rejuvenates the soul.
15+
- Wildlife Encounters: Spot birds, animals, and plant life. Connecting with nature fosters appreciation and wonder.
16+
4. Social Interaction:
17+
- Group Hikes: Join hiking clubs or go with friends. It's a great way to bond and share experiences.
18+
- Solitude: Solo hikes provide introspection and solitude, allowing you to recharge.
19+
5. Adventure and Exploration:
20+
- Discover Hidden Gems: Hiking takes you off the beaten path. Discover hidden waterfalls, caves, and scenic trails.
21+
- Sense of Accomplishment: Reaching a summit or completing a challenging trail gives a sense of achievement.
22+
Remember, hiking can be tailored to your fitness level—start with shorter, easier trails and gradually progress. Lace up those hiking boots and embark on an adventure!
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.Extensions.Configuration;
2+
using Microsoft.SemanticKernel;
3+
using Microsoft.SemanticKernel.Connectors.OpenAI;
4+
5+
// Retrieve the local secrets that were set from the command line
6+
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
7+
string model = "gpt-3.5-turbo";
8+
string key = config["OpenAIKey"];
9+
10+
// Create a Kernel containing the OpenAI Chat Completion Service
11+
Kernel kernel = Kernel.CreateBuilder()
12+
.AddOpenAIChatCompletion(model, key)
13+
.Build();
14+
15+
// Create and print out the prompt
16+
string prompt = $"""
17+
Please summarize the the following text in 20 words or less:
18+
{File.ReadAllText("benefits.md")}
19+
""";
20+
Console.WriteLine($"user >>> {prompt}");
21+
22+
// Submit the prompt and print out the response
23+
string response = await kernel.InvokePromptAsync<string>(prompt, new(new OpenAIPromptExecutionSettings() { MaxTokens = 400 }));
24+
Console.WriteLine($"assistant >>> {response}");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Hiking Benefits
2+
3+
**Hiking** is a wonderful activity that offers a plethora of benefits for both your body and mind. Here are some compelling reasons why you should consider starting hiking:
4+
5+
1. **Physical Fitness**:
6+
- **Cardiovascular Health**: Hiking gets your heart pumping, improving cardiovascular fitness. The varied terrain challenges your body and burns calories.
7+
- Strength and Endurance: Uphill climbs and uneven trails engage different muscle groups, enhancing strength and endurance.
8+
- Weight Management: Regular hiking can help you maintain a healthy weight.
9+
2. Mental Well-Being:
10+
- Stress Reduction: Nature has a calming effect. Hiking outdoors reduces stress, anxiety, and promotes relaxation.
11+
- Improved Mood: Fresh air, sunlight, and natural surroundings boost your mood and overall happiness.
12+
- Mindfulness: Disconnect from screens and immerse yourself in the present moment. Hiking encourages mindfulness.
13+
3. Connection with Nature:
14+
- Scenic Views: Explore breathtaking landscapes, from lush forests to mountain peaks. Nature's beauty rejuvenates the soul.
15+
- Wildlife Encounters: Spot birds, animals, and plant life. Connecting with nature fosters appreciation and wonder.
16+
4. Social Interaction:
17+
- Group Hikes: Join hiking clubs or go with friends. It's a great way to bond and share experiences.
18+
- Solitude: Solo hikes provide introspection and solitude, allowing you to recharge.
19+
5. Adventure and Exploration:
20+
- Discover Hidden Gems: Hiking takes you off the beaten path. Discover hidden waterfalls, caves, and scenic trails.
21+
- Sense of Accomplishment: Reaching a summit or completing a challenging trail gives a sense of achievement.
22+
Remember, hiking can be tailored to your fitness level—start with shorter, easier trails and gradually progress. Lace up those hiking boots and embark on an adventure!

0 commit comments

Comments
 (0)