diff --git a/sk-csharp-console-chat/ConsoleChat.cs b/sk-csharp-console-chat/ConsoleChat.cs index 22230dd..3aca8a4 100644 --- a/sk-csharp-console-chat/ConsoleChat.cs +++ b/sk-csharp-console-chat/ConsoleChat.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.SemanticKernel; -using Microsoft.SemanticKernel.AI.ChatCompletion; -using Microsoft.SemanticKernel.Connectors.AI.OpenAI; +using Microsoft.SemanticKernel.ChatCompletion; +using Microsoft.SemanticKernel.Connectors.OpenAI; /// /// This is the main application service. @@ -51,12 +51,13 @@ private async Task ExecuteAsync(CancellationToken cancellationToken) // Get the chat completions OpenAIPromptExecutionSettings openAIPromptExecutionSettings = new() { - FunctionCallBehavior = FunctionCallBehavior.AutoInvokeKernelFunctions + ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions }; + IAsyncEnumerable result = chatCompletionService.GetStreamingChatMessageContentsAsync( chatMessages, - executionSettings: openAIPromptExecutionSettings, + openAIPromptExecutionSettings, kernel: this._kernel, cancellationToken: cancellationToken); @@ -69,18 +70,26 @@ private async Task ExecuteAsync(CancellationToken cancellationToken) System.Console.Write("Assistant > "); chatMessageContent = new( content.Role ?? AuthorRole.Assistant, - content.ModelId!, content.Content!, + content.ModelId!, content.InnerContent, content.Encoding, content.Metadata ); } + if (content.Content is null) + { + continue; + } System.Console.Write(content.Content); chatMessageContent!.Content += content.Content; + } System.Console.WriteLine(); - chatMessages.AddMessage(chatMessageContent!); + if (chatMessageContent is not null && chatMessageContent.Content is not null) + { + chatMessages.AddAssistantMessage(chatMessageContent!.Content ?? ""); + } } } } diff --git a/sk-csharp-console-chat/Program.cs b/sk-csharp-console-chat/Program.cs index 7adc070..b3209ad 100644 --- a/sk-csharp-console-chat/Program.cs +++ b/sk-csharp-console-chat/Program.cs @@ -26,7 +26,7 @@ services .AddSingleton(kernelSettings) .AddTransient(serviceProvider => { - KernelBuilder builder = new(); + IKernelBuilder builder = Kernel.CreateBuilder(); builder.Services.AddLogging(c => c.AddDebug().SetMinimumLevel(LogLevel.Information)); builder.Services.AddChatCompletionService(kernelSettings); builder.Plugins.AddFromType(); diff --git a/sk-csharp-console-chat/config/ServiceCollectionExtensions.cs b/sk-csharp-console-chat/config/ServiceCollectionExtensions.cs index 50172a0..7e14570 100644 --- a/sk-csharp-console-chat/config/ServiceCollectionExtensions.cs +++ b/sk-csharp-console-chat/config/ServiceCollectionExtensions.cs @@ -14,7 +14,7 @@ internal static IServiceCollection AddChatCompletionService(this IServiceCollect switch (kernelSettings.ServiceType.ToUpperInvariant()) { case ServiceTypes.AzureOpenAI: - serviceCollection = serviceCollection.AddAzureOpenAIChatCompletion(kernelSettings.DeploymentId, kernelSettings.ModelId, endpoint: kernelSettings.Endpoint, apiKey: kernelSettings.ApiKey, serviceId: kernelSettings.ServiceId); + serviceCollection = serviceCollection.AddAzureOpenAIChatCompletion(kernelSettings.DeploymentId, endpoint: kernelSettings.Endpoint, apiKey: kernelSettings.ApiKey, serviceId: kernelSettings.ServiceId); break; case ServiceTypes.OpenAI: diff --git a/sk-csharp-console-chat/plugins/LightPlugin.cs b/sk-csharp-console-chat/plugins/LightPlugin.cs index dccacff..5da2d54 100644 --- a/sk-csharp-console-chat/plugins/LightPlugin.cs +++ b/sk-csharp-console-chat/plugins/LightPlugin.cs @@ -1,6 +1,6 @@ using System.ComponentModel; using Microsoft.SemanticKernel; -using Microsoft.SemanticKernel.AI.ChatCompletion; +using Microsoft.SemanticKernel.ChatCompletion; namespace Plugins; diff --git a/sk-csharp-console-chat/sk-csharp-console-chat.csproj b/sk-csharp-console-chat/sk-csharp-console-chat.csproj index 1f47ae9..69e77d5 100644 --- a/sk-csharp-console-chat/sk-csharp-console-chat.csproj +++ b/sk-csharp-console-chat/sk-csharp-console-chat.csproj @@ -13,7 +13,7 @@ - +