From 11f2d46dfc2bffea79ed0549229664c212519b31 Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Mon, 1 Jul 2024 23:50:01 +0000 Subject: [PATCH 01/31] Updating first quickstart to reflect new sample separation of AzOAI and OpenAI. --- .../quickstarts/get-started-azure-openai.md | 158 +++++++----------- .../prerequisites-and-azure-deploy.md | 2 +- .../includes/prerequisites-openai.md | 12 ++ .../includes/set-openai-secrets.md | 15 ++ 4 files changed, 84 insertions(+), 103 deletions(-) create mode 100644 docs/ai/quickstarts/includes/prerequisites-openai.md create mode 100644 docs/ai/quickstarts/includes/set-openai-secrets.md diff --git a/docs/ai/quickstarts/get-started-azure-openai.md b/docs/ai/quickstarts/get-started-azure-openai.md index ce5cc451e6b59..6d7b929e83883 100644 --- a/docs/ai/quickstarts/get-started-azure-openai.md +++ b/docs/ai/quickstarts/get-started-azure-openai.md @@ -1,61 +1,93 @@ --- -title: Quickstart - Build an Azure AI chat app with .NET -description: Create a simple chat app using Semantic Kernel or the .NET Azure OpenAI SDK. -ms.date: 03/04/2024 +title: Quickstart - Build an AI chat app with .NET +description: Create a simple chat app using Semantic Kernel with OpenAI or Azure OpenAI +ms.date: 07/03/2024 ms.topic: quickstart ms.custom: devx-track-dotnet, devx-track-dotnet-ai author: fboucher ms.author: frbouche zone_pivot_groups: openai-library -# CustomerIntent: As a .NET developer new to Azure OpenAI, I want deploy and use sample code to interact to learn from the sample code. +# CustomerIntent: As a .NET developer new to AI, I want deploy and use sample code to interact to learn from the sample code. --- -# Build an Azure AI chat app with .NET +# Build an AI chat app with .NET -:::zone target="docs" pivot="semantic-kernel" +:::zone target="docs" pivot="open-ai" -Get started with Semantic Kernel by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `gpt-35-turbo` model deployed into an Azure OpenAI account. Follow these steps to provision Azure OpenAI and learn how to use Semantic Kernel. +Get started with Semantic Kernel by creating a simple .NET 8 console chat application. 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. :::zone-end -:::zone target="docs" pivot="azure-openai-sdk" +:::zone target="docs" pivot="azure-openai" -Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `gpt-35-turbo` model deployed into an Azure OpenAI account. Follow these steps to provision Azure OpenAI and learn how to use the .NET Azure OpenAI SDK. +Get started with Semantic Kernel by creating a simple .NET 8 console chat application. 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. :::zone-end -[!INCLUDE [download-alert](includes/prerequisites-and-azure-deploy.md)] - ## Trying HikerAI sample -:::zone target="docs" pivot="semantic-kernel" +:::zone target="docs" pivot="open-ai" -1. From a terminal or command prompt, navigate to the `semantic-kernel\02-HikerAI` directory. +1. From a terminal or command prompt, navigate to the `open-ai\02-HikerAI` directory. :::zone-end -:::zone target="docs" pivot="azure-openai-sdk" +:::zone target="docs" pivot="azure-openai" + +[!INCLUDE [download-alert](includes/prerequisites-openai.md)] -1. From a terminal or command prompt, navigate to the `azure-openai-sdk\02-HikerAI` directory. +1. From a terminal or command prompt, navigate to the `azure-openai\02-HikerAI` directory. + +[!INCLUDE [download-alert](includes/set-openai-secrets.md)] :::zone-end -2. It's now time to try the console application. Type in the following to run the app: +1. It's now time to try the console application. Type in the following to run the app: ```dotnetcli dotnet run ``` - If you get an error message the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. +:::zone target="docs" pivot="azure-openai" +If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. +::::zone-end + -:::zone target="docs" pivot="semantic-kernel" +:::zone target="docs" pivot="open-ai" + + +## 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 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. + +```csharp +var config = new ConfigurationBuilder().AddUserSecrets().Build(); +string model = "gpt-3.5-turbo"; +string key = config["OpenAIKey"]; +``` + +The `OpenAIChatCompletionService` service facilitates the requests and responses. + +```csharp +// Create the OpenAI Chat Completion Service +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. + +::::zone-end + + +:::zone target="docs" pivot="azure-open-ai" ## Understanding the code @@ -80,6 +112,7 @@ 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. +::::zone-end ```csharp // Start the conversation with context for the AI model @@ -124,90 +157,9 @@ Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}") Customize the system prompt and user message to see how the model responds to help you find a hike that you'll like. -:::zone-end - -:::zone target="docs" pivot="azure-openai-sdk" +:::zone target="docs" pivot="azure-open-ai" - -## Understanding the code - -Our application uses the `Azure.AI.OpenAI` client SDK, which is available on [NuGet](https://www.nuget.org/packages/Azure.AI.OpenAI), 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. - -```csharp -// == Retrieve the local secrets saved during the Azure deployment ========== -var config = new ConfigurationBuilder().AddUserSecrets().Build(); -string openAIEndpoint = config["AZURE_OPENAI_ENDPOINT"]; -string openAIDeploymentName = config["AZURE_OPENAI_GPT_NAME"]; -string openAiKey = config["AZURE_OPENAI_KEY"]; - -// == Creating the AIClient ========== -var endpoint = new Uri(openAIEndpoint); -var credentials = new AzureKeyCredential(openAiKey); -``` - -The `OpenAIClient` class facilitates the requests and responses. `ChatCompletionOptions` specifies parameters of how the model will respond. - -```csharp -var openAIClient = new OpenAIClient(endpoint, credentials); - -var completionOptions = new ChatCompletionsOptions -{ - MaxTokens = 400, - Temperature = 1f, - FrequencyPenalty = 0.0f, - PresencePenalty = 0.0f, - NucleusSamplingFactor = 0.95f, // Top P - DeploymentName = openAIDeploymentName -}; -``` - -Once the `OpenAIClient` 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. - -```csharp -var systemPrompt = -""" -You are a hiking enthusiast who helps people discover fun hikes in their area. You are upbeat and friendly. -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. -"""; - -completionOptions.Messages.Add(new ChatRequestSystemMessage(systemPrompt)); -``` - -Then you can add a user message to the model by using the `ChatRequestUserMessage` class. - -To have the model generate a response based off the system prompt and the user request, use the `GetChatCompletionsAsync` function. - -```csharp -string userGreeting = """ -Hi! -Apparently you can help me find a hike that I will like? -"""; - -completionOptions.Messages.Add(new ChatRequestUserMessage(userGreeting)); -Console.WriteLine($"\n\nUser >>> {userGreeting}"); - -ChatCompletions response = await openAIClient.GetChatCompletionsAsync(completionOptions); -ChatResponseMessage assistantResponse = response.Choices[0].Message; -Console.WriteLine($"\n\nAI >>> {assistantResponse.Content}"); -completionOptions.Messages.Add(new ChatRequestAssisstantMessage(assistantResponse.Content)); -``` - -To maintain the chat history or context, make sure you add the response from the model as a `ChatRequestAssistantMessage`. - -Customize the system prompt and user message to see how the model responds to help you find a hike that you'll like. - -:::zone-end - ## Clean up resources When you no longer need the sample application or resources, remove the corresponding deployment and all resources. @@ -216,7 +168,9 @@ When you no longer need the sample application or resources, remove the correspo azd down ``` +::::zone-end + ## Next steps -- [Quickstart - Get insight about your data from an .NET Azure AI chat app](quickstart-ai-chat-with-data.md) -- [Generate text and conversations with .NET and Azure OpenAI Completions](/training/modules/open-ai-dotnet-text-completions/) +- [Quickstart - Get insight about your data from .NET AI chat app](quickstart-ai-chat-with-data.md) +- [Generate text and conversations with .NET and OpenAI Completions](/training/modules/open-ai-dotnet-text-completions/) diff --git a/docs/ai/quickstarts/includes/prerequisites-and-azure-deploy.md b/docs/ai/quickstarts/includes/prerequisites-and-azure-deploy.md index 55f922839195a..acd149c755885 100644 --- a/docs/ai/quickstarts/includes/prerequisites-and-azure-deploy.md +++ b/docs/ai/quickstarts/includes/prerequisites-and-azure-deploy.md @@ -18,7 +18,7 @@ ms.topic: include Ensure that you follow the [Prerequisites](#prerequisites) to have access to Azure OpenAI Service as well as the Azure Developer CLI, and then follow the following guide to set started with the sample application. 1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) -1. From a terminal or command prompt, navigate to the _quickstarts_ directory. +1. From a terminal or command prompt, navigate to the _src\quickstarts\azure-openai_ directory (on macOS or Linux, replace the '\' character with a '/'. 1. This provisions the Azure OpenAI resources. It may take several minutes to create the Azure OpenAI service and deploy the model. ```azdeveloper diff --git a/docs/ai/quickstarts/includes/prerequisites-openai.md b/docs/ai/quickstarts/includes/prerequisites-openai.md new file mode 100644 index 0000000000000..a6b3aeebcf02f --- /dev/null +++ b/docs/ai/quickstarts/includes/prerequisites-openai.md @@ -0,0 +1,12 @@ +--- +author: jmatthiesen +ms.author: jomatthi +ms.date: 07/03/2024 +ms.topic: include +--- + +## Prerequisites + +- .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 returns the current version. If it returns an error, execute the following command: `dotnet tool update --global PowerShell`. diff --git a/docs/ai/quickstarts/includes/set-openai-secrets.md b/docs/ai/quickstarts/includes/set-openai-secrets.md new file mode 100644 index 0000000000000..9c24ff531b798 --- /dev/null +++ b/docs/ai/quickstarts/includes/set-openai-secrets.md @@ -0,0 +1,15 @@ +--- +author: jmatthiesen +ms.author: jomatthi +ms.date: 07/03/2024 +ms.topic: include +--- + +1. Run the following commands to configure your OpenAI API key to run the sample, using the key you previously got from OpenAI. + + ```bash + dotnet user-secrets init + dotnet user-secrets set OpenAIKey + ``` + + The sample now has the user-secrets configured and they can be tested. From 6dd034ab680af08fa54ae324548e3a1dd871c340 Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Mon, 1 Jul 2024 23:55:10 +0000 Subject: [PATCH 02/31] Fixed an issue caught by the linter --- docs/ai/quickstarts/includes/set-openai-secrets.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ai/quickstarts/includes/set-openai-secrets.md b/docs/ai/quickstarts/includes/set-openai-secrets.md index 9c24ff531b798..d2418b23b0f32 100644 --- a/docs/ai/quickstarts/includes/set-openai-secrets.md +++ b/docs/ai/quickstarts/includes/set-openai-secrets.md @@ -11,5 +11,5 @@ ms.topic: include dotnet user-secrets init dotnet user-secrets set OpenAIKey ``` - + The sample now has the user-secrets configured and they can be tested. From 1cdb32e03dba05f8e80f87815fc5a3ade94ced29 Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Tue, 2 Jul 2024 00:00:12 +0000 Subject: [PATCH 03/31] Fixed typos when working with pivots. --- docs/ai/quickstarts/get-started-azure-openai.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/ai/quickstarts/get-started-azure-openai.md b/docs/ai/quickstarts/get-started-azure-openai.md index 6d7b929e83883..7d68384f7df8c 100644 --- a/docs/ai/quickstarts/get-started-azure-openai.md +++ b/docs/ai/quickstarts/get-started-azure-openai.md @@ -55,7 +55,7 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone target="docs" pivot="azure-openai" If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. -::::zone-end +:::zone-end @@ -84,7 +84,7 @@ 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. -::::zone-end +:::zone-end :::zone target="docs" pivot="azure-open-ai" @@ -112,7 +112,7 @@ 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. -::::zone-end +:::zone-end ```csharp // Start the conversation with context for the AI model @@ -168,7 +168,7 @@ When you no longer need the sample application or resources, remove the correspo azd down ``` -::::zone-end +:::zone-end ## Next steps From 0fa11e00cc823ebed93dcfe1a66d73ddc0e24775 Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Tue, 2 Jul 2024 00:18:23 +0000 Subject: [PATCH 04/31] Added new pivots for quickstarts --- docs/zone-pivot-groups.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/zone-pivot-groups.yml b/docs/zone-pivot-groups.yml index ee5a06569354a..d3527c44e161b 100644 --- a/docs/zone-pivot-groups.yml +++ b/docs/zone-pivot-groups.yml @@ -146,3 +146,7 @@ groups: title: Semantic Kernel - id: azure-openai-sdk title: Azure OpenAI SDK + - id: open-ai + title: OpenAI + - id: azure-openai + title: Azure OpenAI From 1bf66e3c72c2816deb4c26be264bccec8456ded8 Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Tue, 2 Jul 2024 00:31:54 +0000 Subject: [PATCH 05/31] Moving to new pivots. --- docs/ai/quickstarts/get-started-azure-openai.md | 10 +++++----- docs/ai/quickstarts/quickstart-ai-chat-with-data.md | 12 ++++++------ docs/ai/quickstarts/quickstart-azure-openai-tool.md | 12 ++++++------ .../quickstarts/quickstart-openai-generate-images.md | 12 ++++++------ .../quickstarts/quickstart-openai-summarize-text.md | 12 ++++++------ docs/zone-pivot-groups.yml | 4 ---- 6 files changed, 29 insertions(+), 33 deletions(-) diff --git a/docs/ai/quickstarts/get-started-azure-openai.md b/docs/ai/quickstarts/get-started-azure-openai.md index 7d68384f7df8c..0848ad299a602 100644 --- a/docs/ai/quickstarts/get-started-azure-openai.md +++ b/docs/ai/quickstarts/get-started-azure-openai.md @@ -13,7 +13,7 @@ zone_pivot_groups: openai-library # Build an AI chat app with .NET -:::zone target="docs" pivot="open-ai" +:::zone target="docs" pivot="openai" Get started with Semantic Kernel by creating a simple .NET 8 console chat application. 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. @@ -31,7 +31,7 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic ## Trying HikerAI sample -:::zone target="docs" pivot="open-ai" +:::zone target="docs" pivot="openai" 1. From a terminal or command prompt, navigate to the `open-ai\02-HikerAI` directory. @@ -60,7 +60,7 @@ If you get an error message, the Azure OpenAI resources may not have finished de -:::zone target="docs" pivot="open-ai" +:::zone target="docs" pivot="openai" ## Understanding the code @@ -87,7 +87,7 @@ Once the `OpenAIChatCompletionService` service is created, we provide more conte :::zone-end -:::zone target="docs" pivot="azure-open-ai" +:::zone target="docs" pivot="azure-openai" ## Understanding the code @@ -158,7 +158,7 @@ Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}") Customize the system prompt and user message to see how the model responds to help you find a hike that you'll like. -:::zone target="docs" pivot="azure-open-ai" +:::zone target="docs" pivot="azure-openai" ## Clean up resources diff --git a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md index 3a38685e80b13..c77a937c4fa87 100644 --- a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md +++ b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md @@ -13,14 +13,14 @@ zone_pivot_groups: openai-library # Get insight about your data from an .NET Azure AI chat app -:::zone target="docs" pivot="semantic-kernel" +:::zone target="docs" pivot="open-ai" Get started with Semantic Kernel and the `gpt-35-turbo` model, from a simple .NET 8.0 console application. Use the AI model to get analytics and information about your previous hikes. It consists of a simple console application, running locally, that will read the file `hikes.md` and send request to an Azure OpenAI service deployed in your Azure subscription and provide the result in the console. Follow these steps to provision Azure OpenAI and learn how to use Semantic Kernel. :::zone-end -:::zone target="docs" pivot="azure-openai-sdk" +:::zone target="docs" pivot="azure-openai" Get started with the .NET Azure OpenAI with a `gpt-35-turbo` model, from a simple .NET 8.0 console application. Use the AI model to get analytics and information about your previous hikes. It consists of a simple console application, running locally, that will read the file `hikes.md` and send request to an Azure OpenAI service deployed in your Azure subscription and provide the result in the console. Follow these steps to provision Azure OpenAI and learn how to use the .NET Azure OpenAI SDK. @@ -32,13 +32,13 @@ Get started with the .NET Azure OpenAI with a `gpt-35-turbo` model, from a simpl ## Try "Chatting About My Previous Hikes" sample -:::zone target="docs" pivot="semantic-kernel" +:::zone target="docs" pivot="openai" 1. From a terminal or command prompt, navigate to the `semantic-kernel\03-ChattingAboutMyHikes` directory. :::zone-end -:::zone target="docs" pivot="azure-openai-sdk" +:::zone target="docs" pivot="azure-openai" 1. From a terminal or command prompt, navigate to the `azure-openai-sdk\03-ChattingAboutMyHikes` directory. @@ -54,7 +54,7 @@ Get started with the .NET Azure OpenAI with a `gpt-35-turbo` model, from a simpl -:::zone target="docs" pivot="semantic-kernel" +:::zone target="docs" pivot="openai" ## Explore the code @@ -120,7 +120,7 @@ Customize the system prompt and change the request, asking for different questio :::zone-end -:::zone target="docs" pivot="azure-openai-sdk" +:::zone target="docs" pivot="azure-openai" ## Explore the code diff --git a/docs/ai/quickstarts/quickstart-azure-openai-tool.md b/docs/ai/quickstarts/quickstart-azure-openai-tool.md index 6baf877ff8ca0..ae3b3ce472f86 100644 --- a/docs/ai/quickstarts/quickstart-azure-openai-tool.md +++ b/docs/ai/quickstarts/quickstart-azure-openai-tool.md @@ -13,7 +13,7 @@ zone_pivot_groups: openai-library # Extend Azure AI using Tools and execute a local Function with .NET -:::zone target="docs" pivot="semantic-kernel" +:::zone target="docs" pivot="openai" Get started with Semantic Kernel by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `gpt-35-turbo` model deployed into an Azure OpenAI account, however using Tool to extend the model capabilities it will call a local function. Follow these steps to provision Azure OpenAI and learn how to use Semantic Kernel. @@ -21,7 +21,7 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone-end -:::zone target="docs" pivot="azure-openai-sdk" +:::zone target="docs" pivot="azure-openai" Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `gpt-35-turbo` model deployed into an Azure OpenAI account, however using Tool to extend the model capabilities it will call a local function. Follow these steps to provision Azure OpenAI and learn how to use the .NET Azure OpenAI SDK. @@ -33,13 +33,13 @@ Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console c ## Try HikerAI Pro sample -:::zone target="docs" pivot="semantic-kernel" +:::zone target="docs" pivot="openai" 1. From a terminal or command prompt, navigate to the `semantic-kernel\04-HikerAIPro` directory. :::zone-end -:::zone target="docs" pivot="azure-openai-sdk" +:::zone target="docs" pivot="azure-openai" 1. From a terminal or command prompt, navigate to the `azure-openai-sdk\04-HikerAIPro` directory. @@ -55,7 +55,7 @@ Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console c -:::zone target="docs" pivot="semantic-kernel" +:::zone target="docs" pivot="openai" ## Understand the code @@ -138,7 +138,7 @@ Customize the system prompt and user message to see how the model responds to he :::zone-end -:::zone target="docs" pivot="azure-openai-sdk" +:::zone target="docs" pivot="azure-openai" ## Understand the code diff --git a/docs/ai/quickstarts/quickstart-openai-generate-images.md b/docs/ai/quickstarts/quickstart-openai-generate-images.md index 9beb85172068e..8626ae7a0dfad 100644 --- a/docs/ai/quickstarts/quickstart-openai-generate-images.md +++ b/docs/ai/quickstarts/quickstart-openai-generate-images.md @@ -13,7 +13,7 @@ zone_pivot_groups: openai-library # Generate images using Azure AI with .NET -:::zone target="docs" pivot="semantic-kernel" +:::zone target="docs" pivot="openai" Get started with Semantic Kernel by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `dell-e-3` model to generate postal card and invite your friends for a hike! Follow these steps to provision Azure OpenAI and learn how to use Semantic Kernel. @@ -21,7 +21,7 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone-end -:::zone target="docs" pivot="azure-openai-sdk" +:::zone target="docs" pivot="azure-openai" Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `dell-e-3` model to generate postal card and invite your friends for a hike! Follow these steps to provision Azure OpenAI and learn how to use the .NET Azure OpenAI SDK. @@ -33,13 +33,13 @@ Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console c ## Trying Generate Hiking Images sample -:::zone target="docs" pivot="semantic-kernel" +:::zone target="docs" pivot="openai" 1. From a terminal or command prompt, navigate to the `semantic-kernel\05-HikeImages` directory. :::zone-end -:::zone target="docs" pivot="azure-openai-sdk" +:::zone target="docs" pivot="azure-openai" 1. From a terminal or command prompt, navigate to the `azure-openai-sdk\05-HikeImages` directory. @@ -55,7 +55,7 @@ Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console c -:::zone target="docs" pivot="semantic-kernel" +:::zone target="docs" pivot="openai" ## Understanding the code @@ -99,7 +99,7 @@ Customize the prompt to personalize the images generated by the model. :::zone-end -:::zone target="docs" pivot="azure-openai-sdk" +:::zone target="docs" pivot="azure-openai" ## Understanding the code diff --git a/docs/ai/quickstarts/quickstart-openai-summarize-text.md b/docs/ai/quickstarts/quickstart-openai-summarize-text.md index c5ae5ed47117e..8df7a24cc72c0 100644 --- a/docs/ai/quickstarts/quickstart-openai-summarize-text.md +++ b/docs/ai/quickstarts/quickstart-openai-summarize-text.md @@ -13,7 +13,7 @@ zone_pivot_groups: openai-library # Summarize text using Azure AI chat app with .NET -:::zone target="docs" pivot="semantic-kernel" +:::zone target="docs" pivot="openai" Get started with Semantic Kernel by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `gpt-35-turbo` model deployed into an Azure OpenAI account. Follow these steps to provision Azure OpenAI and learn how to use Semantic Kernel. @@ -21,7 +21,7 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone-end -:::zone target="docs" pivot="azure-openai-sdk" +:::zone target="docs" pivot="azure-openai" Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `gpt-35-turbo` model deployed into an Azure OpenAI account. Follow these steps to provision Azure OpenAI and learn how to use the .NET Azure OpenAI SDK. @@ -33,13 +33,13 @@ Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console c ## Trying Hiking Benefits Summary sample -:::zone target="docs" pivot="semantic-kernel" +:::zone target="docs" pivot="openai" 1. From a terminal or command prompt, navigate to the `semantic-kernel\01-HikeBenefitsSummary` directory. :::zone-end -:::zone target="docs" pivot="azure-openai-sdk" +:::zone target="docs" pivot="azure-openai" 1. From a terminal or command prompt, navigate to the `azure-openai-sdk\01-HikeBenefitsSummary` directory. @@ -55,7 +55,7 @@ Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console c -:::zone target="docs" pivot="semantic-kernel" +:::zone target="docs" pivot="openai" ## Understanding the code @@ -111,7 +111,7 @@ Customize the text content of the file or the length of the summary to see the d :::zone-end -:::zone target="docs" pivot="azure-openai-sdk" +:::zone target="docs" pivot="azure-openai" ## Understanding the code diff --git a/docs/zone-pivot-groups.yml b/docs/zone-pivot-groups.yml index d3527c44e161b..98ebde17b9b3e 100644 --- a/docs/zone-pivot-groups.yml +++ b/docs/zone-pivot-groups.yml @@ -142,10 +142,6 @@ groups: title: OpenAI Library prompt: Choose a library for OpenAI pivots: - - id: semantic-kernel - title: Semantic Kernel - - id: azure-openai-sdk - title: Azure OpenAI SDK - id: open-ai title: OpenAI - id: azure-openai From 496d2f16b4a1772022dec75e3eceba0db0f7922e Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Tue, 2 Jul 2024 02:56:24 +0000 Subject: [PATCH 06/31] Fixed a typo in a pivot name --- docs/zone-pivot-groups.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/zone-pivot-groups.yml b/docs/zone-pivot-groups.yml index 98ebde17b9b3e..bcbd0179e3f4d 100644 --- a/docs/zone-pivot-groups.yml +++ b/docs/zone-pivot-groups.yml @@ -142,7 +142,7 @@ groups: title: OpenAI Library prompt: Choose a library for OpenAI pivots: - - id: open-ai + - id: openai title: OpenAI - id: azure-openai title: Azure OpenAI From 136c305294723738dcca1f69c6b27218e337df85 Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:08:55 +0000 Subject: [PATCH 07/31] Fixed a bad pivot reference --- docs/ai/quickstarts/quickstart-ai-chat-with-data.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md index c77a937c4fa87..5e5f682e6aca5 100644 --- a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md +++ b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md @@ -13,7 +13,7 @@ zone_pivot_groups: openai-library # Get insight about your data from an .NET Azure AI chat app -:::zone target="docs" pivot="open-ai" +:::zone target="docs" pivot="openai" Get started with Semantic Kernel and the `gpt-35-turbo` model, from a simple .NET 8.0 console application. Use the AI model to get analytics and information about your previous hikes. It consists of a simple console application, running locally, that will read the file `hikes.md` and send request to an Azure OpenAI service deployed in your Azure subscription and provide the result in the console. Follow these steps to provision Azure OpenAI and learn how to use Semantic Kernel. From 77b20631d62279007a344737bdacd77fe27d76ee Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Mon, 15 Jul 2024 19:45:36 +0000 Subject: [PATCH 08/31] File name fixes, fixing pre-reqs documentation. --- ...{get-started-azure-openai.md => get-started-openai.md} | 8 +++++--- ...-and-azure-deploy.md => prerequisites-azure-openai.md} | 0 docs/ai/quickstarts/quickstart-ai-chat-with-data.md | 2 +- docs/ai/quickstarts/quickstart-azure-openai-tool.md | 2 +- docs/ai/quickstarts/quickstart-openai-generate-images.md | 2 +- docs/ai/quickstarts/quickstart-openai-summarize-text.md | 2 +- docs/zone-pivot-groups.yml | 2 +- 7 files changed, 10 insertions(+), 8 deletions(-) rename docs/ai/quickstarts/{get-started-azure-openai.md => get-started-openai.md} (98%) rename docs/ai/quickstarts/includes/{prerequisites-and-azure-deploy.md => prerequisites-azure-openai.md} (100%) diff --git a/docs/ai/quickstarts/get-started-azure-openai.md b/docs/ai/quickstarts/get-started-openai.md similarity index 98% rename from docs/ai/quickstarts/get-started-azure-openai.md rename to docs/ai/quickstarts/get-started-openai.md index 0848ad299a602..c9afd7486392a 100644 --- a/docs/ai/quickstarts/get-started-azure-openai.md +++ b/docs/ai/quickstarts/get-started-openai.md @@ -33,18 +33,20 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone target="docs" pivot="openai" +[!INCLUDE [download-alert](includes/prerequisites-openai.md)] + 1. From a terminal or command prompt, navigate to the `open-ai\02-HikerAI` directory. +[!INCLUDE [download-alert](includes/set-openai-secrets.md)] + :::zone-end :::zone target="docs" pivot="azure-openai" -[!INCLUDE [download-alert](includes/prerequisites-openai.md)] +[!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)] 1. From a terminal or command prompt, navigate to the `azure-openai\02-HikerAI` directory. -[!INCLUDE [download-alert](includes/set-openai-secrets.md)] - :::zone-end 1. It's now time to try the console application. Type in the following to run the app: diff --git a/docs/ai/quickstarts/includes/prerequisites-and-azure-deploy.md b/docs/ai/quickstarts/includes/prerequisites-azure-openai.md similarity index 100% rename from docs/ai/quickstarts/includes/prerequisites-and-azure-deploy.md rename to docs/ai/quickstarts/includes/prerequisites-azure-openai.md diff --git a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md index 5e5f682e6aca5..94e2c3c9ba0b2 100644 --- a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md +++ b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md @@ -27,7 +27,7 @@ Get started with the .NET Azure OpenAI with a `gpt-35-turbo` model, from a simpl :::zone-end -[!INCLUDE [download-alert](includes/prerequisites-and-azure-deploy.md)] +[!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)] ## Try "Chatting About My Previous Hikes" sample diff --git a/docs/ai/quickstarts/quickstart-azure-openai-tool.md b/docs/ai/quickstarts/quickstart-azure-openai-tool.md index ae3b3ce472f86..11232d43b980a 100644 --- a/docs/ai/quickstarts/quickstart-azure-openai-tool.md +++ b/docs/ai/quickstarts/quickstart-azure-openai-tool.md @@ -28,7 +28,7 @@ Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console c :::zone-end -[!INCLUDE [download-alert](includes/prerequisites-and-azure-deploy.md)] +[!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)] ## Try HikerAI Pro sample diff --git a/docs/ai/quickstarts/quickstart-openai-generate-images.md b/docs/ai/quickstarts/quickstart-openai-generate-images.md index 8626ae7a0dfad..ea0e24ac0facf 100644 --- a/docs/ai/quickstarts/quickstart-openai-generate-images.md +++ b/docs/ai/quickstarts/quickstart-openai-generate-images.md @@ -28,7 +28,7 @@ Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console c :::zone-end -[!INCLUDE [download-alert](includes/prerequisites-and-azure-deploy.md)] +[!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)] ## Trying Generate Hiking Images sample diff --git a/docs/ai/quickstarts/quickstart-openai-summarize-text.md b/docs/ai/quickstarts/quickstart-openai-summarize-text.md index 8df7a24cc72c0..075e4722a4aa6 100644 --- a/docs/ai/quickstarts/quickstart-openai-summarize-text.md +++ b/docs/ai/quickstarts/quickstart-openai-summarize-text.md @@ -28,7 +28,7 @@ Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console c :::zone-end -[!INCLUDE [download-alert](includes/prerequisites-and-azure-deploy.md)] +[!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)] ## Trying Hiking Benefits Summary sample diff --git a/docs/zone-pivot-groups.yml b/docs/zone-pivot-groups.yml index bcbd0179e3f4d..1480c03def97d 100644 --- a/docs/zone-pivot-groups.yml +++ b/docs/zone-pivot-groups.yml @@ -140,7 +140,7 @@ groups: title: "Other" - id: openai-library title: OpenAI Library - prompt: Choose a library for OpenAI + prompt: Choose a host service for OpenAI pivots: - id: openai title: OpenAI From e08ef948d20e882b28ec14c42d56ae1af894d980 Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Mon, 15 Jul 2024 20:06:52 +0000 Subject: [PATCH 09/31] Renamed `get-started-azure-openai` to `get-started-openai` --- .openpublishing.redirection.ai.json | 7 ++++++- docs/ai/get-started/dotnet-ai-overview.md | 4 ++-- docs/ai/index.yml | 2 +- docs/ai/quickstarts/quickstart-openai-summarize-text.md | 2 +- docs/ai/toc.yml | 2 +- docs/azure/index.yml | 2 +- docs/index.yml | 2 +- 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.openpublishing.redirection.ai.json b/.openpublishing.redirection.ai.json index ef52176e5e7d0..8c73dbebb51da 100644 --- a/.openpublishing.redirection.ai.json +++ b/.openpublishing.redirection.ai.json @@ -1,3 +1,8 @@ { - "redirections": [] + "redirections": [ + { + "source_path_from_root": "/docs/ai/quickstarts/get-started-azure-openai.md", + "redirect_url": "/dotnet/ai/quickstarts/get-started-openai" + } + ] } \ No newline at end of file diff --git a/docs/ai/get-started/dotnet-ai-overview.md b/docs/ai/get-started/dotnet-ai-overview.md index 3a52c6f3c4194..7588586ed4370 100644 --- a/docs/ai/get-started/dotnet-ai-overview.md +++ b/docs/ai/get-started/dotnet-ai-overview.md @@ -36,7 +36,7 @@ We recommend the following sequence of tutorials and articles for an introductio |Scenario |Tutorial | |----------|----------| -| Create a chat application | [Build an Azure AI chat app with .NET](../quickstarts/get-started-azure-openai.md)| +| Create a chat application | [Build an Azure AI chat app with .NET](../quickstarts/get-started-openai.md)| | Summarize text | [Summarize text using Azure AI chat app with .NET](../quickstarts/quickstart-openai-summarize-text.md) | | Chat with your data | [Get insight about your data from an .NET Azure AI chat app](../quickstarts/quickstart-ai-chat-with-data.md) | | Call .NET functions with AI | [Extend Azure AI using tools and execute a local function with .NET](../quickstarts/quickstart-azure-openai-tool.md) | @@ -47,5 +47,5 @@ Browse the table of contents to learn more about the core concepts, starting wit ## Next steps -- [Quickstart: Build an Azure AI chat app with .NET](../quickstarts/get-started-azure-openai.md) +- [Quickstart: Build an Azure AI chat app with .NET](../quickstarts/get-started-openai.md) - [Video series: Machine Learning and AI with .NET](/shows/machine-learning-and-ai-with-dotnet-for-beginners) diff --git a/docs/ai/index.yml b/docs/ai/index.yml index 611f4f4c8a702..af00f5e0e6880 100644 --- a/docs/ai/index.yml +++ b/docs/ai/index.yml @@ -28,7 +28,7 @@ landingContent: - text: Learning resources and samples url: azure-ai-for-dotnet-developers.md - text: Build an Azure AI chat app with .NET - url: quickstarts/get-started-azure-openai.md + url: quickstarts/get-started-openai.md - text: Summarize text using an Azure OpenAI chat app url: quickstarts/quickstart-openai-summarize-text.md - text: Generate images using Azure AI with .NET diff --git a/docs/ai/quickstarts/quickstart-openai-summarize-text.md b/docs/ai/quickstarts/quickstart-openai-summarize-text.md index 075e4722a4aa6..1c0c61aedf6a4 100644 --- a/docs/ai/quickstarts/quickstart-openai-summarize-text.md +++ b/docs/ai/quickstarts/quickstart-openai-summarize-text.md @@ -184,5 +184,5 @@ azd down ## Next steps -- [Quickstart - Build an Azure AI chat app with .NET](get-started-azure-openai.md) +- [Quickstart - Build an Azure AI chat app with .NET](get-started-openai.md) - [Generate text and conversations with .NET and Azure OpenAI Completions](/training/modules/open-ai-dotnet-text-completions/) diff --git a/docs/ai/toc.yml b/docs/ai/toc.yml index 3716479974d6a..97d537f320ef9 100644 --- a/docs/ai/toc.yml +++ b/docs/ai/toc.yml @@ -14,7 +14,7 @@ items: - name: Summarize text href: quickstarts/quickstart-openai-summarize-text.md - name: Build a chat app - href: quickstarts/get-started-azure-openai.md + href: quickstarts/get-started-openai.md - name: Create an app to chat about your data href: quickstarts/quickstart-ai-chat-with-data.md - name: Execute a local .NET function diff --git a/docs/azure/index.yml b/docs/azure/index.yml index 5a9c4be3a605d..0c7c521048a1a 100644 --- a/docs/azure/index.yml +++ b/docs/azure/index.yml @@ -99,7 +99,7 @@ conceptualContent: url: ../ai/get-started/dotnet-ai-overview.md text: AI for .NET overview - itemType: quickstart - url: ../ai/quickstarts/get-started-azure-openai.md + url: ../ai/quickstarts/get-started-openai.md text: Build a chat app - itemType: quickstart text: Generate images diff --git a/docs/index.yml b/docs/index.yml index f6bfe477a8b0c..06c62445fbfef 100644 --- a/docs/index.yml +++ b/docs/index.yml @@ -323,7 +323,7 @@ additionalContent: links: - url: ai/index.yml text: AI for .NET developers - - url: ai/quickstarts/get-started-azure-openai.md + - url: ai/quickstarts/get-started-openai.md text: Build a chat app - url: ai/conceptual/prompt-engineering-dotnet.md text: Understand prompt engineering From 65e7d17cde012fa8832c55be0c2b492cec380567 Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Mon, 15 Jul 2024 20:16:51 +0000 Subject: [PATCH 10/31] Fixed the pre-reqs section. --- docs/ai/quickstarts/get-started-openai.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/ai/quickstarts/get-started-openai.md b/docs/ai/quickstarts/get-started-openai.md index c9afd7486392a..a968669d22d43 100644 --- a/docs/ai/quickstarts/get-started-openai.md +++ b/docs/ai/quickstarts/get-started-openai.md @@ -18,6 +18,8 @@ zone_pivot_groups: openai-library Get started with Semantic Kernel by creating a simple .NET 8 console chat application. 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. +[!INCLUDE [download-alert](includes/prerequisites-openai.md)] + :::zone-end @@ -26,6 +28,8 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic Get started with Semantic Kernel by creating a simple .NET 8 console chat application. 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. +[!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)] + :::zone-end ## Trying HikerAI sample @@ -33,8 +37,6 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone target="docs" pivot="openai" -[!INCLUDE [download-alert](includes/prerequisites-openai.md)] - 1. From a terminal or command prompt, navigate to the `open-ai\02-HikerAI` directory. [!INCLUDE [download-alert](includes/set-openai-secrets.md)] @@ -43,8 +45,6 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone target="docs" pivot="azure-openai" -[!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)] - 1. From a terminal or command prompt, navigate to the `azure-openai\02-HikerAI` directory. :::zone-end From a7da2d1c5f9137447966b944c6f8891864d4bd7d Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Mon, 15 Jul 2024 22:43:56 +0000 Subject: [PATCH 11/31] Working to fix bullet points --- docs/ai/quickstarts/get-started-openai.md | 4 ++-- .../includes/prerequisites-azure-openai.md | 2 +- docs/ai/quickstarts/includes/prerequisites-openai.md | 2 +- docs/ai/quickstarts/includes/set-openai-secrets.md | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/ai/quickstarts/get-started-openai.md b/docs/ai/quickstarts/get-started-openai.md index a968669d22d43..725b8f9560e60 100644 --- a/docs/ai/quickstarts/get-started-openai.md +++ b/docs/ai/quickstarts/get-started-openai.md @@ -1,7 +1,7 @@ --- title: Quickstart - Build an AI chat app with .NET description: Create a simple chat app using Semantic Kernel with OpenAI or Azure OpenAI -ms.date: 07/03/2024 +ms.date: 07/17/2024 ms.topic: quickstart ms.custom: devx-track-dotnet, devx-track-dotnet-ai author: fboucher @@ -49,7 +49,7 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone-end -1. It's now time to try the console application. Type in the following to run the app: +2. It's now time to try the console application. Type in the following to run the app: ```dotnetcli dotnet run diff --git a/docs/ai/quickstarts/includes/prerequisites-azure-openai.md b/docs/ai/quickstarts/includes/prerequisites-azure-openai.md index acd149c755885..af6306e654a49 100644 --- a/docs/ai/quickstarts/includes/prerequisites-azure-openai.md +++ b/docs/ai/quickstarts/includes/prerequisites-azure-openai.md @@ -11,7 +11,7 @@ ms.topic: include - An Azure subscription - [Create one for free](https://azure.microsoft.com/free) - Azure Developer CLI - [Install or update the Azure Developer CLI](/azure/developer/azure-developer-cli/install-azd) - Access to [Azure OpenAI service](/azure/ai-services/openai/overview#how-do-i-get-access-to-azure-openai). -- On Windows, PowerShell `v7+` is required. To validate your version, run `pwsh` in a terminal. It should returns the current version. If it returns an error, execute the following command: `dotnet tool update --global PowerShell`. +- 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`. ## Deploy the Azure resources diff --git a/docs/ai/quickstarts/includes/prerequisites-openai.md b/docs/ai/quickstarts/includes/prerequisites-openai.md index a6b3aeebcf02f..d3f9d5c0a1160 100644 --- a/docs/ai/quickstarts/includes/prerequisites-openai.md +++ b/docs/ai/quickstarts/includes/prerequisites-openai.md @@ -9,4 +9,4 @@ 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 returns the current version. If it returns an error, execute the following command: `dotnet tool update --global PowerShell`. +- 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`. diff --git a/docs/ai/quickstarts/includes/set-openai-secrets.md b/docs/ai/quickstarts/includes/set-openai-secrets.md index d2418b23b0f32..a0afb4a2b6618 100644 --- a/docs/ai/quickstarts/includes/set-openai-secrets.md +++ b/docs/ai/quickstarts/includes/set-openai-secrets.md @@ -5,11 +5,11 @@ ms.date: 07/03/2024 ms.topic: include --- -1. Run the following commands to configure your OpenAI API key to run the sample, using the key you previously got from OpenAI. +Run the following commands to configure your OpenAI API key to run the sample, using the key you previously got from OpenAI. - ```bash - dotnet user-secrets init - dotnet user-secrets set OpenAIKey - ``` +```bash +dotnet user-secrets init +dotnet user-secrets set OpenAIKey +``` - The sample now has the user-secrets configured and they can be tested. +The sample now has the user-secrets configured and they can be tested. From ce87975c810f8ab77a874bf7a44c65c0f352e373 Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:32:42 +0000 Subject: [PATCH 12/31] Updating the rest of the quickstarts to use the new SK based model. --- docs/ai/quickstarts/get-started-openai.md | 4 +- .../includes/prerequisites-azure-openai.md | 2 +- .../includes/set-openai-secrets.md | 13 +- .../quickstart-ai-chat-with-data.md | 143 ++++------- .../quickstart-azure-openai-tool.md | 222 ++++-------------- .../quickstart-openai-generate-images.md | 134 ++++------- .../quickstart-openai-summarize-text.md | 133 ++++------- 7 files changed, 186 insertions(+), 465 deletions(-) diff --git a/docs/ai/quickstarts/get-started-openai.md b/docs/ai/quickstarts/get-started-openai.md index 725b8f9560e60..6a242c09a54de 100644 --- a/docs/ai/quickstarts/get-started-openai.md +++ b/docs/ai/quickstarts/get-started-openai.md @@ -37,7 +37,7 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone target="docs" pivot="openai" -1. From a terminal or command prompt, navigate to the `open-ai\02-HikerAI` directory. +1. From a terminal or command prompt, navigate to the `openai\02-HikerAI` directory. [!INCLUDE [download-alert](includes/set-openai-secrets.md)] @@ -56,7 +56,7 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic ``` :::zone target="docs" pivot="azure-openai" -If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. + If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. :::zone-end diff --git a/docs/ai/quickstarts/includes/prerequisites-azure-openai.md b/docs/ai/quickstarts/includes/prerequisites-azure-openai.md index af6306e654a49..e2acaff7e9a2d 100644 --- a/docs/ai/quickstarts/includes/prerequisites-azure-openai.md +++ b/docs/ai/quickstarts/includes/prerequisites-azure-openai.md @@ -18,7 +18,7 @@ ms.topic: include Ensure that you follow the [Prerequisites](#prerequisites) to have access to Azure OpenAI Service as well as the Azure Developer CLI, and then follow the following guide to set started with the sample application. 1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) -1. From a terminal or command prompt, navigate to the _src\quickstarts\azure-openai_ directory (on macOS or Linux, replace the '\' character with a '/'. +1. From a terminal or command prompt, navigate to the _src\quickstarts\azure-openai_ directory (on macOS or Linux, replace the '\\' character with a '/'. 1. This provisions the Azure OpenAI resources. It may take several minutes to create the Azure OpenAI service and deploy the model. ```azdeveloper diff --git a/docs/ai/quickstarts/includes/set-openai-secrets.md b/docs/ai/quickstarts/includes/set-openai-secrets.md index a0afb4a2b6618..64c86758aae54 100644 --- a/docs/ai/quickstarts/includes/set-openai-secrets.md +++ b/docs/ai/quickstarts/includes/set-openai-secrets.md @@ -4,12 +4,9 @@ ms.author: jomatthi ms.date: 07/03/2024 ms.topic: include --- + Run the following commands to configure your OpenAI API key to run the sample, using the key you previously got from OpenAI. -Run the following commands to configure your OpenAI API key to run the sample, using the key you previously got from OpenAI. - -```bash -dotnet user-secrets init -dotnet user-secrets set OpenAIKey -``` - -The sample now has the user-secrets configured and they can be tested. + ```bash + dotnet user-secrets init + dotnet user-secrets set OpenAIKey + ``` diff --git a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md index 94e2c3c9ba0b2..cd7059731e964 100644 --- a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md +++ b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md @@ -1,46 +1,49 @@ --- -title: Quickstart - Get insight about your data from an .NET Azure AI chat app -description: Create a simple chat app using your data and Semantic Kernel or the .NET Azure OpenAI SDK. -ms.date: 03/04/2024 +title: Quickstart - Get insight about your data from a .NET AI chat app +description: Create a simple chat app using your data, Semantic Kernel, and OpenAI. +ms.date: 07/17/2024 ms.topic: quickstart ms.custom: devx-track-dotnet, devx-track-dotnet-ai author: fboucher ms.author: frbouche zone_pivot_groups: openai-library -# CustomerIntent: As a .NET developer new to Azure OpenAI, I want deploy and use sample code and data to interact to learn from the sample code. +# CustomerIntent: As a .NET developer new to AI development with OpenAI, I want deploy and use sample code and data to interact to learn from the sample code. --- -# Get insight about your data from an .NET Azure AI chat app +# Get insight about your data from a .NET AI chat app :::zone target="docs" pivot="openai" -Get started with Semantic Kernel and the `gpt-35-turbo` model, from a simple .NET 8.0 console application. Use the AI model to get analytics and information about your previous hikes. It consists of a simple console application, running locally, that will read the file `hikes.md` and send request to an Azure OpenAI service deployed in your Azure subscription and provide the result in the console. Follow these steps to provision Azure OpenAI and learn how to use Semantic Kernel. +Get started with AI development, using the `gpt-3.5-turbo` model from a simple .NET 8.0 console application. Use the AI model to get analytics and information about your previous hikes. It consists of a simple console application, running locally, that will read the file `hikes.md` and send request to the OpenAI service and provide the result in the console. Follow these steps to get access to OpenAI and learn how to use Semantic Kernel. + +[!INCLUDE [download-alert](includes/prerequisites-openai.md)] :::zone-end :::zone target="docs" pivot="azure-openai" -Get started with the .NET Azure OpenAI with a `gpt-35-turbo` model, from a simple .NET 8.0 console application. Use the AI model to get analytics and information about your previous hikes. It consists of a simple console application, running locally, that will read the file `hikes.md` and send request to an Azure OpenAI service deployed in your Azure subscription and provide the result in the console. Follow these steps to provision Azure OpenAI and learn how to use the .NET Azure OpenAI SDK. - -:::zone-end +Get started with AI development, using the `gpt-35-turbo` model from a simple .NET 8.0 console application. Use the AI model to get analytics and information about your previous hikes. It consists of a simple console application, running locally, that will read the file `hikes.md` and send request to an Azure OpenAI service deployed in your Azure subscription and provide the result in the console. Follow these steps to provision Azure OpenAI and learn how to use the .NET Azure OpenAI SDK. [!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)] +:::zone-end ## Try "Chatting About My Previous Hikes" sample :::zone target="docs" pivot="openai" -1. From a terminal or command prompt, navigate to the `semantic-kernel\03-ChattingAboutMyHikes` directory. +1. From a terminal or command prompt, navigate to the `openai\03-ChattingAboutMyHikes` directory. + + [!INCLUDE [download-alert](includes/set-openai-secrets.md)] :::zone-end :::zone target="docs" pivot="azure-openai" -1. From a terminal or command prompt, navigate to the `azure-openai-sdk\03-ChattingAboutMyHikes` directory. +1. From a terminal or command prompt, navigate to the `azure-openai\03-ChattingAboutMyHikes` directory. :::zone-end @@ -50,15 +53,37 @@ Get started with the .NET Azure OpenAI with a `gpt-35-turbo` model, from a simpl dotnet run ``` +:::zone target="docs" pivot="azure-openai" If you get an error message the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. +:::zone-end +## Explore the code + :::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. -## Explore the code +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. + +```csharp +var config = new ConfigurationBuilder().AddUserSecrets().Build(); +string model = "gpt-3.5-turbo"; +string key = config["OpenAIKey"]; +``` + +The `OpenAIChatCompletionService` service facilitates the requests and responses. + +```csharp +// Create the OpenAI Chat Completion Service +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. +:::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 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. @@ -79,6 +104,7 @@ AzureOpenAIChatCompletionService service = new(deployment, endpoint, key); ``` Once the `AzureOpenAIChatCompletionService` 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. +:::zone-end ```csharp // Provide context for the AI model @@ -117,96 +143,7 @@ Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}") Customize the system prompt and change the request, asking for different questions (ex: How many times did you hiked when it was raining? How many times did you hiked in 2021? etc.) to see how the model responds. -:::zone-end - - :::zone target="docs" pivot="azure-openai" - - -## Explore the code - -Our application uses the `Azure.AI.OpenAI` client SDK, which is available on [NuGet](https://www.nuget.org/packages/Azure.AI.OpenAI), 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. - -```csharp -// == Retrieve the local secrets saved during the Azure deployment ========== -var config = new ConfigurationBuilder() - .AddUserSecrets() - .Build(); - -string openAIEndpoint = config["AZURE_OPENAI_ENDPOINT"]; -string openAIDeploymentName = config["AZURE_OPENAI_GPT_NAME"]; -string openAiKey = config["AZURE_OPENAI_KEY"]; - -// == Creating the AIClient ========== -var endpoint = new Uri(openAIEndpoint); -var credentials = new AzureKeyCredential(openAiKey); -``` - -The `OpenAIClient` class facilitates the requests and responses. `ChatCompletionOptions` specifies parameters of how the model will respond. - -```csharp -var openAIClient = new OpenAIClient(endpoint, credentials); - -var completionOptions = new ChatCompletionsOptions -{ - MaxTokens = 400, - Temperature = 1f, - FrequencyPenalty = 0.0f, - PresencePenalty = 0.0f, - NucleusSamplingFactor = 0.95f, // Top P - DeploymentName = openAIDeploymentName -}; -``` - -Once the `OpenAIClient` 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. - -```csharp -var systemPrompt = -""" -You are upbeat and friendly. You introduce yourself when first saying hello. -Provide a short answer only based on the user hiking records below: - -""" + markdown; - -completionOptions.Messages.Add(new ChatRequestSystemMessage(systemPrompt)); -``` - -Then you can add a user message to the model by using the `ChatRequestUserMessage` class. - -To have the model generate a response based off the system prompt and the user request, use the `GetChatCompletionsAsync` function. - -```csharp -string userGreeting = """ -Hi! -"""; - -completionOptions.Messages.Add(new ChatRequestUserMessage(userGreeting)); -Console.WriteLine($"\n\nUser >>> {userGreeting}"); - -ChatCompletions response = await openAIClient.GetChatCompletionsAsync(completionOptions); -ChatResponseMessage assistantResponse = response.Choices[0].Message; -Console.WriteLine($"\n\nAI >>> {assistantResponse.Content}"); -completionOptions.Messages.Add(new ChatRequestAssisstantMessage(assistantResponse.Content)); -``` - -To maintain the chat history or context, make sure you add the response from the model as a `ChatRequestAssistantMessage`. It's time to make our user request about our data again using the `ChatRequestUserMessage` and `GetChatCompletionsAsync` function. - -```csharp -var hikeRequest = -""" -I would like to know the ration of hike I did in Canada compare to hikes done in other countries. -"""; - -Console.WriteLine($"\n\nUser >>> {hikeRequest}"); -completionOptions.Messages.Add(new ChatRequestUserMessage(hikeRequest)); -response = await openAIClient.GetChatCompletionsAsync(completionOptions); -``` - -Customize the system prompt and change the request, asking for different questions (ex: How many times did you hiked when it was raining? How many times did you hiked in 2021? etc.) to see how the model responds. - -:::zone-end ## Clean up resources @@ -216,7 +153,9 @@ When you no longer need the sample application or resources, remove the correspo azd down ``` +:::zone-end + ## Next steps -- [Quickstart - Generate images using Azure AI with .NET](quickstart-openai-generate-images.md) +- [Quickstart - Generate images using AI with .NET](quickstart-openai-generate-images.md) - [Generate text and conversations with .NET and Azure OpenAI Completions](/training/modules/open-ai-dotnet-text-completions/) diff --git a/docs/ai/quickstarts/quickstart-azure-openai-tool.md b/docs/ai/quickstarts/quickstart-azure-openai-tool.md index 11232d43b980a..22e10d030c4bb 100644 --- a/docs/ai/quickstarts/quickstart-azure-openai-tool.md +++ b/docs/ai/quickstarts/quickstart-azure-openai-tool.md @@ -1,22 +1,24 @@ --- -title: Quickstart - Extend Azure AI using Tools and execute a local Function with .NET -description: Create a simple chat app using Semantic Kernel or the .NET Azure OpenAI SDK and extend the model to execute a local function. -ms.date: 03/04/2024 +title: Quickstart - Extend OpenAI using Tools and execute a local Function with .NET +description: Create a simple chat app using OpenAI and extend the model to execute a local function. +ms.date: 07/14/2024 ms.topic: quickstart ms.custom: devx-track-dotnet, devx-track-dotnet-ai author: fboucher ms.author: frbouche zone_pivot_groups: openai-library -# CustomerIntent: As a .NET developer new to Azure OpenAI, I want deploy and use sample code to interact to learn from the sample code how to extend the model using Tools. +# CustomerIntent: As a .NET developer new to OpenAI, I want deploy and use sample code to interact to learn from the sample code how to extend the model using Tools. --- -# Extend Azure AI using Tools and execute a local Function with .NET +# Extend OpenAI using Tools and execute a local Function with .NET :::zone target="docs" pivot="openai" -Get started with Semantic Kernel by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `gpt-35-turbo` model deployed into an Azure OpenAI account, however using Tool to extend the model capabilities it will call a local function. 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. The application will run locally and use the OpenAI `gpt-3.5-turbo` model, using Tools to extend the model's capabilities by calling a local .NET method. Follow these steps to get access to OpenAI and learn how to use Semantic Kernel. + +[!INCLUDE [download-alert](includes/prerequisites-openai.md)] :::zone-end @@ -24,24 +26,26 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone target="docs" pivot="azure-openai" -Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `gpt-35-turbo` model deployed into an Azure OpenAI account, however using Tool to extend the model capabilities it will call a local function. Follow these steps to provision Azure OpenAI and learn how to use the .NET Azure OpenAI SDK. - -:::zone-end +Get started with AI by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `gpt-35-turbo` model deployed into an Azure OpenAI account. It uses Tools to extend the model's capabilities by calling a local .NET method. Follow these steps to provision Azure OpenAI and learn how to use Semantic Kernel. [!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)] +:::zone-end + ## Try HikerAI Pro sample :::zone target="docs" pivot="openai" -1. From a terminal or command prompt, navigate to the `semantic-kernel\04-HikerAIPro` directory. +1. From a terminal or command prompt, navigate to the `openai\04-HikerAIPro` directory. + + [!INCLUDE [download-alert](includes/set-openai-secrets.md)] :::zone-end :::zone target="docs" pivot="azure-openai" -1. From a terminal or command prompt, navigate to the `azure-openai-sdk\04-HikerAIPro` directory. +1. From a terminal or command prompt, navigate to the `azure-openai\04-HikerAIPro` directory. :::zone-end @@ -51,14 +55,41 @@ Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console c dotnet run ``` +:::zone target="docs" pivot="azure-openai" If you get an error message the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. +:::zone-end +## Understand the code + :::zone target="docs" pivot="openai" - -## Understand 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 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. + +```csharp +var config = new ConfigurationBuilder().AddUserSecrets().Build(); +string model = "gpt-3.5-turbo"; +string key = config["OpenAIKey"]; +``` + +The `Kernel` class facilitates the requests and responses with the help of `AddOpenAIChatCompletion` service. + +```csharp +// Create a Kernel containing the OpenAI Chat Completion Service +IKernelBuilder b = Kernel.CreateBuilder(); + +Kernel kernel = b + .AddOpenAIChatCompletion(model, key) + .Build(); +``` + +:::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. @@ -82,6 +113,8 @@ Kernel kernel = b .Build(); ``` +:::zone-end + The function's `ImportPluginFromFunctions` and `CreateFromMethod` are used to define the local function that will be called by the model. ```csharp @@ -135,166 +168,7 @@ Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}") Customize the system prompt and user message to see how the model responds to help you find a hike that you'll like. -:::zone-end - - :::zone target="docs" pivot="azure-openai" - - -## Understand the code - -Our application uses the `Azure.AI.OpenAI` client SDK, which is available on [NuGet](https://www.nuget.org/packages/Azure.AI.OpenAI), 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. - -```csharp -// == Retrieve the local secrets saved during the Azure deployment ========== -var config = new ConfigurationBuilder().AddUserSecrets().Build(); -string openAIEndpoint = config["AZURE_OPENAI_ENDPOINT"]; -string openAIDeploymentName = config["AZURE_OPENAI_GPT_NAME"]; -string openAiKey = config["AZURE_OPENAI_KEY"]; - -// == Creating the AIClient ========== -var endpoint = new Uri(openAIEndpoint); -var credentials = new AzureKeyCredential(openAiKey); -``` - -The `OpenAIClient` class facilitates the requests and responses. `ChatCompletionOptions` specifies parameters of how the model will respond. Note how the **Tools** property is used to add the definition. - -```csharp -var openAIClient = new OpenAIClient(endpoint, credentials); - -var completionOptions = new ChatCompletionsOptions -{ - MaxTokens = 400, - Temperature = 1f, - FrequencyPenalty = 0.0f, - PresencePenalty = 0.0f, - NucleusSamplingFactor = 0.95f, // Top P - DeploymentName = openAIDeploymentName, - Tools = { getWeather } -}; -``` - -The class `ChatCompletionsFunctionToolDefinition` is used to define the local function that will be called by the model. - -```csharp -var getWeather = new ChatCompletionsFunctionToolDefinition() -{ - Name = "get_current_weather", - Description = "Get the current weather in a given location", - Parameters = BinaryData.FromObjectAsJson( - new - { - Type = "object", - Properties = new - { - Location = new - { - Type = "string", - Description = "The city, e.g. Montreal, Sidney", - }, - Unit = new - { - Type = "string", - Enum = new[] { "celsius", "fahrenheit" }, - } - }, - Required = new[] { "location" }, - }, - new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }), -}; -``` - -Once the `OpenAIClient` 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. - -```csharp -var systemPrompt = -""" -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. -"""; - -completionOptions.Messages.Add(new ChatRequestSystemMessage(systemPrompt)); -``` - -Then you can add a user message to the model by using the `ChatRequestUserMessage` class. - -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. - -```csharp -ChatRequestToolMessage GetToolCallResponseMessage(ChatCompletionsToolCall toolCall) -{ - var functionToolCall = toolCall as ChatCompletionsFunctionToolCall; - if (functionToolCall?.Name == getWeather.Name) - { - string unvalidatedArguments = functionToolCall.Arguments; - var functionResultData = (object)null; - - // == Here call a weather API to get the weather for specified the location ========== - functionResultData = "Periods of rain or drizzle, 15 C"; - - return new ChatRequestToolMessage(functionResultData.ToString(), toolCall.Id); - } - else - { - throw new NotImplementedException(); - } -} -``` - -To have the model generate a response based off the system prompt and the user request, use the `GetChatCompletionsAsync` function. - -```csharp -string hikeRequest = """ -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. -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. -"""; - -Console.WriteLine($"\n\nUser >>> {hikeRequest}"); -completionOptions.Messages.Add(new ChatRequestUserMessage(hikeRequest)); - -response = await openAIClient.GetChatCompletionsAsync(completionOptions); -``` - -Now, the response need to be examined. If the response includes `ToolCalls`, the method declare previously handle it and continue the conversation. It's important to note that each messages `ChatRequestAssistantMessage` are added to the conversation history. This is important to maintain the context of the conversation. - -```csharp -ChatChoice responseChoice = response.Choices[0]; -if (responseChoice.FinishReason == CompletionsFinishReason.ToolCalls) -{ - // == Include the FunctionCall message in the conversation history ========== - completionOptions.Messages.Add(new ChatRequestAssistantMessage(responseChoice.Message)); - - // == Add a new tool message for each tool call that is resolved ========== - foreach (ChatCompletionsToolCall toolCall in responseChoice.Message.ToolCalls) - { - var ToolCallMsg = GetToolCallResponseMessage(toolCall); - completionOptions.Messages.Add(ToolCallMsg); - } - - // == Retrieve the answer from HikeAI Pro ========== - response = await openAIClient.GetChatCompletionsAsync(completionOptions); -} - -assistantResponse = response.Choices[0].Message; -Console.WriteLine($"\n\nAssistant >>> {assistantResponse.Content}"); -``` - -Customize the system prompt and user message to see how the model responds to help you find a hike that you'll like. - -:::zone-end ## Clean up resources @@ -304,7 +178,9 @@ When you no longer need the sample application or resources, remove the correspo azd down ``` +:::zone-end + ## Next steps -- [Quickstart - Get insight about your data from an .NET Azure AI chat app](quickstart-ai-chat-with-data.md) +- [Quickstart - Get insight about your data from a .NET AI chat app](quickstart-ai-chat-with-data.md) - [Generate text and conversations with .NET and Azure OpenAI Completions](/training/modules/open-ai-dotnet-text-completions/) diff --git a/docs/ai/quickstarts/quickstart-openai-generate-images.md b/docs/ai/quickstarts/quickstart-openai-generate-images.md index ea0e24ac0facf..866a0da49aee3 100644 --- a/docs/ai/quickstarts/quickstart-openai-generate-images.md +++ b/docs/ai/quickstarts/quickstart-openai-generate-images.md @@ -1,7 +1,7 @@ --- -title: Quickstart - Generate images using Azure AI with .NET -description: Create a simple app using Semantic Kernel or the .NET Azure OpenAI SDK to generate postal card images. -ms.date: 03/04/2024 +title: Quickstart - Generate images using AI with .NET +description: Create a simple app using OpenAI to generate postal card images. +ms.date: 07/17/2024 ms.topic: quickstart ms.custom: devx-track-dotnet, devx-track-dotnet-ai author: fboucher @@ -10,13 +10,15 @@ zone_pivot_groups: openai-library # CustomerIntent: As a .NET developer new to Azure OpenAI, I want deploy and use sample code to interact to learn how to generate images from the sample code. --- -# Generate images using Azure AI with .NET +# Generate images using AI with .NET :::zone target="docs" pivot="openai" -Get started with Semantic Kernel by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `dell-e-3` model to generate postal card and invite your friends for a hike! 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. The application will run locally and use the OpenAI `dall-e-3` model to generate postal card images so you can invite your friends for a hike! Follow these steps to get access to OpenAI and learn how to use Semantic Kernel. + +[!INCLUDE [download-alert](includes/prerequisites-openai.md)] :::zone-end @@ -24,24 +26,26 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone target="docs" pivot="azure-openai" -Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `dell-e-3` model to generate postal card and invite your friends for a hike! Follow these steps to provision Azure OpenAI and learn how to use the .NET Azure OpenAI SDK. - -:::zone-end +Get started with AI by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `dall-e-3` model to generate postal card images so you can invite your friends for a hike! Follow these steps to provision Azure OpenAI and learn how to use the .NET Azure OpenAI SDK. [!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)] -## Trying Generate Hiking Images sample +:::zone-end + +## Trying the Hiking Images sample :::zone target="docs" pivot="openai" -1. From a terminal or command prompt, navigate to the `semantic-kernel\05-HikeImages` directory. +1. From a terminal or command prompt, navigate to the `openai\05-HikeImages` directory. + + [!INCLUDE [download-alert](includes/set-openai-secrets.md)] :::zone-end :::zone target="docs" pivot="azure-openai" -1. From a terminal or command prompt, navigate to the `azure-openai-sdk\05-HikeImages` directory. +1. From a terminal or command prompt, navigate to the `azure-openai\05-HikeImages` directory. :::zone-end @@ -51,25 +55,40 @@ Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console c dotnet run ``` +:::zone target="docs" pivot="azure-openai" If you get an error message the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. +:::zone-end +## Understanding the code + :::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. -## Understanding the code +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. + +```csharp +var config = new ConfigurationBuilder().AddUserSecrets().Build(); +string key = config["OpenAIKey"]; +``` + +The `OpenAITextToImageService` service facilitates the requests and responses. + +```csharp +OpenAITextToImageService textToImageService = new(key, null); +``` + +:::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 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. ```csharp // == Retrieve the local secrets saved during the Azure deployment ========== -var config = new ConfigurationBuilder() - .AddUserSecrets() - .Build(); - var config = new ConfigurationBuilder().AddUserSecrets().Build(); string endpoint = config["AZURE_OPENAI_ENDPOINT"]; string deployment = config["AZURE_OPENAI_GPT_NAME"]; @@ -82,6 +101,8 @@ The `AzureOpenAITextToImageService` service facilitates the requests and respons AzureOpenAITextToImageService textToImageService = new(deployment, endpoint, key, null); ``` +:::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. ```csharp @@ -96,82 +117,7 @@ Console.WriteLine($"The generated image is ready at:\n{imageUrl}"); Customize the prompt to personalize the images generated by the model. -:::zone-end - - :::zone target="docs" pivot="azure-openai" - - -## Understanding the code - -Our application uses the `Azure.AI.OpenAI` client SDK, which is available on [NuGet](https://www.nuget.org/packages/Azure.AI.OpenAI), 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 load 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 ========== -var config = new ConfigurationBuilder() - .AddUserSecrets() - .Build(); - -string openAIEndpoint = config["AZURE_OPENAI_ENDPOINT"]; -string openAIDeploymentName = config["AZURE_OPENAI_GPT_NAME"]; -string openAiKey = config["AZURE_OPENAI_KEY"]; - -// == Creating the AIClient ========== -var endpoint = new Uri(openAIEndpoint); -var credentials = new AzureKeyCredential(openAiKey); -``` - -The `OpenAIClient` class facilitates the requests and responses. `ChatCompletionOptions` specifies parameters of how the model will respond. - -```csharp -var openAIClient = new OpenAIClient(endpoint, credentials); - -var completionOptions = new ChatCompletionsOptions -{ - MaxTokens = 400, - Temperature = 1f, - FrequencyPenalty = 0.0f, - PresencePenalty = 0.0f, - NucleusSamplingFactor = 0.95f, // Top P - DeploymentName = openAIDeploymentName -}; -``` - -Once the `OpenAIClient` client 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. - -```csharp -string imagePrompt = """ -A postal card with an happy hiker waving, there a beautiful mountain in the background. -There is a trail visible in the foreground. -The postal card has text in red saying: 'You are invited for a hike!' -"""; -``` - -To have the model generate a response based off the user request, use the `GetImageGenerationsAsync` function, and specify the size and quality. - -```csharp -Response response = await openAIClient.GetImageGenerationsAsync( - new ImageGenerationOptions() - { - DeploymentName = openAIDalleName, - Prompt = imagePrompt, - Size = ImageSize.Size1024x1024, - Quality = ImageGenerationQuality.Standard - }); - -ImageGenerationData generatedImage = response.Value.Data[0]; -if (!string.IsNullOrEmpty(generatedImage.RevisedPrompt)) -{ - Console.WriteLine($"\n\nInput prompt automatically revised to:\n {generatedImage.RevisedPrompt}"); -} -Console.WriteLine($"\n\nThe generated image is ready at:\n {generatedImage.Url.AbsoluteUri}"); -``` - -Customize the prompt to personalize the images generated by the model. - -:::zone-end ## Clean up resources @@ -181,7 +127,9 @@ When you no longer need the sample application or resources, remove the correspo azd down ``` +:::zone-end + ## Next steps -- [Quickstart - Summarize text using Azure AI chat app with .NET](quickstart-openai-summarize-text.md) +- [Quickstart - Summarize text using an AI chat app with .NET](quickstart-openai-summarize-text.md) - [Generate text and conversations with .NET and Azure OpenAI Completions](/training/modules/open-ai-dotnet-text-completions/) diff --git a/docs/ai/quickstarts/quickstart-openai-summarize-text.md b/docs/ai/quickstarts/quickstart-openai-summarize-text.md index 1c0c61aedf6a4..b141f1494bb4e 100644 --- a/docs/ai/quickstarts/quickstart-openai-summarize-text.md +++ b/docs/ai/quickstarts/quickstart-openai-summarize-text.md @@ -1,22 +1,24 @@ --- -title: Quickstart - Summarize text using Azure AI chat app with .NET -description: Create a simple chat app using Semantic Kernel or the .NET Azure OpenAI SDK to summarize a text. -ms.date: 03/04/2024 +title: Quickstart - Summarize text using an AI chat app with .NET +description: Create a simple chat app using OpenAI and the Semantic Kernel SDK to summarize a text. +ms.date: 07/17/2024 ms.topic: quickstart ms.custom: devx-track-dotnet, devx-track-dotnet-ai author: fboucher ms.author: frbouche zone_pivot_groups: openai-library -# CustomerIntent: As a .NET developer new to Azure OpenAI, I want deploy and use sample code to interact to learn from the sample code to summarize text. +# CustomerIntent: As a .NET developer new to OpenAI, I want deploy and use sample code to interact to learn from the sample code to summarize text. --- -# Summarize text using Azure AI chat app with .NET +# Summarize text using AI chat app with .NET :::zone target="docs" pivot="openai" -Get started with Semantic Kernel by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `gpt-35-turbo` model deployed into an Azure OpenAI account. 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 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. + +[!INCLUDE [download-alert](includes/prerequisites-openai.md)] :::zone-end @@ -24,24 +26,26 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone target="docs" pivot="azure-openai" -Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `gpt-35-turbo` model deployed into an Azure OpenAI account. Follow these steps to provision Azure OpenAI and learn how to use the .NET Azure OpenAI SDK. - -:::zone-end +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. [!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)] +:::zone-end + ## Trying Hiking Benefits Summary sample :::zone target="docs" pivot="openai" -1. From a terminal or command prompt, navigate to the `semantic-kernel\01-HikeBenefitsSummary` directory. +1. From a terminal or command prompt, navigate to the `openai\01-HikeBenefitsSummary` directory. + + [!INCLUDE [download-alert](includes/set-openai-secrets.md)] :::zone-end :::zone target="docs" pivot="azure-openai" -1. From a terminal or command prompt, navigate to the `azure-openai-sdk\01-HikeBenefitsSummary` directory. +1. From a terminal or command prompt, navigate to the `azure-openai\01-HikeBenefitsSummary` directory. :::zone-end @@ -51,42 +55,61 @@ Get started with the .NET Azure OpenAI SDK by creating a simple .NET 8 console c dotnet run ``` +:::zone target="docs" pivot="azure-openai" If you get an error message the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. - +:::zone-end + +## Understanding the code :::zone target="docs" pivot="openai" -## 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 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. + +```csharp +var config = new ConfigurationBuilder().AddUserSecrets().Build(); +string model = "gpt-3.5-turbo"; +string key = config["OpenAIKey"]; +``` + +The `Kernel` class facilitates the requests and responses with the help of `AddOpenAIChatCompletion` service. + +```csharp +// Create a Kernel containing the OpenAI Chat Completion Service +Kernel kernel = Kernel.CreateBuilder() + .AddOpenAIChatCompletion(model, key) + .Build(); +``` +:::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 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. ```csharp // == Retrieve the local secrets saved during the Azure deployment ========== -var config = new ConfigurationBuilder() - .AddUserSecrets() - .Build(); +var config = new ConfigurationBuilder().AddUserSecrets().Build(); string endpoint = config["AZURE_OPENAI_ENDPOINT"]; string deployment = config["AZURE_OPENAI_GPT_NAME"]; string key = config["AZURE_OPENAI_KEY"]; - -// Create a Kernel containing the Azure OpenAI Chat Completion Service -Kernel kernel = Kernel.CreateBuilder() - .AddAzureOpenAIChatCompletion(deployment, endpoint, key) - .Build(); ``` The `Kernel` class facilitates the requests and responses with the help of `AddAzureOpenAIChatCompletion` service. ```csharp +// Create a Kernel containing the Azure OpenAI Chat Completion Service Kernel kernel = Kernel.CreateBuilder() .AddAzureOpenAIChatCompletion(deployment, endpoint, key) .Build(); ``` +:::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. ```csharp @@ -108,71 +131,7 @@ Console.WriteLine($"assistant >>> {response}"); Customize the text content of the file or the length of the summary to see the differences in the responses. -:::zone-end - - :::zone target="docs" pivot="azure-openai" - - -## Understanding the code - -Our application uses the `Azure.AI.OpenAI` client SDK, which is available on [NuGet](https://www.nuget.org/packages/Azure.AI.OpenAI), 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. - -```csharp -// == Retrieve the local secrets saved during the Azure deployment ========== -var config = new ConfigurationBuilder() - .AddUserSecrets() - .Build(); - -string openAIEndpoint = config["AZURE_OPENAI_ENDPOINT"]; -string openAIDeploymentName = config["AZURE_OPENAI_GPT_NAME"]; -string openAiKey = config["AZURE_OPENAI_KEY"]; - -// == Creating the AIClient ========== -var endpoint = new Uri(openAIEndpoint); -var credentials = new AzureKeyCredential(openAiKey); -``` - -The `OpenAIClient` class facilitates the requests and responses. `ChatCompletionOptions` specifies parameters of how the model will respond. - -```csharp -var openAIClient = new OpenAIClient(endpoint, credentials); - -var completionOptions = new ChatCompletionsOptions -{ - MaxTokens = 400, - Temperature = 1f, - FrequencyPenalty = 0.0f, - PresencePenalty = 0.0f, - NucleusSamplingFactor = 0.95f, // Top P - DeploymentName = openAIDeploymentName -}; -``` - -Once the `OpenAIClient` client is created, we read the content of the file `benefits.md`. Then using the `ChatRequestUserMessage` class we can add to the model the request to summarize that text. - -```csharp -string userRequest = """ -Please summarize the the following text in 20 words or less: -""" + markdown; - -completionOptions.Messages.Add(new ChatRequestUserMessage(userRequest)); -Console.WriteLine($"\n\nUser >>> {userRequest}"); -``` - -To have the model generate a response based off the user request, use the `GetChatCompletionsAsync` function. - -```csharp -ChatCompletions response = await openAIClient.GetChatCompletionsAsync(completionOptions); -ChatResponseMessage assistantResponse = response.Choices[0].Message; -Console.WriteLine($"\n\nAssistant >>> {assistantResponse.Content}"); -``` - -Customize the text content of the file or the length of the summary to see the differences in the responses. - -:::zone-end ## Clean up resources @@ -182,7 +141,9 @@ When you no longer need the sample application or resources, remove the correspo azd down ``` +:::zone-end + ## Next steps -- [Quickstart - Build an Azure AI chat app with .NET](get-started-openai.md) +- [Quickstart - Build an AI chat app with .NET](get-started-openai.md) - [Generate text and conversations with .NET and Azure OpenAI Completions](/training/modules/open-ai-dotnet-text-completions/) From cbab44e416e10452de65f57aef3de5db77d0fcac Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:39:30 +0000 Subject: [PATCH 13/31] Fixing an indentation issue. --- docs/ai/quickstarts/includes/set-openai-secrets.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/ai/quickstarts/includes/set-openai-secrets.md b/docs/ai/quickstarts/includes/set-openai-secrets.md index 64c86758aae54..7927f79ca386d 100644 --- a/docs/ai/quickstarts/includes/set-openai-secrets.md +++ b/docs/ai/quickstarts/includes/set-openai-secrets.md @@ -4,9 +4,9 @@ ms.author: jomatthi ms.date: 07/03/2024 ms.topic: include --- - Run the following commands to configure your OpenAI API key to run the sample, using the key you previously got from OpenAI. +Run the following commands to configure your OpenAI API key to run the sample, using the key you previously got from OpenAI. - ```bash - dotnet user-secrets init - dotnet user-secrets set OpenAIKey - ``` +```bash +dotnet user-secrets init +dotnet user-secrets set OpenAIKey +``` From aab186a9ec5427a300219f71b0b54f734d66daea Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Thu, 18 Jul 2024 02:19:32 +0000 Subject: [PATCH 14/31] Trying to fix indentation issue --- docs/ai/quickstarts/get-started-openai.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/ai/quickstarts/get-started-openai.md b/docs/ai/quickstarts/get-started-openai.md index 6a242c09a54de..80dc40ea474fb 100644 --- a/docs/ai/quickstarts/get-started-openai.md +++ b/docs/ai/quickstarts/get-started-openai.md @@ -55,9 +55,9 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic dotnet run ``` -:::zone target="docs" pivot="azure-openai" + :::zone target="docs" pivot="azure-openai" If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. -:::zone-end + :::zone-end From 3a0e642e91976ddf7449b2b95a5641299c2354f4 Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Thu, 18 Jul 2024 03:07:17 +0000 Subject: [PATCH 15/31] Fixed indentation issues, for real --- docs/ai/quickstarts/quickstart-ai-chat-with-data.md | 4 ++-- docs/ai/quickstarts/quickstart-azure-openai-tool.md | 4 ++-- docs/ai/quickstarts/quickstart-openai-generate-images.md | 4 ++-- docs/ai/quickstarts/quickstart-openai-summarize-text.md | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md index cd7059731e964..484da6297f804 100644 --- a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md +++ b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md @@ -53,9 +53,9 @@ Get started with AI development, using the `gpt-35-turbo` model from a simple .N dotnet run ``` -:::zone target="docs" pivot="azure-openai" + :::zone target="docs" pivot="azure-openai" If you get an error message the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. -:::zone-end + :::zone-end ## Explore the code diff --git a/docs/ai/quickstarts/quickstart-azure-openai-tool.md b/docs/ai/quickstarts/quickstart-azure-openai-tool.md index 22e10d030c4bb..0675ccc49a0f4 100644 --- a/docs/ai/quickstarts/quickstart-azure-openai-tool.md +++ b/docs/ai/quickstarts/quickstart-azure-openai-tool.md @@ -55,9 +55,9 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap dotnet run ``` -:::zone target="docs" pivot="azure-openai" + :::zone target="docs" pivot="azure-openai" If you get an error message the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. -:::zone-end + :::zone-end ## Understand the code diff --git a/docs/ai/quickstarts/quickstart-openai-generate-images.md b/docs/ai/quickstarts/quickstart-openai-generate-images.md index 866a0da49aee3..9c0eeec959c0b 100644 --- a/docs/ai/quickstarts/quickstart-openai-generate-images.md +++ b/docs/ai/quickstarts/quickstart-openai-generate-images.md @@ -55,9 +55,9 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap dotnet run ``` -:::zone target="docs" pivot="azure-openai" + :::zone target="docs" pivot="azure-openai" If you get an error message the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. -:::zone-end + :::zone-end ## Understanding the code diff --git a/docs/ai/quickstarts/quickstart-openai-summarize-text.md b/docs/ai/quickstarts/quickstart-openai-summarize-text.md index b141f1494bb4e..81714919d5aea 100644 --- a/docs/ai/quickstarts/quickstart-openai-summarize-text.md +++ b/docs/ai/quickstarts/quickstart-openai-summarize-text.md @@ -55,9 +55,9 @@ Get started with AI by creating a simple .NET 8 console chat application to summ dotnet run ``` -:::zone target="docs" pivot="azure-openai" + :::zone target="docs" pivot="azure-openai" If you get an error message the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. -:::zone-end + :::zone-end ## Understanding the code From e3eadfc3954c7bf9bbf927dd443c871f1c6c9fb3 Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Thu, 18 Jul 2024 14:28:38 -0400 Subject: [PATCH 16/31] tweaks --- docs/ai/quickstarts/get-started-openai.md | 27 +++++++++---------- .../includes/prerequisites-openai.md | 2 ++ .../quickstart-ai-chat-with-data.md | 6 ++--- .../quickstart-azure-openai-tool.md | 6 ++--- .../quickstart-openai-generate-images.md | 6 ++--- .../quickstart-openai-summarize-text.md | 6 ++--- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/docs/ai/quickstarts/get-started-openai.md b/docs/ai/quickstarts/get-started-openai.md index 80dc40ea474fb..731e65ebd78f9 100644 --- a/docs/ai/quickstarts/get-started-openai.md +++ b/docs/ai/quickstarts/get-started-openai.md @@ -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 @@ -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 @@ -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. @@ -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 @@ -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().Build(); string endpoint = config["AZURE_OPENAI_ENDPOINT"]; string deployment = config["AZURE_OPENAI_GPT_NAME"]; @@ -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 @@ -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 @@ -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 @@ -164,7 +163,7 @@ Customize the system prompt and user message to see how the model responds to he ## 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 diff --git a/docs/ai/quickstarts/includes/prerequisites-openai.md b/docs/ai/quickstarts/includes/prerequisites-openai.md index d3f9d5c0a1160..f9c0caa02bf28 100644 --- a/docs/ai/quickstarts/includes/prerequisites-openai.md +++ b/docs/ai/quickstarts/includes/prerequisites-openai.md @@ -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) \ No newline at end of file diff --git a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md index 484da6297f804..df8bfc692987d 100644 --- a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md +++ b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md @@ -63,7 +63,7 @@ Get started with AI development, using the `gpt-35-turbo` model from a simple .N :::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 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. @@ -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. diff --git a/docs/ai/quickstarts/quickstart-azure-openai-tool.md b/docs/ai/quickstarts/quickstart-azure-openai-tool.md index 0675ccc49a0f4..c213a178adbcc 100644 --- a/docs/ai/quickstarts/quickstart-azure-openai-tool.md +++ b/docs/ai/quickstarts/quickstart-azure-openai-tool.md @@ -65,7 +65,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap :::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. @@ -91,7 +91,7 @@ Kernel kernel = b :::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 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. @@ -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(""" diff --git a/docs/ai/quickstarts/quickstart-openai-generate-images.md b/docs/ai/quickstarts/quickstart-openai-generate-images.md index 9c0eeec959c0b..ae1d9edd4b42c 100644 --- a/docs/ai/quickstarts/quickstart-openai-generate-images.md +++ b/docs/ai/quickstarts/quickstart-openai-generate-images.md @@ -64,7 +64,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap :::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. @@ -83,7 +83,7 @@ OpenAITextToImageService textToImageService = new(key, null); :::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 load secrets and configuration values that were set in the `dotnet user-secrets` for you during the application provisioning. @@ -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 diff --git a/docs/ai/quickstarts/quickstart-openai-summarize-text.md b/docs/ai/quickstarts/quickstart-openai-summarize-text.md index 81714919d5aea..265dd07becac4 100644 --- a/docs/ai/quickstarts/quickstart-openai-summarize-text.md +++ b/docs/ai/quickstarts/quickstart-openai-summarize-text.md @@ -65,7 +65,7 @@ Get started with AI by creating a simple .NET 8 console chat application to summ :::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 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. @@ -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. @@ -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 From e5ea1a26fd750a84925aadf3a19421735b9116b5 Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Thu, 18 Jul 2024 14:48:57 -0400 Subject: [PATCH 17/31] fixes --- docs/ai/quickstarts/get-started-openai.md | 6 ++++-- docs/ai/quickstarts/includes/prerequisites-openai.md | 4 +--- docs/ai/quickstarts/quickstart-ai-chat-with-data.md | 2 ++ docs/ai/quickstarts/quickstart-azure-openai-tool.md | 2 ++ docs/ai/quickstarts/quickstart-openai-generate-images.md | 4 +++- docs/ai/quickstarts/quickstart-openai-summarize-text.md | 4 +++- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/ai/quickstarts/get-started-openai.md b/docs/ai/quickstarts/get-started-openai.md index 731e65ebd78f9..e803f6789a8e6 100644 --- a/docs/ai/quickstarts/get-started-openai.md +++ b/docs/ai/quickstarts/get-started-openai.md @@ -37,6 +37,8 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone target="docs" pivot="openai" +1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) + 1. From a terminal or command prompt, navigate to the `openai\02-HikerAI` directory. [!INCLUDE [download-alert](includes/set-openai-secrets.md)] @@ -49,7 +51,7 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone-end -2. It's now time to try the console application. Type in the following to run the app: +2. Use the following to run the app: ```dotnetcli dotnet run @@ -65,7 +67,7 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone target="docs" pivot="openai" -## Understanding the code +## 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. diff --git a/docs/ai/quickstarts/includes/prerequisites-openai.md b/docs/ai/quickstarts/includes/prerequisites-openai.md index f9c0caa02bf28..082d17feb6523 100644 --- a/docs/ai/quickstarts/includes/prerequisites-openai.md +++ b/docs/ai/quickstarts/includes/prerequisites-openai.md @@ -9,6 +9,4 @@ 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) \ No newline at end of file +- 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`. \ No newline at end of file diff --git a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md index df8bfc692987d..5cbe97d6ab276 100644 --- a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md +++ b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md @@ -35,6 +35,8 @@ Get started with AI development, using the `gpt-35-turbo` model from a simple .N :::zone target="docs" pivot="openai" +1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) + 1. From a terminal or command prompt, navigate to the `openai\03-ChattingAboutMyHikes` directory. [!INCLUDE [download-alert](includes/set-openai-secrets.md)] diff --git a/docs/ai/quickstarts/quickstart-azure-openai-tool.md b/docs/ai/quickstarts/quickstart-azure-openai-tool.md index c213a178adbcc..1d539efebb7a7 100644 --- a/docs/ai/quickstarts/quickstart-azure-openai-tool.md +++ b/docs/ai/quickstarts/quickstart-azure-openai-tool.md @@ -37,6 +37,8 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap :::zone target="docs" pivot="openai" +1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) + 1. From a terminal or command prompt, navigate to the `openai\04-HikerAIPro` directory. [!INCLUDE [download-alert](includes/set-openai-secrets.md)] diff --git a/docs/ai/quickstarts/quickstart-openai-generate-images.md b/docs/ai/quickstarts/quickstart-openai-generate-images.md index ae1d9edd4b42c..036f0df636971 100644 --- a/docs/ai/quickstarts/quickstart-openai-generate-images.md +++ b/docs/ai/quickstarts/quickstart-openai-generate-images.md @@ -37,6 +37,8 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap :::zone target="docs" pivot="openai" +1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) + 1. From a terminal or command prompt, navigate to the `openai\05-HikeImages` directory. [!INCLUDE [download-alert](includes/set-openai-secrets.md)] @@ -60,7 +62,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap :::zone-end -## Understanding the code +## Explore the code :::zone target="docs" pivot="openai" diff --git a/docs/ai/quickstarts/quickstart-openai-summarize-text.md b/docs/ai/quickstarts/quickstart-openai-summarize-text.md index 265dd07becac4..2cddbc06f5921 100644 --- a/docs/ai/quickstarts/quickstart-openai-summarize-text.md +++ b/docs/ai/quickstarts/quickstart-openai-summarize-text.md @@ -37,6 +37,8 @@ Get started with AI by creating a simple .NET 8 console chat application to summ :::zone target="docs" pivot="openai" +1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) + 1. From a terminal or command prompt, navigate to the `openai\01-HikeBenefitsSummary` directory. [!INCLUDE [download-alert](includes/set-openai-secrets.md)] @@ -59,7 +61,7 @@ Get started with AI by creating a simple .NET 8 console chat application to summ If you get an error message the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. :::zone-end -## Understanding the code +## Explore the code :::zone target="docs" pivot="openai" From 94f4104f6a0b546edec3a53ef4208de547f23940 Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Thu, 18 Jul 2024 15:40:54 -0400 Subject: [PATCH 18/31] fixes --- docs/ai/quickstarts/get-started-openai.md | 9 +++---- .../quickstart-ai-chat-with-data.md | 14 +++++++---- .../quickstart-azure-openai-tool.md | 24 +++++++++++-------- .../quickstart-openai-generate-images.md | 2 +- .../quickstart-openai-summarize-text.md | 10 ++++---- 5 files changed, 35 insertions(+), 24 deletions(-) diff --git a/docs/ai/quickstarts/get-started-openai.md b/docs/ai/quickstarts/get-started-openai.md index e803f6789a8e6..4f5504825fc81 100644 --- a/docs/ai/quickstarts/get-started-openai.md +++ b/docs/ai/quickstarts/get-started-openai.md @@ -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 :::zone target="docs" pivot="openai" @@ -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().Build(); @@ -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. diff --git a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md index 5cbe97d6ab276..34a555ceb88eb 100644 --- a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md +++ b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md @@ -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 :::zone target="docs" pivot="openai" @@ -128,7 +128,10 @@ 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}"); ``` @@ -136,10 +139,13 @@ To maintain the chat history or context, make sure you add the response from the ```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}"); ``` diff --git a/docs/ai/quickstarts/quickstart-azure-openai-tool.md b/docs/ai/quickstarts/quickstart-azure-openai-tool.md index 1d539efebb7a7..9703bfc273f75 100644 --- a/docs/ai/quickstarts/quickstart-azure-openai-tool.md +++ b/docs/ai/quickstarts/quickstart-azure-openai-tool.md @@ -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 :::zone target="docs" pivot="openai" @@ -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"; @@ -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. """); ``` @@ -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. """); diff --git a/docs/ai/quickstarts/quickstart-openai-generate-images.md b/docs/ai/quickstarts/quickstart-openai-generate-images.md index 036f0df636971..33dd2928d854d 100644 --- a/docs/ai/quickstarts/quickstart-openai-generate-images.md +++ b/docs/ai/quickstarts/quickstart-openai-generate-images.md @@ -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 :::zone target="docs" pivot="openai" diff --git a/docs/ai/quickstarts/quickstart-openai-summarize-text.md b/docs/ai/quickstarts/quickstart-openai-summarize-text.md index 2cddbc06f5921..d326d9672e9fe 100644 --- a/docs/ai/quickstarts/quickstart-openai-summarize-text.md +++ b/docs/ai/quickstarts/quickstart-openai-summarize-text.md @@ -16,7 +16,7 @@ zone_pivot_groups: openai-library :::zone target="docs" pivot="openai" -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)] @@ -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" -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 :::zone target="docs" pivot="openai" @@ -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 ========== @@ -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 From 17be75edd050f97a876d5f6e87335b4b777e6b79 Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Thu, 18 Jul 2024 16:54:20 -0400 Subject: [PATCH 19/31] fixes --- docs/ai/quickstarts/get-started-openai.md | 55 ++++++++++++------- .../quickstarts/includes/clone-sample-repo.md | 12 ++++ docs/ai/quickstarts/includes/deploy-azd.md | 22 ++++++++ .../includes/prerequisites-azure-openai.md | 44 --------------- .../includes/set-openai-secrets.md | 3 +- docs/ai/quickstarts/includes/troubleshoot.md | 28 ++++++++++ .../quickstart-ai-chat-with-data.md | 42 ++++++++++---- .../quickstart-azure-openai-tool.md | 38 ++++++++++--- .../quickstart-openai-generate-images.md | 36 +++++++++--- .../quickstart-openai-summarize-text.md | 42 ++++++++++---- 10 files changed, 221 insertions(+), 101 deletions(-) create mode 100644 docs/ai/quickstarts/includes/clone-sample-repo.md create mode 100644 docs/ai/quickstarts/includes/deploy-azd.md create mode 100644 docs/ai/quickstarts/includes/troubleshoot.md diff --git a/docs/ai/quickstarts/get-started-openai.md b/docs/ai/quickstarts/get-started-openai.md index 4f5504825fc81..cb4400d03e62c 100644 --- a/docs/ai/quickstarts/get-started-openai.md +++ b/docs/ai/quickstarts/get-started-openai.md @@ -32,16 +32,35 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone-end +## Get the sample project + +[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)] + +:::zone target="docs" pivot="azure-openai" + +[!INCLUDE [deploy-azd](includes/deploy-azd.md)] + +:::zone-end + ## Try the HikerAI sample :::zone target="docs" pivot="openai" -1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) - 1. From a terminal or command prompt, navigate to the `openai\02-HikerAI` directory. - [!INCLUDE [download-alert](includes/set-openai-secrets.md)] +1. Run the following commands to configure your OpenAI API key as a secret for the sample app: + + ```bash + dotnet user-secrets init + dotnet user-secrets set OpenAIKey + ``` + +1. Use the `dotnet run` command to run the app: + + ```dotnetcli + dotnet run + ``` :::zone-end @@ -49,23 +68,16 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic 1. From a terminal or command prompt, navigate to the `azure-openai\02-HikerAI` directory. -:::zone-end - -2. Use the following to run the app: +2. Use the `dotnet run` command to run the app: ```dotnetcli dotnet run ``` - :::zone target="docs" pivot="azure-openai" - If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. - :::zone-end - - +> [!NOTE] +> If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. - -:::zone target="docs" pivot="openai" - +:::zone-end ## Explore the code @@ -122,15 +134,17 @@ Add a system prompt to provide more context to the model, which influences model ```csharp // Start the conversation with context for the AI model ChatHistory chatHistory = new(""" - You are a hiking enthusiast who helps people discover fun hikes in their area. You are upbeat and friendly. - 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. 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. """); ``` @@ -172,8 +186,11 @@ Remove the corresponding deployment and all resources when you no longer need th azd down ``` +[!INCLUDE [troubleshoot](includes/troubleshoot.md)] + :::zone-end + ## Next steps - [Quickstart - Get insight about your data from .NET AI chat app](quickstart-ai-chat-with-data.md) diff --git a/docs/ai/quickstarts/includes/clone-sample-repo.md b/docs/ai/quickstarts/includes/clone-sample-repo.md new file mode 100644 index 0000000000000..a644d271f13bc --- /dev/null +++ b/docs/ai/quickstarts/includes/clone-sample-repo.md @@ -0,0 +1,12 @@ +--- +author: jmatthiesen +ms.author: jomatthi +ms.date: 07/03/2024 +ms.topic: include +--- + +A GitHub repository is available that contains all the sample apps for all of the quickstarts. Clone the repository using the following command: + +```bash +git clone https://github.com/dotnet/ai-samples.git +``` diff --git a/docs/ai/quickstarts/includes/deploy-azd.md b/docs/ai/quickstarts/includes/deploy-azd.md new file mode 100644 index 0000000000000..8110274b84ef6 --- /dev/null +++ b/docs/ai/quickstarts/includes/deploy-azd.md @@ -0,0 +1,22 @@ +--- +author: jmatthiesen +ms.author: jomatthi +ms.date: 07/03/2024 +ms.topic: include +--- + +## Deploy the Azure resources + +Ensure that you follow the [Prerequisites](#prerequisites) to have access to Azure OpenAI Service as well as the Azure Developer CLI, and then follow the following guide to set started with the sample application. + +1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) +1. From a terminal or command prompt, navigate to the _src\quickstarts\azure-openai_ directory (on macOS or Linux, replace the '\\' character with a '/'. +1. This provisions the Azure OpenAI resources. It may take several minutes to create the Azure OpenAI service and deploy the model. + + ```azdeveloper + azd up + ``` + +> [!NOTE] +> If you encounter an error during the `azd up` deployment, visit the [troubleshooting](#troubleshoot) section. + diff --git a/docs/ai/quickstarts/includes/prerequisites-azure-openai.md b/docs/ai/quickstarts/includes/prerequisites-azure-openai.md index e2acaff7e9a2d..f6326525ff4b3 100644 --- a/docs/ai/quickstarts/includes/prerequisites-azure-openai.md +++ b/docs/ai/quickstarts/includes/prerequisites-azure-openai.md @@ -12,47 +12,3 @@ ms.topic: include - Azure Developer CLI - [Install or update the Azure Developer CLI](/azure/developer/azure-developer-cli/install-azd) - Access to [Azure OpenAI service](/azure/ai-services/openai/overview#how-do-i-get-access-to-azure-openai). - 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`. - -## Deploy the Azure resources - -Ensure that you follow the [Prerequisites](#prerequisites) to have access to Azure OpenAI Service as well as the Azure Developer CLI, and then follow the following guide to set started with the sample application. - -1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) -1. From a terminal or command prompt, navigate to the _src\quickstarts\azure-openai_ directory (on macOS or Linux, replace the '\\' character with a '/'. -1. This provisions the Azure OpenAI resources. It may take several minutes to create the Azure OpenAI service and deploy the model. - - ```azdeveloper - azd up - ``` - -> [!NOTE] -> If you already have an Azure OpenAI service available, you can skip the deployment and use that value in the _Program.cs_, preferably from an `IConfiguration`. - -## Troubleshoot - -On Windows, you might get the following error messages after running `azd up`: - -> *postprovision.ps1 is not digitally signed. The script will not execute on the system* - -The script **postprovision.ps1** is executed to set the .NET user secrets used in the application. To avoid this error, run the following PowerShell command: - -```powershell -Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -``` - -Then re-run the `azd up` command. - -Another possible error: - -> 'pwsh' is not recognized as an internal or external command, -> operable program or batch file. -> WARNING: 'postprovision' hook failed with exit code: '1', Path: '.\infra\post-script\postprovision.ps1'. : exit code: 1 -> Execution will continue since ContinueOnError has been set to true. - -The script **postprovision.ps1** is executed to set the .NET user secrets used in the application. To avoid this error, manually run the script using the following PowerShell command: - -```powershell -.\infra\post-script\postprovision.ps1 -``` - -The .NET AI apps now have the user-secrets configured and they can be tested. diff --git a/docs/ai/quickstarts/includes/set-openai-secrets.md b/docs/ai/quickstarts/includes/set-openai-secrets.md index 7927f79ca386d..9f4348ed8f339 100644 --- a/docs/ai/quickstarts/includes/set-openai-secrets.md +++ b/docs/ai/quickstarts/includes/set-openai-secrets.md @@ -4,7 +4,8 @@ ms.author: jomatthi ms.date: 07/03/2024 ms.topic: include --- -Run the following commands to configure your OpenAI API key to run the sample, using the key you previously got from OpenAI. + +Run the following commands to configure your OpenAI API key as a secret for the sample app: ```bash dotnet user-secrets init diff --git a/docs/ai/quickstarts/includes/troubleshoot.md b/docs/ai/quickstarts/includes/troubleshoot.md new file mode 100644 index 0000000000000..9ddef936a04c1 --- /dev/null +++ b/docs/ai/quickstarts/includes/troubleshoot.md @@ -0,0 +1,28 @@ +## Troubleshoot + +On Windows, you might get the following error messages after running `azd up`: + +> *postprovision.ps1 is not digitally signed. The script will not execute on the system* + +The script **postprovision.ps1** is executed to set the .NET user secrets used in the application. To avoid this error, run the following PowerShell command: + +```powershell +Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass +``` + +Then re-run the `azd up` command. + +Another possible error: + +> 'pwsh' is not recognized as an internal or external command, +> operable program or batch file. +> WARNING: 'postprovision' hook failed with exit code: '1', Path: '.\infra\post-script\postprovision.ps1'. : exit code: 1 +> Execution will continue since ContinueOnError has been set to true. + +The script **postprovision.ps1** is executed to set the .NET user secrets used in the application. To avoid this error, manually run the script using the following PowerShell command: + +```powershell +.\infra\post-script\postprovision.ps1 +``` + +The .NET AI apps now have the user-secrets configured and they can be tested. \ No newline at end of file diff --git a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md index 34a555ceb88eb..cb53e005be3d3 100644 --- a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md +++ b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md @@ -30,34 +30,53 @@ 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 +## Get the sample project + +[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)] + +:::zone target="docs" pivot="azure-openai" + +[!INCLUDE [deploy-azd](includes/deploy-azd.md)] + +:::zone-end + ## Try the "Chatting About My Previous Hikes" sample :::zone target="docs" pivot="openai" -1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) - 1. From a terminal or command prompt, navigate to the `openai\03-ChattingAboutMyHikes` directory. - [!INCLUDE [download-alert](includes/set-openai-secrets.md)] +1. Run the following commands to configure your OpenAI API key as a secret for the sample app: -:::zone-end + ```bash + dotnet user-secrets init + dotnet user-secrets set OpenAIKey + ``` -:::zone target="docs" pivot="azure-openai" +1. Use the `dotnet run` command to run the app: -1. From a terminal or command prompt, navigate to the `azure-openai\03-ChattingAboutMyHikes` directory. + ```dotnetcli + dotnet run + ``` :::zone-end -2. It's now time to try the console application. Type in the following to run the app: +:::zone target="docs" pivot="azure-openai" + +1. From a terminal or command prompt, navigate to the `azure-openai\02-HikerAI` directory. + +2. Use the `dotnet run` command to run the app: ```dotnetcli dotnet run ``` - :::zone target="docs" pivot="azure-openai" - If you get an error message the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. - :::zone-end +> [!NOTE] +> If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. + +:::zone-end + ## Explore the code @@ -161,8 +180,11 @@ When you no longer need the sample application or resources, remove the correspo azd down ``` +[!INCLUDE [troubleshoot](includes/troubleshoot.md)] + :::zone-end + ## Next steps - [Quickstart - Generate images using AI with .NET](quickstart-openai-generate-images.md) diff --git a/docs/ai/quickstarts/quickstart-azure-openai-tool.md b/docs/ai/quickstarts/quickstart-azure-openai-tool.md index 9703bfc273f75..4a3e25e7b30a4 100644 --- a/docs/ai/quickstarts/quickstart-azure-openai-tool.md +++ b/docs/ai/quickstarts/quickstart-azure-openai-tool.md @@ -32,16 +32,35 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap :::zone-end +## Get the sample project + +[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)] + +:::zone target="docs" pivot="azure-openai" + +[!INCLUDE [deploy-azd](includes/deploy-azd.md)] + +:::zone-end + ## Try the the HikerAI Pro sample :::zone target="docs" pivot="openai" -1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) +1. From a terminal or command prompt, navigate to the `azure-openai\04-HikerAIPro` directory. -1. From a terminal or command prompt, navigate to the `openai\04-HikerAIPro` directory. +1. Run the following commands to configure your OpenAI API key as a secret for the sample app: + + ```bash + dotnet user-secrets init + dotnet user-secrets set OpenAIKey + ``` - [!INCLUDE [download-alert](includes/set-openai-secrets.md)] +1. Use the `dotnet run` command to run the app: + + ```dotnetcli + dotnet run + ``` :::zone-end @@ -49,17 +68,16 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap 1. From a terminal or command prompt, navigate to the `azure-openai\04-HikerAIPro` directory. -:::zone-end - -2. It's now time to try the console application. Type in the following to run the app: +2. Use the `dotnet run` command to run the app: ```dotnetcli dotnet run ``` - :::zone target="docs" pivot="azure-openai" - If you get an error message the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. - :::zone-end +> [!NOTE] +> If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. + +:::zone-end ## Understand the code @@ -184,6 +202,8 @@ When you no longer need the sample application or resources, remove the correspo azd down ``` +[!INCLUDE [troubleshoot](includes/troubleshoot.md)] + :::zone-end ## Next steps diff --git a/docs/ai/quickstarts/quickstart-openai-generate-images.md b/docs/ai/quickstarts/quickstart-openai-generate-images.md index 33dd2928d854d..43f5d9355e0fd 100644 --- a/docs/ai/quickstarts/quickstart-openai-generate-images.md +++ b/docs/ai/quickstarts/quickstart-openai-generate-images.md @@ -32,6 +32,16 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap :::zone-end +## Get the sample project + +[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)] + +:::zone target="docs" pivot="azure-openai" + +[!INCLUDE [deploy-azd](includes/deploy-azd.md)] + +:::zone-end + ## Try the the Hiking Images sample @@ -39,9 +49,18 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap 1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) -1. From a terminal or command prompt, navigate to the `openai\05-HikeImages` directory. +1. Run the following commands to configure your OpenAI API key as a secret for the sample app: + + ```bash + dotnet user-secrets init + dotnet user-secrets set OpenAIKey + ``` + +1. Use the `dotnet run` command to run the app: - [!INCLUDE [download-alert](includes/set-openai-secrets.md)] + ```dotnetcli + dotnet run + ``` :::zone-end @@ -49,17 +68,16 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap 1. From a terminal or command prompt, navigate to the `azure-openai\05-HikeImages` directory. -:::zone-end - -2. It's now time to try the console application. Type in the following to run the app: +2. Use the `dotnet run` command to run the app: ```dotnetcli dotnet run ``` - :::zone target="docs" pivot="azure-openai" - If you get an error message the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. - :::zone-end +> [!NOTE] +> If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. + +:::zone-end ## Explore the code @@ -129,6 +147,8 @@ When you no longer need the sample application or resources, remove the correspo azd down ``` +[!INCLUDE [troubleshoot](includes/troubleshoot.md)] + :::zone-end ## Next steps diff --git a/docs/ai/quickstarts/quickstart-openai-summarize-text.md b/docs/ai/quickstarts/quickstart-openai-summarize-text.md index d326d9672e9fe..70b8bff42cf6d 100644 --- a/docs/ai/quickstarts/quickstart-openai-summarize-text.md +++ b/docs/ai/quickstarts/quickstart-openai-summarize-text.md @@ -32,16 +32,35 @@ Get started with AI by creating a simple .NET 8 console chat application to summ :::zone-end +## Get the sample project + +[!INCLUDE [clone-sample-repo](includes/clone-sample-repo.md)] + +:::zone target="docs" pivot="azure-openai" + +[!INCLUDE [deploy-azd](includes/deploy-azd.md)] + +:::zone-end + ## Try the Hiking Benefits Summary sample :::zone target="docs" pivot="openai" -1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) - 1. From a terminal or command prompt, navigate to the `openai\01-HikeBenefitsSummary` directory. - [!INCLUDE [download-alert](includes/set-openai-secrets.md)] +1. Run the following commands to configure your OpenAI API key as a secret for the sample app: + + ```bash + dotnet user-secrets init + dotnet user-secrets set OpenAIKey + ``` + +1. Use the `dotnet run` command to run the app: + + ```dotnetcli + dotnet run + ``` :::zone-end @@ -49,17 +68,16 @@ Get started with AI by creating a simple .NET 8 console chat application to summ 1. From a terminal or command prompt, navigate to the `azure-openai\01-HikeBenefitsSummary` directory. -:::zone-end - -2. It's now time to try the console application. Type in the following to run the app: +2. Use the `dotnet run` command to run the app: ```dotnetcli dotnet run ``` - :::zone target="docs" pivot="azure-openai" - If you get an error message the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. - :::zone-end +> [!NOTE] +> If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. + +:::zone-end ## Explore the code @@ -127,7 +145,8 @@ Use the `InvokePromptAsync` function to have the model generate a response based ```csharp // Submit the prompt and print out the response -string response = await kernel.InvokePromptAsync(prompt, new(new OpenAIPromptExecutionSettings() { MaxTokens = 400 })); +string response = await kernel.InvokePromptAsync( + prompt, new(new OpenAIPromptExecutionSettings() { MaxTokens = 400 })); Console.WriteLine($"assistant >>> {response}"); ``` @@ -143,8 +162,11 @@ When you no longer need the sample application or resources, remove the correspo azd down ``` +[!INCLUDE [troubleshoot](includes/troubleshoot.md)] + :::zone-end + ## Next steps - [Quickstart - Build an AI chat app with .NET](get-started-openai.md) From 491902799d54ac839438aaf80c7c153dd547ee39 Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Thu, 18 Jul 2024 17:01:01 -0400 Subject: [PATCH 20/31] fixes --- docs/ai/quickstarts/get-started-openai.md | 1 - docs/ai/quickstarts/includes/prerequisites-openai.md | 2 +- docs/ai/quickstarts/includes/troubleshoot.md | 9 ++++++++- docs/ai/quickstarts/quickstart-ai-chat-with-data.md | 1 - docs/ai/quickstarts/quickstart-openai-summarize-text.md | 1 - 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/ai/quickstarts/get-started-openai.md b/docs/ai/quickstarts/get-started-openai.md index cb4400d03e62c..98d876726ffb1 100644 --- a/docs/ai/quickstarts/get-started-openai.md +++ b/docs/ai/quickstarts/get-started-openai.md @@ -190,7 +190,6 @@ azd down :::zone-end - ## Next steps - [Quickstart - Get insight about your data from .NET AI chat app](quickstart-ai-chat-with-data.md) diff --git a/docs/ai/quickstarts/includes/prerequisites-openai.md b/docs/ai/quickstarts/includes/prerequisites-openai.md index 082d17feb6523..d3f9d5c0a1160 100644 --- a/docs/ai/quickstarts/includes/prerequisites-openai.md +++ b/docs/ai/quickstarts/includes/prerequisites-openai.md @@ -9,4 +9,4 @@ 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`. \ No newline at end of file +- 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`. diff --git a/docs/ai/quickstarts/includes/troubleshoot.md b/docs/ai/quickstarts/includes/troubleshoot.md index 9ddef936a04c1..4179dba627487 100644 --- a/docs/ai/quickstarts/includes/troubleshoot.md +++ b/docs/ai/quickstarts/includes/troubleshoot.md @@ -1,3 +1,10 @@ +--- +author: jmatthiesen +ms.author: jomatthi +ms.date: 07/03/2024 +ms.topic: include +--- + ## Troubleshoot On Windows, you might get the following error messages after running `azd up`: @@ -25,4 +32,4 @@ The script **postprovision.ps1** is executed to set the .NET user secrets used i .\infra\post-script\postprovision.ps1 ``` -The .NET AI apps now have the user-secrets configured and they can be tested. \ No newline at end of file +The .NET AI apps now have the user-secrets configured and they can be tested. diff --git a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md index cb53e005be3d3..1710fb775bb7e 100644 --- a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md +++ b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md @@ -184,7 +184,6 @@ azd down :::zone-end - ## Next steps - [Quickstart - Generate images using AI with .NET](quickstart-openai-generate-images.md) diff --git a/docs/ai/quickstarts/quickstart-openai-summarize-text.md b/docs/ai/quickstarts/quickstart-openai-summarize-text.md index 70b8bff42cf6d..f81217164e9a9 100644 --- a/docs/ai/quickstarts/quickstart-openai-summarize-text.md +++ b/docs/ai/quickstarts/quickstart-openai-summarize-text.md @@ -166,7 +166,6 @@ azd down :::zone-end - ## Next steps - [Quickstart - Build an AI chat app with .NET](get-started-openai.md) From adf87619c2c3da21c548c3ad13b7b5455fb2ed83 Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Thu, 18 Jul 2024 17:17:22 -0400 Subject: [PATCH 21/31] fix alerts --- docs/ai/quickstarts/get-started-openai.md | 4 ++-- docs/ai/quickstarts/includes/deploy-azd.md | 5 ++--- docs/ai/quickstarts/quickstart-ai-chat-with-data.md | 4 ++-- docs/ai/quickstarts/quickstart-azure-openai-tool.md | 4 ++-- docs/ai/quickstarts/quickstart-openai-generate-images.md | 4 ++-- docs/ai/quickstarts/quickstart-openai-summarize-text.md | 4 ++-- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/docs/ai/quickstarts/get-started-openai.md b/docs/ai/quickstarts/get-started-openai.md index 98d876726ffb1..c46ac8bd05543 100644 --- a/docs/ai/quickstarts/get-started-openai.md +++ b/docs/ai/quickstarts/get-started-openai.md @@ -74,8 +74,8 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic dotnet run ``` -> [!NOTE] -> If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. + > [!TIP] + > If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. :::zone-end diff --git a/docs/ai/quickstarts/includes/deploy-azd.md b/docs/ai/quickstarts/includes/deploy-azd.md index 8110274b84ef6..f451269d1fd7b 100644 --- a/docs/ai/quickstarts/includes/deploy-azd.md +++ b/docs/ai/quickstarts/includes/deploy-azd.md @@ -17,6 +17,5 @@ Ensure that you follow the [Prerequisites](#prerequisites) to have access to Azu azd up ``` -> [!NOTE] -> If you encounter an error during the `azd up` deployment, visit the [troubleshooting](#troubleshoot) section. - + > [!NOTE] + > If you encounter an error during the `azd up` deployment, visit the [troubleshooting](#troubleshoot) section. diff --git a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md index 1710fb775bb7e..7ec4b5fa23f56 100644 --- a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md +++ b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md @@ -72,8 +72,8 @@ Get started with AI development, using the `gpt-35-turbo` model from a simple .N dotnet run ``` -> [!NOTE] -> If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. + > [!TIP] + > If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. :::zone-end diff --git a/docs/ai/quickstarts/quickstart-azure-openai-tool.md b/docs/ai/quickstarts/quickstart-azure-openai-tool.md index 4a3e25e7b30a4..d16584b717f8b 100644 --- a/docs/ai/quickstarts/quickstart-azure-openai-tool.md +++ b/docs/ai/quickstarts/quickstart-azure-openai-tool.md @@ -74,8 +74,8 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap dotnet run ``` -> [!NOTE] -> If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. + > [!TIP] + > If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. :::zone-end diff --git a/docs/ai/quickstarts/quickstart-openai-generate-images.md b/docs/ai/quickstarts/quickstart-openai-generate-images.md index 43f5d9355e0fd..56748fc679367 100644 --- a/docs/ai/quickstarts/quickstart-openai-generate-images.md +++ b/docs/ai/quickstarts/quickstart-openai-generate-images.md @@ -74,8 +74,8 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap dotnet run ``` -> [!NOTE] -> If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. + > [!TIP] + > If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. :::zone-end diff --git a/docs/ai/quickstarts/quickstart-openai-summarize-text.md b/docs/ai/quickstarts/quickstart-openai-summarize-text.md index f81217164e9a9..7bfe74f365b69 100644 --- a/docs/ai/quickstarts/quickstart-openai-summarize-text.md +++ b/docs/ai/quickstarts/quickstart-openai-summarize-text.md @@ -74,8 +74,8 @@ Get started with AI by creating a simple .NET 8 console chat application to summ dotnet run ``` -> [!NOTE] -> If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. + > [!TIP] + > If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. :::zone-end From 06b7a7d6d4b96e805061a88dba4da5aed7454892 Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Thu, 18 Jul 2024 17:25:42 -0400 Subject: [PATCH 22/31] fix note --- docs/ai/quickstarts/includes/deploy-azd.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/ai/quickstarts/includes/deploy-azd.md b/docs/ai/quickstarts/includes/deploy-azd.md index f451269d1fd7b..4f440c8a9deba 100644 --- a/docs/ai/quickstarts/includes/deploy-azd.md +++ b/docs/ai/quickstarts/includes/deploy-azd.md @@ -17,5 +17,5 @@ Ensure that you follow the [Prerequisites](#prerequisites) to have access to Azu azd up ``` - > [!NOTE] - > If you encounter an error during the `azd up` deployment, visit the [troubleshooting](#troubleshoot) section. + > [!NOTE] + > If you encounter an error during the `azd up` deployment, visit the [troubleshooting](#troubleshoot) section. From acf6e17eacae1f8e2f8fb1cc5eb83f97b2407cea Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Thu, 18 Jul 2024 18:23:16 -0400 Subject: [PATCH 23/31] fixes --- .../quickstarts/quickstart-ai-chat-with-data.md | 10 ++++------ .../quickstart-openai-generate-images.md | 17 ++++++----------- .../quickstart-openai-summarize-text.md | 17 +++++------------ 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md index 7ec4b5fa23f56..f0540d5aea0ee 100644 --- a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md +++ b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md @@ -124,7 +124,7 @@ The `AzureOpenAIChatCompletionService` service facilitates the requests and resp AzureOpenAIChatCompletionService service = new(deployment, endpoint, key); ``` -Once the `AzureOpenAIChatCompletionService` 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 ```csharp @@ -138,9 +138,7 @@ ChatHistory chatHistory = new($""" Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}"); ``` -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 prompt to the model by using the `AddUserMessage` function.Call the `GetChatMessageContentAsync` function to instruct the model to generate a response based off the system and user prompts. ```csharp // Start the conversation @@ -154,12 +152,12 @@ chatHistory.Add( 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. +To maintain the chat history or context, add the response from the model to the `chatHistory`. ```csharp // Continue the conversation with a question. chatHistory.AddUserMessage( - "I would like to know the ratio of the hikesI've done in Canada compared to other countries."); + "I would like to know the ratio of the hikes I've done in Canada compared to other countries."); Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}"); chatHistory.Add(await service.GetChatMessageContentAsync( diff --git a/docs/ai/quickstarts/quickstart-openai-generate-images.md b/docs/ai/quickstarts/quickstart-openai-generate-images.md index 56748fc679367..c116abfca033f 100644 --- a/docs/ai/quickstarts/quickstart-openai-generate-images.md +++ b/docs/ai/quickstarts/quickstart-openai-generate-images.md @@ -12,9 +12,7 @@ zone_pivot_groups: openai-library # Generate images using AI with .NET - :::zone target="docs" pivot="openai" - Get started with AI by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `dall-e-3` model to generate postal card images so you can invite your friends for a hike! Follow these steps to get access to OpenAI and learn how to use Semantic Kernel. @@ -22,9 +20,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap :::zone-end - :::zone target="docs" pivot="azure-openai" - Get started with AI by creating a simple .NET 8 console chat application. The application will run locally and use the OpenAI `dall-e-3` model to generate postal card images so you can invite your friends for a hike! Follow these steps to provision Azure OpenAI and learn how to use the .NET Azure OpenAI SDK. @@ -44,7 +40,6 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap ## Try the the Hiking Images sample - :::zone target="docs" pivot="openai" 1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) @@ -78,15 +73,13 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap > If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. :::zone-end - ## Explore the code - :::zone target="docs" pivot="openai" 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. +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. ```csharp var config = new ConfigurationBuilder().AddUserSecrets().Build(); @@ -102,13 +95,13 @@ OpenAITextToImageService textToImageService = new(key, null); :::zone-end :::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 load 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().Build(); string endpoint = config["AZURE_OPENAI_ENDPOINT"]; string deployment = config["AZURE_OPENAI_GPT_NAME"]; @@ -123,7 +116,9 @@ AzureOpenAITextToImageService textToImageService = new(deployment, endpoint, key :::zone-end -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. +Provide context and instructions to the model by adding a system prompt. A good prompt to generate images requires a clear description: what is in the image, the specific color to use, style (drawing, painting, realistic or cartoony). + +Use the `GenerateImageAsync` function to have the model generate a response based off the user request and specify the size and quality. ```csharp // Generate the image diff --git a/docs/ai/quickstarts/quickstart-openai-summarize-text.md b/docs/ai/quickstarts/quickstart-openai-summarize-text.md index 7bfe74f365b69..61227fa1249b9 100644 --- a/docs/ai/quickstarts/quickstart-openai-summarize-text.md +++ b/docs/ai/quickstarts/quickstart-openai-summarize-text.md @@ -12,9 +12,7 @@ zone_pivot_groups: openai-library # Summarize text using AI chat app with .NET - :::zone target="docs" pivot="openai" - 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. @@ -22,9 +20,7 @@ Get started with AI by creating a simple .NET 8 console chat application to summ :::zone-end - :::zone target="docs" pivot="azure-openai" - 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. @@ -44,7 +40,6 @@ Get started with AI by creating a simple .NET 8 console chat application to summ ## Try the Hiking Benefits Summary sample - :::zone target="docs" pivot="openai" 1. From a terminal or command prompt, navigate to the `openai\01-HikeBenefitsSummary` directory. @@ -81,13 +76,11 @@ Get started with AI by creating a simple .NET 8 console chat application to summ ## Explore the code - :::zone target="docs" pivot="openai" - 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 **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. ```csharp var config = new ConfigurationBuilder().AddUserSecrets().Build(); @@ -109,10 +102,10 @@ 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 retrieve secrets and configuration values that were set in the `dotnet user-secrets` for you during the application provisioning. +The **Program.cs** file contains all of the app code. 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. ```csharp -// == Retrieve the local secrets saved during the Azure deployment ========== +// Retrieve the local secrets saved during the Azure deployment var config = new ConfigurationBuilder().AddUserSecrets().Build(); string endpoint = config["AZURE_OPENAI_ENDPOINT"]; string deployment = config["AZURE_OPENAI_GPT_NAME"]; @@ -130,7 +123,7 @@ Kernel kernel = Kernel.CreateBuilder() :::zone-end -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. +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 text. ```csharp // Create and print out the prompt @@ -141,7 +134,7 @@ string prompt = $""" Console.WriteLine($"user >>> {prompt}"); ``` -Use the `InvokePromptAsync` function to have the model generate a response based on the `prompt` value. +The `InvokePromptAsync` function sends the `prompt` to the model to generate a response. ```csharp // Submit the prompt and print out the response From 3acf04de104e5af0b700dc5406ab83d31bfea3ba Mon Sep 17 00:00:00 2001 From: Jordan Matthiesen <1333029+jmatthiesen@users.noreply.github.com> Date: Mon, 22 Jul 2024 10:05:35 -0700 Subject: [PATCH 24/31] Update quickstart-openai-generate-images.md Fixed a linting error --- docs/ai/quickstarts/quickstart-openai-generate-images.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ai/quickstarts/quickstart-openai-generate-images.md b/docs/ai/quickstarts/quickstart-openai-generate-images.md index c116abfca033f..43c18eec4ad90 100644 --- a/docs/ai/quickstarts/quickstart-openai-generate-images.md +++ b/docs/ai/quickstarts/quickstart-openai-generate-images.md @@ -116,7 +116,7 @@ AzureOpenAITextToImageService textToImageService = new(deployment, endpoint, key :::zone-end -Provide context and instructions to the model by adding a system prompt. A good prompt to generate images requires a clear description: what is in the image, the specific color to use, style (drawing, painting, realistic or cartoony). +Provide context and instructions to the model by adding a system prompt. A good prompt to generate images requires a clear description: what is in the image, the specific color to use, style (drawing, painting, realistic or cartoony). Use the `GenerateImageAsync` function to have the model generate a response based off the user request and specify the size and quality. From 4a1d3c019569a08595bb1fc0ec8e225bceeed566 Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Tue, 23 Jul 2024 11:29:19 -0400 Subject: [PATCH 25/31] fix pivot --- docs/ai/quickstarts/get-started-openai.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/ai/quickstarts/get-started-openai.md b/docs/ai/quickstarts/get-started-openai.md index c46ac8bd05543..da44262fb4eda 100644 --- a/docs/ai/quickstarts/get-started-openai.md +++ b/docs/ai/quickstarts/get-started-openai.md @@ -79,6 +79,8 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone-end +:::zone target="docs" pivot="openai" + ## Explore the code The app uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to the OpenAI service. @@ -98,15 +100,13 @@ The `OpenAIChatCompletionService` service facilitates the requests and responses OpenAIChatCompletionService service = new(model, key); ``` -Provide more context to the model by adding a system prompt, which influences model behavior and the generated completions during the conversation. - :::zone-end :::zone target="docs" pivot="azure-openai" -## Understanding the code +## Explore the code 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. @@ -127,10 +127,10 @@ The `AzureOpenAIChatCompletionService` service facilitates the requests and resp AzureOpenAIChatCompletionService service = new(deployment, endpoint, key); ``` -Add a system prompt to provide more context to the model, which influences model behavior and the generated completions during the conversation. - :::zone-end +Add a system prompt to provide more context to the model, which influences model behavior and the generated completions during the conversation. + ```csharp // Start the conversation with context for the AI model ChatHistory chatHistory = new(""" From 692777f50d9c437cde5a53621bfa69eade558bd3 Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Tue, 23 Jul 2024 11:56:29 -0400 Subject: [PATCH 26/31] fixes --- docs/ai/quickstarts/get-started-openai.md | 4 +-- .../quickstarts/includes/clone-sample-repo.md | 2 +- .../quickstart-ai-chat-with-data.md | 28 +++++++++++++------ .../quickstart-azure-openai-tool.md | 2 +- .../quickstart-openai-generate-images.md | 2 +- .../quickstart-openai-summarize-text.md | 19 ++++++++----- 6 files changed, 37 insertions(+), 20 deletions(-) diff --git a/docs/ai/quickstarts/get-started-openai.md b/docs/ai/quickstarts/get-started-openai.md index da44262fb4eda..522cd8026b4cd 100644 --- a/docs/ai/quickstarts/get-started-openai.md +++ b/docs/ai/quickstarts/get-started-openai.md @@ -16,7 +16,7 @@ zone_pivot_groups: openai-library :::zone target="docs" pivot="openai" -Get started with Semantic Kernel by creating a simple .NET 8 console chat application. 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 OpenAI and [Semantic Kernel](../semantic-kernel-dotnet-overview.md) by creating a simple .NET 8.0 console chat application. 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. [!INCLUDE [download-alert](includes/prerequisites-openai.md)] @@ -26,7 +26,7 @@ Get started with Semantic Kernel by creating a simple .NET 8 console chat applic :::zone target="docs" pivot="azure-openai" -Get started with Semantic Kernel by creating a simple .NET 8 console chat application. 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 OpenAI and [Semantic Kernel](../semantic-kernel-dotnet-overview.md) by creating a simple .NET 8.0 console chat application. 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. [!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)] diff --git a/docs/ai/quickstarts/includes/clone-sample-repo.md b/docs/ai/quickstarts/includes/clone-sample-repo.md index a644d271f13bc..33e028ab1342f 100644 --- a/docs/ai/quickstarts/includes/clone-sample-repo.md +++ b/docs/ai/quickstarts/includes/clone-sample-repo.md @@ -5,7 +5,7 @@ ms.date: 07/03/2024 ms.topic: include --- -A GitHub repository is available that contains all the sample apps for all of the quickstarts. Clone the repository using the following command: +A GitHub repository is available that contains the sample apps for all of the quickstarts. Clone the repository using the following command: ```bash git clone https://github.com/dotnet/ai-samples.git diff --git a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md index f0540d5aea0ee..df214591d5091 100644 --- a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md +++ b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md @@ -16,7 +16,7 @@ zone_pivot_groups: openai-library :::zone target="docs" pivot="openai" -Get started with AI development, using the `gpt-3.5-turbo` model from a simple .NET 8.0 console application. Use the AI model to get analytics and information about your previous hikes. It consists of a simple console application, running locally, that will read the file `hikes.md` and send request to the OpenAI service and provide the result in the console. Follow these steps to get access to OpenAI and learn how to use Semantic Kernel. +Get started with AI development using a .NET 8.0 console app to connect to an OpenAI `gpt-3.5-turbo` model. You'll connect to the AI model using [Semantic Kernel](../semantic-kernel-dotnet-overview.md) to analyze hiking data and provide insights. [!INCLUDE [download-alert](includes/prerequisites-openai.md)] :::zone-end @@ -25,7 +25,7 @@ Get started with AI development, using the `gpt-3.5-turbo` model from a simple . :::zone target="docs" pivot="azure-openai" -Get started with AI development, using the `gpt-35-turbo` model from a simple .NET 8.0 console application. Use the AI model to get analytics and information about your previous hikes. It consists of a simple console application, running locally, that will read the file `hikes.md` and send request to an Azure OpenAI service deployed in your Azure subscription and provide the result in the console. Follow these steps to provision Azure OpenAI and learn how to use the .NET Azure OpenAI SDK. +Get started with AI development using a .NET 8.0 console app to connect to an OpenAI `gpt-3.5-turbo` model deployed on Azure. You'll connect to the AI model using [Semantic Kernel](../semantic-kernel-dotnet-overview.md) to analyze hiking data and provide insights. [!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)] :::zone-end @@ -40,7 +40,7 @@ Get started with AI development, using the `gpt-35-turbo` model from a simple .N :::zone-end -## Try the "Chatting About My Previous Hikes" sample +## Try the hiking chat sample :::zone target="docs" pivot="openai" @@ -105,6 +105,7 @@ Once the `OpenAIChatCompletionService` client is created, the app reads the cont :::zone-end :::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 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. @@ -138,7 +139,7 @@ ChatHistory chatHistory = new($""" Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}"); ``` -Add a user prompt to the model by using the `AddUserMessage` function.Call the `GetChatMessageContentAsync` function to instruct the model to generate a response based off the system and user prompts. +The following code adds a user prompt to the model using the `AddUserMessage` function. The `GetChatMessageContentAsync` function instructs the model to generate a response based off the system and user prompts. ```csharp // Start the conversation @@ -148,25 +149,36 @@ Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}") chatHistory.Add( await service.GetChatMessageContentAsync( chatHistory, - new OpenAIPromptExecutionSettings() { MaxTokens = 400 })); + new OpenAIPromptExecutionSettings() + { + MaxTokens = 400 + })); Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}"); ``` -To maintain the chat history or context, add the response from the model to the `chatHistory`. +The app adds the response from the model to the `chatHistory` to maintain the chat history or context. ```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."); + Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}"); chatHistory.Add(await service.GetChatMessageContentAsync( chatHistory, - new OpenAIPromptExecutionSettings() { MaxTokens = 400 })); + new OpenAIPromptExecutionSettings() + { + MaxTokens = 400 + })); + Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}"); ``` -Customize the system prompt and change the request, asking for different questions (ex: How many times did you hiked when it was raining? How many times did you hiked in 2021? etc.) to see how the model responds. +Customize the system prompt or user prompt to provide different questions and context to see how the models responds: + +- How many times did I hike when it was raining? +- How many times did I hike in 2021? :::zone target="docs" pivot="azure-openai" diff --git a/docs/ai/quickstarts/quickstart-azure-openai-tool.md b/docs/ai/quickstarts/quickstart-azure-openai-tool.md index d16584b717f8b..38c491c06c0fd 100644 --- a/docs/ai/quickstarts/quickstart-azure-openai-tool.md +++ b/docs/ai/quickstarts/quickstart-azure-openai-tool.md @@ -42,7 +42,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap :::zone-end -## Try the the HikerAI Pro sample +## Try the the hiker pro sample :::zone target="docs" pivot="openai" diff --git a/docs/ai/quickstarts/quickstart-openai-generate-images.md b/docs/ai/quickstarts/quickstart-openai-generate-images.md index 43c18eec4ad90..72443db8631cc 100644 --- a/docs/ai/quickstarts/quickstart-openai-generate-images.md +++ b/docs/ai/quickstarts/quickstart-openai-generate-images.md @@ -38,7 +38,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap :::zone-end -## Try the the Hiking Images sample +## Try the the hiking images sample :::zone target="docs" pivot="openai" diff --git a/docs/ai/quickstarts/quickstart-openai-summarize-text.md b/docs/ai/quickstarts/quickstart-openai-summarize-text.md index 61227fa1249b9..7bf23b7c76839 100644 --- a/docs/ai/quickstarts/quickstart-openai-summarize-text.md +++ b/docs/ai/quickstarts/quickstart-openai-summarize-text.md @@ -14,7 +14,7 @@ zone_pivot_groups: openai-library :::zone target="docs" pivot="openai" -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. +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. [!INCLUDE [download-alert](includes/prerequisites-openai.md)] @@ -22,7 +22,7 @@ Get started with AI by creating a simple .NET 8 console chat application to summ :::zone target="docs" pivot="azure-openai" -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. +Get started with AI by creating a simple .NET 8.0 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)] @@ -38,7 +38,7 @@ Get started with AI by creating a simple .NET 8 console chat application to summ :::zone-end -## Try the Hiking Benefits Summary sample +## Try the hiking benefits sample :::zone target="docs" pivot="openai" @@ -88,7 +88,7 @@ string model = "gpt-3.5-turbo"; string key = config["OpenAIKey"]; ``` -The `Kernel` class facilitates the requests and responses with the help of `AddOpenAIChatCompletion` service. +The `Kernel` class facilitates the requests and responses and registers an `OpenAIChatCompletion` service. ```csharp // Create a Kernel containing the OpenAI Chat Completion Service @@ -112,7 +112,7 @@ string deployment = config["AZURE_OPENAI_GPT_NAME"]; string key = config["AZURE_OPENAI_KEY"]; ``` -The `Kernel` class facilitates the requests and responses with the help of `AddAzureOpenAIChatCompletion` service. +The `Kernel` class facilitates the requests and responses and registers an `OpenAIChatCompletion` service. ```csharp // Create a Kernel containing the Azure OpenAI Chat Completion Service @@ -123,7 +123,7 @@ Kernel kernel = Kernel.CreateBuilder() :::zone-end -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 text. +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. ```csharp // Create and print out the prompt @@ -139,7 +139,12 @@ The `InvokePromptAsync` function sends the `prompt` to the model to generate a r ```csharp // Submit the prompt and print out the response string response = await kernel.InvokePromptAsync( - prompt, new(new OpenAIPromptExecutionSettings() { MaxTokens = 400 })); + prompt, + new(new OpenAIPromptExecutionSettings() + { + MaxTokens = 400 + }) + ); Console.WriteLine($"assistant >>> {response}"); ``` From 1f70b9c56ec722ee79713ae72afaf21700a1c547 Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Tue, 23 Jul 2024 12:22:55 -0400 Subject: [PATCH 27/31] fixes --- .../quickstart-ai-chat-with-data.md | 4 +++- .../quickstart-azure-openai-tool.md | 18 +++++++++++------- .../quickstart-openai-generate-images.md | 10 ++++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md index df214591d5091..5204a06b5b72c 100644 --- a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md +++ b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md @@ -175,11 +175,13 @@ chatHistory.Add(await service.GetChatMessageContentAsync( Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last().Content}"); ``` -Customize the system prompt or user prompt to provide different questions and context to see how the models responds: +Customize the system or user prompts to provide different questions and context: - How many times did I hike when it was raining? - How many times did I hike in 2021? +The model generates a relevant response to each prompt based on your inputs. + :::zone target="docs" pivot="azure-openai" ## Clean up resources diff --git a/docs/ai/quickstarts/quickstart-azure-openai-tool.md b/docs/ai/quickstarts/quickstart-azure-openai-tool.md index 38c491c06c0fd..00fefdf625c6e 100644 --- a/docs/ai/quickstarts/quickstart-azure-openai-tool.md +++ b/docs/ai/quickstarts/quickstart-azure-openai-tool.md @@ -122,7 +122,7 @@ string deployment = config["AZURE_OPENAI_GPT_NAME"]; string key = config["AZURE_OPENAI_KEY"]; ``` -The `Kernel` class facilitates the requests and responses with the help of `AddAzureOpenAIChatCompletion` service. +The `Kernel` class facilitates the requests and responses with the help of `AzureOpenAIChatCompletion` service. ```csharp // Create a Kernel containing the Azure OpenAI Chat Completion Service @@ -135,7 +135,7 @@ Kernel kernel = b :::zone-end -The function's `ImportPluginFromFunctions` and `CreateFromMethod` are used to define the local function that will be called by the model. +The function's `ImportPluginFromFunctions` and `CreateFromMethod` define the local function that will be called by the model. ```csharp // Add a new plugin with a local .NET function that should be available to the AI model @@ -151,7 +151,7 @@ kernel.ImportPluginFromFunctions("WeatherPlugin", ]); ``` -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. +Once the `kernel` client is created, the code uses a system prompt to provide context and influence the completion tone and content. Note how the weather is emphasized in the system prompt. ```csharp ChatHistory chatHistory = new(""" @@ -170,9 +170,7 @@ ChatHistory chatHistory = new(""" """); ``` -Then you can add a user message to the model by using the `AddUserMessage` functon. - -To have the model generate a response based off the system prompt and the user request, use the `GetChatMessageContentAsync` function. +The app also adds a user message to the model using the `AddUserMessage` function. The `GetChatMessageContentAsync` function sends the chat history to the model to generate a response based off the system and user prompts. ```csharp chatHistory.AddUserMessage(""" @@ -186,7 +184,13 @@ chatHistory.AddUserMessage(""" 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}"); ``` diff --git a/docs/ai/quickstarts/quickstart-openai-generate-images.md b/docs/ai/quickstarts/quickstart-openai-generate-images.md index 72443db8631cc..b1215a5035c8b 100644 --- a/docs/ai/quickstarts/quickstart-openai-generate-images.md +++ b/docs/ai/quickstarts/quickstart-openai-generate-images.md @@ -77,9 +77,10 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap ## Explore the code :::zone target="docs" pivot="openai" + The application uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to the OpenAI service. -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 _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. ```csharp var config = new ConfigurationBuilder().AddUserSecrets().Build(); @@ -98,7 +99,7 @@ OpenAITextToImageService textToImageService = new(key, null); 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. +The _Program.cs_ file contains all of the app code. 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. ```csharp // Retrieve the local secrets saved during the Azure deployment @@ -116,9 +117,9 @@ AzureOpenAITextToImageService textToImageService = new(deployment, endpoint, key :::zone-end -Provide context and instructions to the model by adding a system prompt. A good prompt to generate images requires a clear description: what is in the image, the specific color to use, style (drawing, painting, realistic or cartoony). +Provide context and instructions to the model by adding a system prompt. A good image generation prompt requires a clear description of what the image is, which colors to use, the intended style, and other descriptors. -Use the `GenerateImageAsync` function to have the model generate a response based off the user request and specify the size and quality. +The `GenerateImageAsync` function instructs the model to generate a response based on the user prompt and image size and quality configurations. ```csharp // Generate the image @@ -127,6 +128,7 @@ string imageUrl = await textToImageService.GenerateImageAsync(""" There is a trail visible in the foreground. The postal card has text in red saying: 'You are invited for a hike!' """, 1024, 1024); + Console.WriteLine($"The generated image is ready at:\n{imageUrl}"); ``` From 066341f03d35fbcdf386bf82cf46ccd385004623 Mon Sep 17 00:00:00 2001 From: alexwolfmsft <93200798+alexwolfmsft@users.noreply.github.com> Date: Mon, 29 Jul 2024 21:16:34 -0400 Subject: [PATCH 28/31] Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- docs/ai/quickstarts/get-started-openai.md | 10 +++++----- docs/ai/quickstarts/includes/deploy-azd.md | 4 ++-- .../quickstarts/includes/prerequisites-azure-openai.md | 6 +++--- docs/ai/quickstarts/includes/troubleshoot.md | 2 +- docs/ai/quickstarts/quickstart-ai-chat-with-data.md | 6 +++--- .../quickstarts/quickstart-openai-generate-images.md | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/ai/quickstarts/get-started-openai.md b/docs/ai/quickstarts/get-started-openai.md index 522cd8026b4cd..2ca135c396b69 100644 --- a/docs/ai/quickstarts/get-started-openai.md +++ b/docs/ai/quickstarts/get-started-openai.md @@ -16,7 +16,7 @@ zone_pivot_groups: openai-library :::zone target="docs" pivot="openai" -Get started with OpenAI and [Semantic Kernel](../semantic-kernel-dotnet-overview.md) by creating a simple .NET 8.0 console chat application. 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 OpenAI and [Semantic Kernel](../semantic-kernel-dotnet-overview.md) by creating a simple .NET 8 console chat application. 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. [!INCLUDE [download-alert](includes/prerequisites-openai.md)] @@ -26,7 +26,7 @@ Get started with OpenAI and [Semantic Kernel](../semantic-kernel-dotnet-overview :::zone target="docs" pivot="azure-openai" -Get started with OpenAI and [Semantic Kernel](../semantic-kernel-dotnet-overview.md) by creating a simple .NET 8.0 console chat application. 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 OpenAI and [Semantic Kernel](../semantic-kernel-dotnet-overview.md) by creating a simple .NET 8 console chat application. 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. [!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)] @@ -75,7 +75,7 @@ Get started with OpenAI and [Semantic Kernel](../semantic-kernel-dotnet-overview ``` > [!TIP] - > If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. + > If you get an error message, the Azure OpenAI resources might not have finished deploying. Wait a couple of minutes and try again. :::zone-end @@ -85,7 +85,7 @@ Get started with OpenAI and [Semantic Kernel](../semantic-kernel-dotnet-overview The app uses the [`Microsoft.SemanticKernel`](https://www.nuget.org/packages/Microsoft.SemanticKernel) package to send and receive requests to the OpenAI service. -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. +The app code is contained within the **Program.cs** file. The first several lines of code set configuration values and get the OpenAI Key that was previously set using the `dotnet user-secrets` command. ```csharp var config = new ConfigurationBuilder().AddUserSecrets().Build(); @@ -110,7 +110,7 @@ OpenAIChatCompletionService service = new(model, key); 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 retrieves the 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 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 diff --git a/docs/ai/quickstarts/includes/deploy-azd.md b/docs/ai/quickstarts/includes/deploy-azd.md index 4f440c8a9deba..cdaaf650e63ad 100644 --- a/docs/ai/quickstarts/includes/deploy-azd.md +++ b/docs/ai/quickstarts/includes/deploy-azd.md @@ -7,11 +7,11 @@ ms.topic: include ## Deploy the Azure resources -Ensure that you follow the [Prerequisites](#prerequisites) to have access to Azure OpenAI Service as well as the Azure Developer CLI, and then follow the following guide to set started with the sample application. +Ensure that you follow the [Prerequisites](#prerequisites) to have access to Azure OpenAI Service as well as the Azure Developer CLI, and then use the following guide to get started with the sample application. 1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) 1. From a terminal or command prompt, navigate to the _src\quickstarts\azure-openai_ directory (on macOS or Linux, replace the '\\' character with a '/'. -1. This provisions the Azure OpenAI resources. It may take several minutes to create the Azure OpenAI service and deploy the model. +1. The following command provisions the Azure OpenAI resources. It might take several minutes to create the Azure OpenAI service and deploy the model. ```azdeveloper azd up diff --git a/docs/ai/quickstarts/includes/prerequisites-azure-openai.md b/docs/ai/quickstarts/includes/prerequisites-azure-openai.md index f6326525ff4b3..388d5b7d77926 100644 --- a/docs/ai/quickstarts/includes/prerequisites-azure-openai.md +++ b/docs/ai/quickstarts/includes/prerequisites-azure-openai.md @@ -7,8 +7,8 @@ ms.topic: include ## Prerequisites -- .NET 8.0 SDK - [Install the .NET 8.0 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) -- An Azure subscription - [Create one for free](https://azure.microsoft.com/free) -- Azure Developer CLI - [Install or update the Azure Developer CLI](/azure/developer/azure-developer-cli/install-azd) +- .NET 8 SDK - [Install the .NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0). +- An Azure subscription - [Create one for free](https://azure.microsoft.com/free). +- Azure Developer CLI - [Install or update the Azure Developer CLI](/azure/developer/azure-developer-cli/install-azd). - Access to [Azure OpenAI service](/azure/ai-services/openai/overview#how-do-i-get-access-to-azure-openai). - 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`. diff --git a/docs/ai/quickstarts/includes/troubleshoot.md b/docs/ai/quickstarts/includes/troubleshoot.md index 4179dba627487..e0c2f7c0119ec 100644 --- a/docs/ai/quickstarts/includes/troubleshoot.md +++ b/docs/ai/quickstarts/includes/troubleshoot.md @@ -32,4 +32,4 @@ The script **postprovision.ps1** is executed to set the .NET user secrets used i .\infra\post-script\postprovision.ps1 ``` -The .NET AI apps now have the user-secrets configured and they can be tested. +The .NET AI apps now have the user secrets configured and they can be tested. diff --git a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md index 5204a06b5b72c..51a272c98ba91 100644 --- a/docs/ai/quickstarts/quickstart-ai-chat-with-data.md +++ b/docs/ai/quickstarts/quickstart-ai-chat-with-data.md @@ -16,7 +16,7 @@ zone_pivot_groups: openai-library :::zone target="docs" pivot="openai" -Get started with AI development using a .NET 8.0 console app to connect to an OpenAI `gpt-3.5-turbo` model. You'll connect to the AI model using [Semantic Kernel](../semantic-kernel-dotnet-overview.md) to analyze hiking data and provide insights. +Get started with AI development using a .NET 8 console app to connect to an OpenAI `gpt-3.5-turbo` model. You'll connect to the AI model using [Semantic Kernel](../semantic-kernel-dotnet-overview.md) to analyze hiking data and provide insights. [!INCLUDE [download-alert](includes/prerequisites-openai.md)] :::zone-end @@ -25,7 +25,7 @@ Get started with AI development using a .NET 8.0 console app to connect to an Op :::zone target="docs" pivot="azure-openai" -Get started with AI development using a .NET 8.0 console app to connect to an OpenAI `gpt-3.5-turbo` model deployed on Azure. You'll connect to the AI model using [Semantic Kernel](../semantic-kernel-dotnet-overview.md) to analyze hiking data and provide insights. +Get started with AI development using a .NET 8 console app to connect to an OpenAI `gpt-3.5-turbo` model deployed on Azure. You'll connect to the AI model using [Semantic Kernel](../semantic-kernel-dotnet-overview.md) to analyze hiking data and provide insights. [!INCLUDE [download-alert](includes/prerequisites-azure-openai.md)] :::zone-end @@ -73,7 +73,7 @@ Get started with AI development using a .NET 8.0 console app to connect to an Op ``` > [!TIP] - > If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. + > If you get an error message, the Azure OpenAI resources might not have finished deploying. Wait a couple of minutes and try again. :::zone-end diff --git a/docs/ai/quickstarts/quickstart-openai-generate-images.md b/docs/ai/quickstarts/quickstart-openai-generate-images.md index b1215a5035c8b..99ad604af92a6 100644 --- a/docs/ai/quickstarts/quickstart-openai-generate-images.md +++ b/docs/ai/quickstarts/quickstart-openai-generate-images.md @@ -70,7 +70,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap ``` > [!TIP] - > If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. + > If you get an error message, the Azure OpenAI resources might not have finished deploying. Wait a couple of minutes and try again. :::zone-end @@ -124,7 +124,7 @@ The `GenerateImageAsync` function instructs the model to generate a response bas ```csharp // Generate the image string imageUrl = await textToImageService.GenerateImageAsync(""" - A postal card with an happy hiker waving and a beautiful mountain in the background. + A postal card with a happy hiker waving and a beautiful mountain in the background. There is a trail visible in the foreground. The postal card has text in red saying: 'You are invited for a hike!' """, 1024, 1024); From a716388d13c7eb4ceb3c3de8b52e69b81e9d05c1 Mon Sep 17 00:00:00 2001 From: alexwolfmsft <93200798+alexwolfmsft@users.noreply.github.com> Date: Mon, 29 Jul 2024 21:19:33 -0400 Subject: [PATCH 29/31] Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- docs/ai/quickstarts/includes/deploy-azd.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ai/quickstarts/includes/deploy-azd.md b/docs/ai/quickstarts/includes/deploy-azd.md index cdaaf650e63ad..f5877c1119422 100644 --- a/docs/ai/quickstarts/includes/deploy-azd.md +++ b/docs/ai/quickstarts/includes/deploy-azd.md @@ -10,7 +10,7 @@ ms.topic: include Ensure that you follow the [Prerequisites](#prerequisites) to have access to Azure OpenAI Service as well as the Azure Developer CLI, and then use the following guide to get started with the sample application. 1. Clone the repository: [dotnet/ai-samples](https://github.com/dotnet/ai-samples) -1. From a terminal or command prompt, navigate to the _src\quickstarts\azure-openai_ directory (on macOS or Linux, replace the '\\' character with a '/'. +1. From a terminal or command prompt, navigate to the _src\quickstarts\azure-openai_ directory (on macOS or Linux, replace the '\\' character with a '/'). 1. The following command provisions the Azure OpenAI resources. It might take several minutes to create the Azure OpenAI service and deploy the model. ```azdeveloper From 50d43293f42729d3fdee8e22ba7092716b634603 Mon Sep 17 00:00:00 2001 From: alexwolfmsft <93200798+alexwolfmsft@users.noreply.github.com> Date: Tue, 30 Jul 2024 08:56:57 -0400 Subject: [PATCH 30/31] Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- docs/ai/quickstarts/quickstart-azure-openai-tool.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/ai/quickstarts/quickstart-azure-openai-tool.md b/docs/ai/quickstarts/quickstart-azure-openai-tool.md index 00fefdf625c6e..ed2e71ac13fa2 100644 --- a/docs/ai/quickstarts/quickstart-azure-openai-tool.md +++ b/docs/ai/quickstarts/quickstart-azure-openai-tool.md @@ -75,7 +75,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap ``` > [!TIP] - > If you get an error message, the Azure OpenAI resources may not have finished deploying. Wait a couple of minutes and try again. + > If you get an error message, the Azure OpenAI resources might not have finished deploying. Wait a couple of minutes and try again. :::zone-end @@ -87,7 +87,7 @@ Get started with AI by creating a simple .NET 8 console chat application. The ap 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. +The entire application is contained within the **Program.cs** file. The first several lines of code set configuration values and get the OpenAI Key that was previously set using the `dotnet user-secrets` command. ```csharp var config = new ConfigurationBuilder().AddUserSecrets().Build(); @@ -135,7 +135,7 @@ Kernel kernel = b :::zone-end -The function's `ImportPluginFromFunctions` and `CreateFromMethod` define the local function that will be called by the model. +The functions `ImportPluginFromFunctions` and `CreateFromMethod` define the local function that will be called by the model. ```csharp // Add a new plugin with a local .NET function that should be available to the AI model @@ -156,7 +156,7 @@ Once the `kernel` client is created, the code uses a system prompt to provide co ```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. + You are upbeat and friendly. 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: From 9845983e20f4e587bc35d50b801709c61469e761 Mon Sep 17 00:00:00 2001 From: alexwolfmsft <93200798+alexwolfmsft@users.noreply.github.com> Date: Tue, 30 Jul 2024 09:22:34 -0400 Subject: [PATCH 31/31] Update dotnet-ai-overview.md --- docs/ai/get-started/dotnet-ai-overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ai/get-started/dotnet-ai-overview.md b/docs/ai/get-started/dotnet-ai-overview.md index 7588586ed4370..a8c3c804d440e 100644 --- a/docs/ai/get-started/dotnet-ai-overview.md +++ b/docs/ai/get-started/dotnet-ai-overview.md @@ -1,7 +1,7 @@ --- title: Develop .NET applications with AI features description: Learn how you can build .NET applications that include AI features. -ms.date: 05/17/2024 +ms.date: 07/30/2024 ms.topic: overview ms.custom: devx-track-dotnet, devx-track-dotnet-ai ---