Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the console starter to use the newest version of semantic kernel #98

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions sk-csharp-console-chat/ConsoleChat.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// This is the main application service.
Expand Down Expand Up @@ -51,12 +51,13 @@ private async Task ExecuteAsync(CancellationToken cancellationToken)
// Get the chat completions
OpenAIPromptExecutionSettings openAIPromptExecutionSettings = new()
{
FunctionCallBehavior = FunctionCallBehavior.AutoInvokeKernelFunctions
ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions
};

IAsyncEnumerable<StreamingChatMessageContent> result =
chatCompletionService.GetStreamingChatMessageContentsAsync(
chatMessages,
executionSettings: openAIPromptExecutionSettings,
openAIPromptExecutionSettings,
kernel: this._kernel,
cancellationToken: cancellationToken);

Expand All @@ -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 ?? "");
}
}
}
}
2 changes: 1 addition & 1 deletion sk-csharp-console-chat/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
services
.AddSingleton<KernelSettings>(kernelSettings)
.AddTransient<Kernel>(serviceProvider => {
KernelBuilder builder = new();
IKernelBuilder builder = Kernel.CreateBuilder();
builder.Services.AddLogging(c => c.AddDebug().SetMinimumLevel(LogLevel.Information));
builder.Services.AddChatCompletionService(kernelSettings);
builder.Plugins.AddFromType<LightPlugin>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion sk-csharp-console-chat/plugins/LightPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.AI.ChatCompletion;
using Microsoft.SemanticKernel.ChatCompletion;

namespace Plugins;

Expand Down
2 changes: 1 addition & 1 deletion sk-csharp-console-chat/sk-csharp-console-chat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.0.0" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.0.0-rc3" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading