Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwolfmsft committed Jul 18, 2024
1 parent e5ea1a2 commit 94f4104
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 24 deletions.
9 changes: 5 additions & 4 deletions docs/ai/quickstarts/get-started-openai.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic

:::zone-end

## Trying HikerAI sample
## Try the HikerAI sample

<!-- markdownlint-disable MD029 MD044 -->
:::zone target="docs" pivot="openai"
Expand Down Expand Up @@ -69,9 +69,9 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic

## Explore the code

The application uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to the OpenAI service.
The app uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to the OpenAI service.

The entire application is contained within the **Program.cs** file. The first several lines of code set configuration values and gets the OpenAI Key that was previously set using the `dotnet user-secrets` command.
The app code is contained within the **Program.cs** file. The first several lines of code set configuration values and gets the OpenAI Key that was previously set using the `dotnet user-secrets` command.

```csharp
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
Expand Down Expand Up @@ -145,7 +145,8 @@ chatHistory.AddUserMessage("Hi! Apparently you can help me find a hike that I wi
Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}");

// Get response
var response = await service.GetChatMessageContentAsync(chatHistory, new OpenAIPromptExecutionSettings() { MaxTokens = 400 });
var response = await service.GetChatMessageContentAsync(
chatHistory, new OpenAIPromptExecutionSettings() { MaxTokens = 400 });
```

Add the response from the mode to maintain the chat history.
Expand Down
14 changes: 10 additions & 4 deletions docs/ai/quickstarts/quickstart-ai-chat-with-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Get started with AI development, using the `gpt-35-turbo` model from a simple .N
[!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)]
:::zone-end

## Try "Chatting About My Previous Hikes" sample
## Try the "Chatting About My Previous Hikes" sample

<!-- markdownlint-disable MD029 MD044 -->
:::zone target="docs" pivot="openai"
Expand Down Expand Up @@ -128,18 +128,24 @@ To have the model generate a response based off the system prompt and the user r
chatHistory.AddUserMessage("Hi!");
Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}");

chatHistory.Add(await service.GetChatMessageContentAsync(chatHistory, new OpenAIPromptExecutionSettings() { MaxTokens = 400 }));
chatHistory.Add(
await service.GetChatMessageContentAsync(
chatHistory,
new OpenAIPromptExecutionSettings() { MaxTokens = 400 }));
Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}");
```

To maintain the chat history or context, make sure you add the response from the model to the `chatHistory`. It's time to make our user request about our data again using the `AddUserMessage` and `GetChatMessageContentAsync` function.

```csharp
// Continue the conversation with a question.
chatHistory.AddUserMessage("I would like to know the ratio of the hikes I've done in Canada compared to other countries.");
chatHistory.AddUserMessage(
"I would like to know the ratio of the hikesI've done in Canada compared to other countries.");
Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}");

chatHistory.Add(await service.GetChatMessageContentAsync(chatHistory, new OpenAIPromptExecutionSettings() { MaxTokens = 400 }));
chatHistory.Add(await service.GetChatMessageContentAsync(
chatHistory,
new OpenAIPromptExecutionSettings() { MaxTokens = 400 }));
Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}");
```

Expand Down
24 changes: 14 additions & 10 deletions docs/ai/quickstarts/quickstart-azure-openai-tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap

:::zone-end

## Try HikerAI Pro sample
## Try the the HikerAI Pro sample

<!-- markdownlint-disable MD029 MD044 -->
:::zone target="docs" pivot="openai"
Expand Down Expand Up @@ -124,7 +124,8 @@ The function's `ImportPluginFromFunctions` and `CreateFromMethod` are used to de
// For convenience and clarity of into the code, this standalone local method handles tool call responses. It will fake a call to a weather API and return the current weather for the specified location.
kernel.ImportPluginFromFunctions("WeatherPlugin",
[
KernelFunctionFactory.CreateFromMethod(([Description("The city, e.g. Montreal, Sidney")] string location, string unit = null) =>
KernelFunctionFactory.CreateFromMethod(
([Description("The city, e.g. Montreal, Sidney")] string location, string unit = null) =>
{
// Here you would call a weather API to get the weather for the location
return "Periods of rain or drizzle, 15 C";
Expand All @@ -136,16 +137,18 @@ Once the `kernel` client is created, provide more context to the model by adding

```csharp
ChatHistory chatHistory = new("""
You are a hiking enthusiast who helps people discover fun hikes in their area. You are upbeat and friendly.
A good weather is important for a good hike. Only make recommendations if the weather is good or if people insist.
You introduce yourself when first saying hello. When helping people out, you always ask them
for this information to inform the hiking recommendation you provide:
You are a hiking enthusiast who helps people discover fun hikes in their area.
You are upbeat and friendly. A good weather is important for a good hike.
Only make recommendations if the weather is good or if people insist.
You introduce yourself when first saying hello. When helping people out,
you always ask them for this information to inform the hiking recommendation you provide:
1. Where they are located
2. What hiking intensity they are looking for
You will then provide three suggestions for nearby hikes that vary in length after you get that information.
You will also share an interesting fact about the local nature on the hikes when making a recommendation.
You will then provide three suggestions for nearby hikes that vary in length
after you get that information. You will also share an interesting fact about the local
nature on the hikes when making a recommendation.
""");
```

Expand All @@ -156,8 +159,9 @@ To have the model generate a response based off the system prompt and the user r
```csharp
chatHistory.AddUserMessage("""
Is the weather is good today for a hike?
If yes, I live in the greater Montreal area and would like an easy hike. I don't mind driving a bit to get there.
I don't want the hike to be over 10 miles round trip. I'd consider a point-to-point hike.
If yes, I live in the greater Montreal area and would like an easy hike.
I don't mind driving a bit to get there. I don't want the hike to be over 10 miles round trip.
I'd consider a point-to-point hike.
I want the hike to be as isolated as possible. I don't want to see many people.
I would like it to be as bug free as possible.
""");
Expand Down
2 changes: 1 addition & 1 deletion docs/ai/quickstarts/quickstart-openai-generate-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap

:::zone-end

## Trying the Hiking Images sample
## Try the the Hiking Images sample

<!-- markdownlint-disable MD029 MD044 -->
:::zone target="docs" pivot="openai"
Expand Down
10 changes: 5 additions & 5 deletions docs/ai/quickstarts/quickstart-openai-summarize-text.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ zone_pivot_groups: openai-library
:::zone target="docs" pivot="openai"
<!-- markdownlint-enable MD044 -->

Get started with AI by creating a simple .NET 8 console chat application to summarize text. The application will run locally and use the OpenAI `gpt-3.5-turbo` model. Follow these steps to get access to OpenAI and learn how to use Semantic Kernel.
Get started with AI by creating a simple .NET 8 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.

[!INCLUDE [download-alert](includes/prerequisites-openai.md)]

Expand All @@ -26,13 +26,13 @@ Get started with AI by creating a simple .NET 8 console chat application to summ
:::zone target="docs" pivot="azure-openai"
<!-- markdownlint-enable MD044 -->

Get started with AI by creating a simple .NET 8 console chat application to summarize text. The application will run locally and connect to the OpenAI `gpt-35-turbo` model deployed into Azure OpenAI. Follow these steps to provision Azure OpenAI and learn how to use Semantic Kernel.
Get started with AI by creating a simple .NET 8 console chat application to summarize text. The app runs locally and connects to the OpenAI `gpt-35-turbo` model deployed into Azure OpenAI. Follow these steps to provision the Azure OpenAI service and learn how to use Semantic Kernel.

[!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)]

:::zone-end

## Trying Hiking Benefits Summary sample
## Try the Hiking Benefits Summary sample

<!-- markdownlint-disable MD029 MD044 -->
:::zone target="docs" pivot="openai"
Expand Down Expand Up @@ -91,7 +91,7 @@ Kernel kernel = Kernel.CreateBuilder()
:::zone target="docs" pivot="azure-openai"
The application uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to the Azure OpenAI service.

The entire application is contained within the **Program.cs** file. The first several lines of code loads up secrets and configuration values that were set in the `dotnet user-secrets` for you during the application provisioning.
The entire application is contained within the **Program.cs** file. The first several lines of code retrieve secrets and configuration values that were set in the `dotnet user-secrets` for you during the application provisioning.

```csharp
// == Retrieve the local secrets saved during the Azure deployment ==========
Expand Down Expand Up @@ -123,7 +123,7 @@ string prompt = $"""
Console.WriteLine($"user >>> {prompt}");
```

To have the model generate a response based off `prompt`, use the `InvokePromptAsync` function.
Use the `InvokePromptAsync` function to have the model generate a response based on the `prompt` value.

```csharp
// Submit the prompt and print out the response
Expand Down

0 comments on commit 94f4104

Please sign in to comment.