From 5444dff4cb4ee5d03c1e83f60a99c7ad3b9c86f2 Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Date: Wed, 16 Jul 2025 18:46:01 +0000
Subject: [PATCH 1/3] Update getting started samples with ChatClient
---
dotnet/global.json | 2 +-
.../GettingStarted/Step1_Create_Kernel.cs | 8 ++++----
.../GettingStarted/Step2_Add_Plugins.cs | 18 +++++++++---------
.../GettingStarted/Step3_Yaml_Prompt.cs | 2 +-
.../Step4_Dependency_Injection.cs | 8 ++++++--
.../GettingStarted/Step5_Chat_Prompt.cs | 2 +-
.../GettingStarted/Step6_Responsible_AI.cs | 2 +-
.../GettingStarted/Step7_Observability.cs | 4 ++--
.../samples/GettingStarted/Step8_Pipelining.cs | 2 +-
.../GettingStarted/Step9_OpenAPI_Plugins.cs | 12 ++++++++----
10 files changed, 34 insertions(+), 26 deletions(-)
diff --git a/dotnet/global.json b/dotnet/global.json
index e00bec377198..97e9c819809c 100644
--- a/dotnet/global.json
+++ b/dotnet/global.json
@@ -1,6 +1,6 @@
{
"sdk": {
- "version": "9.0.300",
+ "version": "9.0.203",
"rollForward": "latestMajor",
"allowPrerelease": false
}
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..7040aca1a50a 100644
--- a/dotnet/samples/GettingStarted/Step2_Add_Plugins.cs
+++ b/dotnet/samples/GettingStarted/Step2_Add_Plugins.cs
@@ -9,21 +9,21 @@
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();
@@ -31,14 +31,14 @@ public async Task AddPlugins()
// Example 1. Invoke the kernel with a prompt that asks the AI for information it cannot provide and may hallucinate
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(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(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(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..aac0a317ce53 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);
@@ -54,7 +54,7 @@ private sealed class MyFunctionFilter(ITestOutputHelper output) : IFunctionInvoc
{
private readonly ITestOutputHelper _output = output;
- public async Task OnFunctionInvocationAsync(FunctionInvocationContext context, Func next)
+ public async Task OnFunctionInvocationAsync(Microsoft.SemanticKernel.FunctionInvocationContext context, Func next)
{
this._output.WriteLine($"Invoking {context.Function.Name}");
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();
}
From a7c0c2747c06ee1e478e7162a80b81cb3dca840a Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Date: Thu, 17 Jul 2025 14:37:46 +0100
Subject: [PATCH 2/3] Address minor stuff
---
dotnet/samples/GettingStarted/Step2_Add_Plugins.cs | 4 ++++
dotnet/samples/GettingStarted/Step7_Observability.cs | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/dotnet/samples/GettingStarted/Step2_Add_Plugins.cs b/dotnet/samples/GettingStarted/Step2_Add_Plugins.cs
index 7040aca1a50a..5b233f734b2f 100644
--- a/dotnet/samples/GettingStarted/Step2_Add_Plugins.cs
+++ b/dotnet/samples/GettingStarted/Step2_Add_Plugins.cs
@@ -29,16 +29,20 @@ public async Task AddPlugins()
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. 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. 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. 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/Step7_Observability.cs b/dotnet/samples/GettingStarted/Step7_Observability.cs
index aac0a317ce53..765f7051421e 100644
--- a/dotnet/samples/GettingStarted/Step7_Observability.cs
+++ b/dotnet/samples/GettingStarted/Step7_Observability.cs
@@ -54,7 +54,7 @@ private sealed class MyFunctionFilter(ITestOutputHelper output) : IFunctionInvoc
{
private readonly ITestOutputHelper _output = output;
- public async Task OnFunctionInvocationAsync(Microsoft.SemanticKernel.FunctionInvocationContext context, Func next)
+ public async Task OnFunctionInvocationAsync(FunctionInvocationContext context, Func next)
{
this._output.WriteLine($"Invoking {context.Function.Name}");
From 2a959e2240cf97aff6f15324001082b6d5412566 Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Date: Thu, 17 Jul 2025 14:39:45 +0100
Subject: [PATCH 3/3] Revert global.json change
---
dotnet/global.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dotnet/global.json b/dotnet/global.json
index 97e9c819809c..e00bec377198 100644
--- a/dotnet/global.json
+++ b/dotnet/global.json
@@ -1,6 +1,6 @@
{
"sdk": {
- "version": "9.0.203",
+ "version": "9.0.300",
"rollForward": "latestMajor",
"allowPrerelease": false
}