Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwolfmsft committed Jul 18, 2024
1 parent 3a0e642 commit e3eadfc
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
27 changes: 13 additions & 14 deletions docs/ai/quickstarts/get-started-openai.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Quickstart - Build an AI chat app with .NET
description: Create a simple chat app using Semantic Kernel with OpenAI or Azure OpenAI
description: Create a simple AI powered chat app using Semantic Kernel SDK for .NET and the OpenAI or Azure OpenAI SDKs
ms.date: 07/17/2024
ms.topic: quickstart
ms.custom: devx-track-dotnet, devx-track-dotnet-ai
Expand Down Expand Up @@ -39,7 +39,7 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic

1. From a terminal or command prompt, navigate to the `openai\02-HikerAI` directory.

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

:::zone-end

Expand Down Expand Up @@ -67,7 +67,7 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic

## Understanding the code

Our application uses the `Microsoft.SemanticKernel` package, which is available on [NuGet](https://www.nuget.org/packages/Microsoft.SemanticKernel), to send and receive requests to the OpenAI service.
The application 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.

Expand All @@ -84,7 +84,7 @@ The `OpenAIChatCompletionService` service facilitates the requests and responses
OpenAIChatCompletionService service = new(model, key);
```

Once the `OpenAIChatCompletionService` service is created, we provide more context to the model by adding a system prompt. This instructs the model how you'd like it to act during the conversation.
Provide more context to the model by adding a system prompt, which influences model behavior and the generated completions during the conversation.

:::zone-end

Expand All @@ -94,12 +94,12 @@ Once the `OpenAIChatCompletionService` service is created, we provide more conte

## Understanding the code

Our application uses the `Microsoft.SemanticKernel` package, which is available on [NuGet](https://www.nuget.org/packages/Microsoft.SemanticKernel), to send and receive requests to an Azure OpenAI service deployed in Azure.
The application uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to an Azure OpenAI service deployed in Azure.

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 retrieves the 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 ==========
// Retrieve the local secrets saved during the Azure deployment
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
string endpoint = config["AZURE_OPENAI_ENDPOINT"];
string deployment = config["AZURE_OPENAI_GPT_NAME"];
Expand All @@ -109,11 +109,12 @@ string key = config["AZURE_OPENAI_KEY"];
The `AzureOpenAIChatCompletionService` service facilitates the requests and responses.

```csharp
// == Create the Azure OpenAI Chat Completion Service ==========
// Create the Azure OpenAI Chat Completion Service
AzureOpenAIChatCompletionService service = new(deployment, endpoint, key);
```

Once the `AzureOpenAIChatCompletionService` service is created, we provide more context to the model by adding a system prompt. This instructs the model how you'd like it to act during the conversation.
Add a system prompt to provide more context to the model, which influences model behavior and the generated completions during the conversation.

:::zone-end

```csharp
Expand All @@ -131,9 +132,7 @@ ChatHistory chatHistory = new("""
""");
```

Then you can add a user message to the model by using the `AddUserMessage` function.

To have the model generate a response based off the system prompt and the user request, use the `GetChatMessageContentAsync` function.
Add a user message to the chat history using the `AddUserMessage` function. Use the `GetChatMessageContentAsync` function to instruct the model to generate a response based off the system prompt and the user request.

```csharp

Expand All @@ -147,7 +146,7 @@ Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}")
var response = await service.GetChatMessageContentAsync(chatHistory, new OpenAIPromptExecutionSettings() { MaxTokens = 400 });
```

To maintain the chat history, make sure you add the response from the model.
Add the response from the mode to maintain the chat history.

```csharp
// Add response to chat history
Expand All @@ -164,7 +163,7 @@ Customize the system prompt and user message to see how the model responds to he
<!-- markdownlint-enable MD044 -->
## Clean up resources

When you no longer need the sample application or resources, remove the corresponding deployment and all resources.
Remove the corresponding deployment and all resources when you no longer need the sample application or resources.

```azdeveloper
azd down
Expand Down
2 changes: 2 additions & 0 deletions docs/ai/quickstarts/includes/prerequisites-openai.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ ms.topic: include
- .NET 8.0 SDK - [Install the .NET 8.0 SDK](https://dotnet.microsoft.com/download/dotnet/8.0).
- An [API key from OpenAI](https://platform.openai.com/docs/quickstart/account-setup) so you can run this sample.
- On Windows, PowerShell `v7+` is required. To validate your version, run `pwsh` in a terminal. It should return the current version. If it returns an error, execute the following command: `dotnet tool update --global PowerShell`.

1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples)
6 changes: 3 additions & 3 deletions docs/ai/quickstarts/quickstart-ai-chat-with-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Get started with AI development, using the `gpt-35-turbo` model from a simple .N
<!-- markdownlint-disable MD044 -->
:::zone target="docs" pivot="openai"
<!-- markdownlint-enable MD044 -->
Our application uses the `Microsoft.SemanticKernel` package, which is available on [NuGet](https://www.nuget.org/packages/Microsoft.SemanticKernel), to send and receive requests to the OpenAI service.
The application uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to an 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.

Expand All @@ -80,11 +80,11 @@ The `OpenAIChatCompletionService` service facilitates the requests and responses
OpenAIChatCompletionService service = new(model, key);
```

Once the `OpenAIChatCompletionService` client is created, we read the content of the file `hikes.md` and use it to provide more context to the model by adding a system prompt. This instructs the model how you'd like it to act during the conversation.
Once the `OpenAIChatCompletionService` client is created, the app reads the content of the file `hikes.md` and uses it to provide more context to the model by adding a system prompt. This influences model behavior and the generated completions during the conversation.
:::zone-end

:::zone target="docs" pivot="azure-openai"
Our application uses the `Microsoft.SemanticKernel` package, which is available on [NuGet](https://www.nuget.org/packages/Microsoft.SemanticKernel), to send and receive requests to an Azure OpenAI service deployed in Azure.
The application uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to an Azure OpenAI service deployed in Azure.

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.

Expand Down
6 changes: 3 additions & 3 deletions docs/ai/quickstarts/quickstart-azure-openai-tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap
<!-- markdownlint-disable MD044 -->
:::zone target="docs" pivot="openai"

Our application uses the `Microsoft.SemanticKernel` package, which is available on [NuGet](https://www.nuget.org/packages/Microsoft.SemanticKernel), to send and receive requests to the OpenAI service.
The application 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.

Expand All @@ -91,7 +91,7 @@ Kernel kernel = b
:::zone target="docs" pivot="azure-openai"
<!-- markdownlint-enable MD044 -->

Our application uses the `Microsoft.SemanticKernel` package, which is available on [NuGet](https://www.nuget.org/packages/Microsoft.SemanticKernel), to send and receive requests to an Azure OpenAI service deployed in Azure.
The application 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 loads up secrets and configuration values that were set in the `dotnet user-secrets` for you during the application provisioning.

Expand Down Expand Up @@ -130,7 +130,7 @@ kernel.ImportPluginFromFunctions("WeatherPlugin",
]);
```

Once the `kernel` client is created, we provide more context to the model by adding a system prompt. This instructs the model how you'd like it to act during the conversation. Note how the weather is emphasized in the system prompt.
Once the `kernel` client is created, provide more context to the model by adding a system prompt. This instructs the model how you'd like it to act during the conversation. Note how the weather is emphasized in the system prompt.

```csharp
ChatHistory chatHistory = new("""
Expand Down
6 changes: 3 additions & 3 deletions docs/ai/quickstarts/quickstart-openai-generate-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap

<!-- markdownlint-disable MD044 -->
:::zone target="docs" pivot="openai"
Our application uses the `Microsoft.SemanticKernel` package, which is available on [NuGet](https://www.nuget.org/packages/Microsoft.SemanticKernel), to send and receive requests to the OpenAI service.
The application 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.

Expand All @@ -83,7 +83,7 @@ OpenAITextToImageService textToImageService = new(key, null);

:::zone target="docs" pivot="azure-openai"
<!-- markdownlint-enable MD044 -->
Our application uses the `Microsoft.SemanticKernel` package, which is available on [NuGet](https://www.nuget.org/packages/Microsoft.SemanticKernel), to send and receive requests to an Azure OpenAI service deployed in Azure.
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 load secrets and configuration values that were set in the `dotnet user-secrets` for you during the application provisioning.

Expand All @@ -103,7 +103,7 @@ AzureOpenAITextToImageService textToImageService = new(deployment, endpoint, key

:::zone-end

Once the `textToImageService` service is created, we we provide more context to the model by adding a system prompt. A good prompt to generate images requires a clear description: what is in the images, specific color to use, style (drawing, painting, realistic or cartoony). The model will use this prompt to generate the image. To have the model generate a response based off the user request, use the `GenerateImageAsync` function, and specify the size and quality.
Once the `textToImageService` service is created, provide more context to the model by adding a system prompt. A good prompt to generate images requires a clear description: what is in the images, specific color to use, style (drawing, painting, realistic or cartoony). The model will use this prompt to generate the image. To have the model generate a response based off the user request, use the `GenerateImageAsync` function, and specify the size and quality.

```csharp
// Generate the image
Expand Down
6 changes: 3 additions & 3 deletions docs/ai/quickstarts/quickstart-openai-summarize-text.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Get started with AI by creating a simple .NET 8 console chat application to summ
:::zone target="docs" pivot="openai"
<!-- markdownlint-enable MD044 -->

Our application uses the `Microsoft.SemanticKernel` package, which is available on [NuGet](https://www.nuget.org/packages/Microsoft.SemanticKernel), 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.

Expand All @@ -87,7 +87,7 @@ Kernel kernel = Kernel.CreateBuilder()
:::zone-end

:::zone target="docs" pivot="azure-openai"
Our application uses the `Microsoft.SemanticKernel` package, which is available on [NuGet](https://www.nuget.org/packages/Microsoft.SemanticKernel), to send and receive requests to an Azure OpenAI service deployed in Azure.
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.

Expand All @@ -110,7 +110,7 @@ Kernel kernel = Kernel.CreateBuilder()

:::zone-end

Once the `Kernel` is created, we read the contents of the file `benefits.md` and create a `prompt` to ask the the model to summarize that text.
Once the `Kernel` is created, read the contents of the file `benefits.md` and create a `prompt` to ask the the model to summarize that text.

```csharp
// Create and print out the prompt
Expand Down

0 comments on commit e3eadfc

Please sign in to comment.