diff --git a/dotnet/samples/GettingStarted/Step1_Create_Kernel.cs b/dotnet/samples/GettingStarted/Step1_Create_Kernel.cs index bcb704b6654d..132d2b830639 100644 --- a/dotnet/samples/GettingStarted/Step1_Create_Kernel.cs +++ b/dotnet/samples/GettingStarted/Step1_Create_Kernel.cs @@ -6,19 +6,19 @@ namespace GettingStarted; /// -/// This example shows how to create and use a . +/// This example shows how to create and use a with ChatClient. /// public sealed class Step1_Create_Kernel(ITestOutputHelper output) : BaseTest(output) { /// - /// Show how to create a and use it to execute prompts. + /// Show how to create a using ChatClient and use it to execute prompts. /// [Fact] public async Task CreateKernel() { - // Create a kernel with OpenAI chat completion + // Create a kernel with OpenAI chat completion using ChatClient Kernel kernel = Kernel.CreateBuilder() - .AddOpenAIChatCompletion( + .AddOpenAIChatClient( modelId: TestConfiguration.OpenAI.ChatModelId, apiKey: TestConfiguration.OpenAI.ApiKey) .Build(); diff --git a/dotnet/samples/GettingStarted/Step2_Add_Plugins.cs b/dotnet/samples/GettingStarted/Step2_Add_Plugins.cs index 3f6b277fe5f3..5b233f734b2f 100644 --- a/dotnet/samples/GettingStarted/Step2_Add_Plugins.cs +++ b/dotnet/samples/GettingStarted/Step2_Add_Plugins.cs @@ -9,36 +9,40 @@ namespace GettingStarted; /// -/// This example shows how to load a instances. +/// This example shows how to load a instances with ChatClient. /// public sealed class Step2_Add_Plugins(ITestOutputHelper output) : BaseTest(output) { /// - /// Shows different ways to load a instances. + /// Shows different ways to load a instances with ChatClient. /// [Fact] public async Task AddPlugins() { - // Create a kernel with OpenAI chat completion + // Create a kernel with ChatClient and plugins IKernelBuilder kernelBuilder = Kernel.CreateBuilder(); - kernelBuilder.AddOpenAIChatCompletion( - modelId: TestConfiguration.OpenAI.ChatModelId, - apiKey: TestConfiguration.OpenAI.ApiKey); + kernelBuilder.AddOpenAIChatClient( + modelId: TestConfiguration.OpenAI.ChatModelId, + apiKey: TestConfiguration.OpenAI.ApiKey); kernelBuilder.Plugins.AddFromType(); kernelBuilder.Plugins.AddFromType(); Kernel kernel = kernelBuilder.Build(); // Example 1. Invoke the kernel with a prompt that asks the AI for information it cannot provide and may hallucinate + Console.WriteLine("Example 1: Asking the AI for information it cannot provide:"); Console.WriteLine(await kernel.InvokePromptAsync("How many days until Christmas?")); - // Example 2. Invoke the kernel with a templated prompt that invokes a plugin and display the result + // Example 2. Use kernel for templated prompts that invoke plugins directly + Console.WriteLine("\nExample 2: Using templated prompts that invoke plugins directly:"); Console.WriteLine(await kernel.InvokePromptAsync("The current time is {{TimeInformation.GetCurrentUtcTime}}. How many days until Christmas?")); - // Example 3. Invoke the kernel with a prompt and allow the AI to automatically invoke functions + // Example 3. Use kernel with function calling for automatic plugin invocation OpenAIPromptExecutionSettings settings = new() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() }; + Console.WriteLine("\nExample 3: Using function calling for automatic plugin invocation:"); Console.WriteLine(await kernel.InvokePromptAsync("How many days until Christmas? Explain your thinking.", new(settings))); - // Example 4. Invoke the kernel with a prompt and allow the AI to automatically invoke functions that use enumerations + // Example 4. Use kernel with function calling for complex scenarios with enumerations + Console.WriteLine("\nExample 4: Using function calling for complex scenarios with enumerations:"); Console.WriteLine(await kernel.InvokePromptAsync("Create a handy lime colored widget for me.", new(settings))); Console.WriteLine(await kernel.InvokePromptAsync("Create a beautiful scarlet colored widget for me.", new(settings))); Console.WriteLine(await kernel.InvokePromptAsync("Create an attractive maroon and navy colored widget for me.", new(settings))); diff --git a/dotnet/samples/GettingStarted/Step3_Yaml_Prompt.cs b/dotnet/samples/GettingStarted/Step3_Yaml_Prompt.cs index 911933b0909c..2c8090e28beb 100644 --- a/dotnet/samples/GettingStarted/Step3_Yaml_Prompt.cs +++ b/dotnet/samples/GettingStarted/Step3_Yaml_Prompt.cs @@ -19,7 +19,7 @@ public async Task CreatePromptFromYaml() { // Create a kernel with OpenAI chat completion Kernel kernel = Kernel.CreateBuilder() - .AddOpenAIChatCompletion( + .AddOpenAIChatClient( modelId: TestConfiguration.OpenAI.ChatModelId, apiKey: TestConfiguration.OpenAI.ApiKey) .Build(); diff --git a/dotnet/samples/GettingStarted/Step4_Dependency_Injection.cs b/dotnet/samples/GettingStarted/Step4_Dependency_Injection.cs index 4ee22ba39261..11a819791342 100644 --- a/dotnet/samples/GettingStarted/Step4_Dependency_Injection.cs +++ b/dotnet/samples/GettingStarted/Step4_Dependency_Injection.cs @@ -38,7 +38,7 @@ public async Task GetKernelUsingDependencyInjection() [Fact] public async Task PluginUsingDependencyInjection() { - // If an application follows DI guidelines, the following line is unnecessary because DI will inject an instance of the KernelClient class to a class that references it. + // If an application follows DI guidelines, the following line is unnecessary because DI will inject an instance of the Kernel class to a class that references it. // DI container guidelines - https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-guidelines#recommendations var serviceProvider = BuildServiceProvider(); var kernel = serviceProvider.GetRequiredService(); @@ -57,8 +57,12 @@ private ServiceProvider BuildServiceProvider() collection.AddSingleton(new XunitLogger(this.Output)); collection.AddSingleton(new FakeUserService()); + // Add ChatClient using OpenAI + collection.AddOpenAIChatClient( + modelId: TestConfiguration.OpenAI.ChatModelId, + apiKey: TestConfiguration.OpenAI.ApiKey); + var kernelBuilder = collection.AddKernel(); - kernelBuilder.Services.AddOpenAIChatCompletion(TestConfiguration.OpenAI.ChatModelId, TestConfiguration.OpenAI.ApiKey); kernelBuilder.Plugins.AddFromType(); kernelBuilder.Plugins.AddFromType(); diff --git a/dotnet/samples/GettingStarted/Step5_Chat_Prompt.cs b/dotnet/samples/GettingStarted/Step5_Chat_Prompt.cs index dc7eb4206592..b4dd6c951f20 100644 --- a/dotnet/samples/GettingStarted/Step5_Chat_Prompt.cs +++ b/dotnet/samples/GettingStarted/Step5_Chat_Prompt.cs @@ -14,7 +14,7 @@ public async Task InvokeChatPrompt() { // Create a kernel with OpenAI chat completion Kernel kernel = Kernel.CreateBuilder() - .AddOpenAIChatCompletion( + .AddOpenAIChatClient( modelId: TestConfiguration.OpenAI.ChatModelId, apiKey: TestConfiguration.OpenAI.ApiKey) .Build(); diff --git a/dotnet/samples/GettingStarted/Step6_Responsible_AI.cs b/dotnet/samples/GettingStarted/Step6_Responsible_AI.cs index 255e9d2bc619..836732abd6c6 100644 --- a/dotnet/samples/GettingStarted/Step6_Responsible_AI.cs +++ b/dotnet/samples/GettingStarted/Step6_Responsible_AI.cs @@ -15,7 +15,7 @@ public async Task AddPromptFilter() { // Create a kernel with OpenAI chat completion var builder = Kernel.CreateBuilder() - .AddOpenAIChatCompletion( + .AddOpenAIChatClient( modelId: TestConfiguration.OpenAI.ChatModelId, apiKey: TestConfiguration.OpenAI.ApiKey); diff --git a/dotnet/samples/GettingStarted/Step7_Observability.cs b/dotnet/samples/GettingStarted/Step7_Observability.cs index 1504097cbbf6..765f7051421e 100644 --- a/dotnet/samples/GettingStarted/Step7_Observability.cs +++ b/dotnet/samples/GettingStarted/Step7_Observability.cs @@ -17,7 +17,7 @@ public async Task ObservabilityWithFilters() { // Create a kernel with OpenAI chat completion IKernelBuilder kernelBuilder = Kernel.CreateBuilder(); - kernelBuilder.AddOpenAIChatCompletion( + kernelBuilder.AddOpenAIChatClient( modelId: TestConfiguration.OpenAI.ChatModelId, apiKey: TestConfiguration.OpenAI.ApiKey); diff --git a/dotnet/samples/GettingStarted/Step8_Pipelining.cs b/dotnet/samples/GettingStarted/Step8_Pipelining.cs index 96f305c37a17..c136a21538e6 100644 --- a/dotnet/samples/GettingStarted/Step8_Pipelining.cs +++ b/dotnet/samples/GettingStarted/Step8_Pipelining.cs @@ -17,7 +17,7 @@ public sealed class Step8_Pipelining(ITestOutputHelper output) : BaseTest(output public async Task CreateFunctionPipeline() { IKernelBuilder builder = Kernel.CreateBuilder(); - builder.AddOpenAIChatCompletion( + builder.AddOpenAIChatClient( TestConfiguration.OpenAI.ChatModelId, TestConfiguration.OpenAI.ApiKey); builder.Services.AddLogging(c => c.AddConsole().SetMinimumLevel(LogLevel.Trace)); diff --git a/dotnet/samples/GettingStarted/Step9_OpenAPI_Plugins.cs b/dotnet/samples/GettingStarted/Step9_OpenAPI_Plugins.cs index 5bff73bab0ca..15d500af582a 100644 --- a/dotnet/samples/GettingStarted/Step9_OpenAPI_Plugins.cs +++ b/dotnet/samples/GettingStarted/Step9_OpenAPI_Plugins.cs @@ -19,7 +19,7 @@ public async Task AddOpenAPIPlugins() { // Create a kernel with OpenAI chat completion IKernelBuilder kernelBuilder = Kernel.CreateBuilder(); - kernelBuilder.AddOpenAIChatCompletion( + kernelBuilder.AddOpenAIChatClient( modelId: TestConfiguration.OpenAI.ChatModelId, apiKey: TestConfiguration.OpenAI.ApiKey); Kernel kernel = kernelBuilder.Build(); @@ -33,12 +33,12 @@ public async Task AddOpenAPIPlugins() } /// - /// Shows how to transform an Open API instance to support dependency injection. + /// Shows how to transform an Open API instance to support dependency injection with ChatClient. /// [Fact] public async Task TransformOpenAPIPlugins() { - // Create a kernel with OpenAI chat completion + // Create a kernel with ChatClient and dependency injection var serviceProvider = BuildServiceProvider(); var kernel = serviceProvider.GetRequiredService(); @@ -61,8 +61,12 @@ private ServiceProvider BuildServiceProvider() var collection = new ServiceCollection(); collection.AddSingleton(new FakeMechanicService()); + // Add ChatClient using OpenAI + collection.AddOpenAIChatClient( + modelId: TestConfiguration.OpenAI.ChatModelId, + apiKey: TestConfiguration.OpenAI.ApiKey); + var kernelBuilder = collection.AddKernel(); - kernelBuilder.Services.AddOpenAIChatCompletion(TestConfiguration.OpenAI.ChatModelId, TestConfiguration.OpenAI.ApiKey); return collection.BuildServiceProvider(); }