Skip to content

Commit 9c36534

Browse files
committed
updates
1 parent 876db7b commit 9c36534

File tree

7 files changed

+134
-38
lines changed

7 files changed

+134
-38
lines changed

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

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -72,64 +72,35 @@ The **Program.cs** file contains all of the app code. The first several lines of
7272

7373
# [OpenAI](#tab/openai)
7474

75-
```csharp
76-
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
77-
string model = "gpt-3.5-turbo";
78-
string key = config["OpenAIKey"];
79-
```
75+
:::code language="csharp" source="./snippets/prompt-completion/extensions-ai/openai/program.cs" range="5-7":::
8076

8177
# [Azure OpenAI](#tab/azure-openai)
8278

83-
```csharp
84-
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
85-
string model = "gpt-3.5-turbo";
86-
string key = config["AzureOpenAIKey"];
87-
```
79+
:::code language="csharp" source="./snippets/prompt-completion/extensions-azure-openai/openai/program.cs" range="6-8":::
8880

8981
---
9082

9183
The following code obtains an `IChatClient` service configured to connect to the AI Model. 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.
9284

9385
# [OpenAI](#tab/openai)
9486

95-
```csharp
96-
// Create the IChatClient
97-
IChatClient client =
98-
new OpenAIClient(key)
99-
.AsChatClient(model);
100-
```
87+
:::code language="csharp" source="./snippets/prompt-completion/extensions-ai/openai/program.cs" range="10-11":::
10188

10289
# [Azure OpenAI](#tab/azure-openai)
10390

104-
```csharp
105-
// Create the IChatClient
106-
IChatClient client =
107-
new AzureOpenAIClient(new Uri(endpoint), new ApiKeyCredential(key))
108-
.AsChatClient(deployment);
109-
```
91+
:::code language="csharp" source="./snippets/prompt-completion/extensions-azure-openai/openai/program.cs" range="10-12":::
11092

11193
---
11294

113-
The following code creates a prompt on behalf to send to the AI model.
114-
115-
```csharp
116-
string prompt = $"""
117-
Please summarize the the following text in 20 words or less:
118-
{File.ReadAllText("benefits.md")}
119-
""";
95+
The `CompleteAsync` function sends the `prompt` to the model to generate a response.
12096

121-
Console.WriteLine($"user >>> {prompt}");
122-
```
97+
# [OpenAI](#tab/openai)
12398

124-
The `CompleteAsync` function sends the `prompt` to the model to generate a response.
99+
:::code language="csharp" source="./snippets/prompt-completion/extensions-ai/openai/program.cs" range="14-22":::
125100

126-
```csharp
127-
// Submit the prompt and print out the response
128-
ChatCompletion response =
129-
await client.CompleteAsync(prompt, new ChatOptions { MaxOutputTokens = 400 });
101+
# [Azure OpenAI](#tab/azure-openai)
130102

131-
Console.WriteLine($"assistant >>> {response}");
132-
```
103+
:::code language="csharp" source="./snippets/prompt-completion/extensions-azure-openai/openai/program.cs" range="15-23":::
133104

134105
Customize the text content of the file or the length of the summary to see the differences in the responses.
135106

@@ -178,6 +149,8 @@ Get started with AI by creating a simple .NET 8.0 console chat application to su
178149

179150
1. From a terminal or command prompt, navigate to the `azure-openai\01-HikeBenefitsSummary` directory.
180151

152+
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 user secrets for you.
153+
181154
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
182155

183156
```bash
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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.AI.OpenAI" Version="2.1.0-beta.1" />
12+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.0-preview.9.24525.1" />
13+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
14+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
15+
<PackageReference Include="Azure.Identity" Version="1.13.1" />
16+
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Microsoft.Extensions.Configuration;
2+
using Microsoft.Extensions.AI;
3+
using Azure.AI.OpenAI;
4+
using Azure.Identity;
5+
6+
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
7+
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
8+
string deployment = config["AZURE_OPENAI_GPT_NAME"];
9+
10+
IChatClient client =
11+
new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
12+
.AsChatClient(deployment);
13+
14+
// Create and print out the prompt
15+
string prompt = $"""
16+
Please summarize the the following text in 20 words or less:
17+
{File.ReadAllText("benefits.md")}
18+
""";
19+
Console.WriteLine($"user >>> {prompt}");
20+
21+
// Submit the prompt and print out the response
22+
ChatCompletion response = await client.CompleteAsync(prompt, new ChatOptions { MaxOutputTokens = 400 });
23+
Console.WriteLine($"assistant >>> {response}");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
1. **Physical Fitness**:
5+
- **Cardiovascular Health**: Hiking gets your heart pumping, improving cardiovascular fitness. The varied terrain challenges your body and burns calories.
6+
- Strength and Endurance: Uphill climbs and uneven trails engage different muscle groups, enhancing strength and endurance.
7+
- Weight Management: Regular hiking can help you maintain a healthy weight.
8+
2. Mental Well-Being:
9+
- Stress Reduction: Nature has a calming effect. Hiking outdoors reduces stress, anxiety, and promotes relaxation.
10+
- Improved Mood: Fresh air, sunlight, and natural surroundings boost your mood and overall happiness.
11+
- Mindfulness: Disconnect from screens and immerse yourself in the present moment. Hiking encourages mindfulness.
12+
3. Connection with Nature:
13+
- Scenic Views: Explore breathtaking landscapes, from lush forests to mountain peaks. Nature's beauty rejuvenates the soul.
14+
- Wildlife Encounters: Spot birds, animals, and plant life. Connecting with nature fosters appreciation and wonder.
15+
4. Social Interaction:
16+
- Group Hikes: Join hiking clubs or go with friends. It's a great way to bond and share experiences.
17+
- Solitude: Solo hikes provide introspection and solitude, allowing you to recharge.
18+
5. Adventure and Exploration:
19+
- Discover Hidden Gems: Hiking takes you off the beaten path. Discover hidden waterfalls, caves, and scenic trails.
20+
- Sense of Accomplishment: Reaching a summit or completing a challenging trail gives a sense of achievement.
21+
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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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.AI.OpenAI" Version="2.1.0-beta.1" />
12+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.0-preview.9.24525.1" />
13+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
14+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Microsoft.Extensions.AI;
2+
using Microsoft.Extensions.Configuration;
3+
using OpenAI;
4+
5+
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
6+
string model = config["ModelName"];
7+
string key = config["OpenAIKey"];
8+
9+
// Create the IChatClient
10+
IChatClient client =
11+
new OpenAIClient(key).AsChatClient(model);
12+
13+
// Create and print out the prompt
14+
string prompt = $"""
15+
Please summarize the the following text in 20 words or less:
16+
{File.ReadAllText("benefits.md")}
17+
""";
18+
Console.WriteLine($"user >>> {prompt}");
19+
20+
// Submit the prompt and print out the response
21+
ChatCompletion response = await client.CompleteAsync(prompt, new ChatOptions { MaxOutputTokens = 400 });
22+
Console.WriteLine($"assistant >>> {response}");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
1. **Physical Fitness**:
5+
- **Cardiovascular Health**: Hiking gets your heart pumping, improving cardiovascular fitness. The varied terrain challenges your body and burns calories.
6+
- Strength and Endurance: Uphill climbs and uneven trails engage different muscle groups, enhancing strength and endurance.
7+
- Weight Management: Regular hiking can help you maintain a healthy weight.
8+
2. Mental Well-Being:
9+
- Stress Reduction: Nature has a calming effect. Hiking outdoors reduces stress, anxiety, and promotes relaxation.
10+
- Improved Mood: Fresh air, sunlight, and natural surroundings boost your mood and overall happiness.
11+
- Mindfulness: Disconnect from screens and immerse yourself in the present moment. Hiking encourages mindfulness.
12+
3. Connection with Nature:
13+
- Scenic Views: Explore breathtaking landscapes, from lush forests to mountain peaks. Nature's beauty rejuvenates the soul.
14+
- Wildlife Encounters: Spot birds, animals, and plant life. Connecting with nature fosters appreciation and wonder.
15+
4. Social Interaction:
16+
- Group Hikes: Join hiking clubs or go with friends. It's a great way to bond and share experiences.
17+
- Solitude: Solo hikes provide introspection and solitude, allowing you to recharge.
18+
5. Adventure and Exploration:
19+
- Discover Hidden Gems: Hiking takes you off the beaten path. Discover hidden waterfalls, caves, and scenic trails.
20+
- Sense of Accomplishment: Reaching a summit or completing a challenging trail gives a sense of achievement.
21+
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)