From daffe0d829d4c78d7894ee3f6382a1210ca3456c Mon Sep 17 00:00:00 2001 From: Demis Bellot Date: Tue, 6 Feb 2024 14:06:53 +0800 Subject: [PATCH] Upgrade to Microsoft.SemanticKernel v1.3.0 --- NuGet.Config | 7 ------ TypeChatExamples.Tests/GptTests.cs | 25 ++++++++++++++++--- .../TypeChatExamples.Tests.csproj | 1 + TypeChatExamples/Configure.Gpt.cs | 5 ++-- TypeChatExamples/TypeChatExamples.csproj | 4 +-- 5 files changed, 27 insertions(+), 15 deletions(-) delete mode 100644 NuGet.Config diff --git a/NuGet.Config b/NuGet.Config deleted file mode 100644 index c00d271..0000000 --- a/NuGet.Config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/TypeChatExamples.Tests/GptTests.cs b/TypeChatExamples.Tests/GptTests.cs index 1c90a4d..5ab020e 100644 --- a/TypeChatExamples.Tests/GptTests.cs +++ b/TypeChatExamples.Tests/GptTests.cs @@ -34,6 +34,10 @@ private ServiceStackHost CreateAppHost() GptPath = Path.GetFullPath("gpt/coffeeshop"), RecognizerId = "coffeeshop-recognizer", PhraseSetId = "coffeeshop-phrases", + }, + Sentiment = new() + { + GptPath = Path.GetFullPath("gpt/sentiment"), } }; host.Register(appConfig); @@ -45,15 +49,15 @@ private ServiceStackHost CreateAppHost() host.LoadPlugin(new AutoQueryFeature()); - var kernel = Kernel.Builder - .WithOpenAIChatCompletionService( + var kernel = Kernel.CreateBuilder() + .AddOpenAIChatCompletion( Environment.GetEnvironmentVariable("OPENAI_MODEL")!, Environment.GetEnvironmentVariable("OPENAI_API_KEY")!) .Build(); host.Register(kernel); var services = host.Container; - services.AddSingleton(c => new KernelTypeChat(c.Resolve())); + services.AddSingleton(c => new KernelTypeChat(c.Resolve())); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); @@ -98,6 +102,20 @@ public async Task Dump_all_phrases() response.Results.PrintDump(); } + [Test] + public async Task Execute_semantic_kernel_prompt() + { + using var appHost = CreateAppHost(); + var service = appHost.Resolve(); + var prompt = await service.CreatePromptAsync("i wanna latte macchiato with vanilla"); + prompt.Print(); + var typeChat = appHost.Resolve(); + var response = await typeChat.TranslateMessageAsync(new TypeChatRequest(null, prompt, null)); + + "Response:".Print(); + response.PrintDump(); + } + [Test] public async Task Execute_Raw_Prompt() { @@ -124,7 +142,6 @@ export interface Syrups { ", }); - var dto = new Dictionary { ["model"] = "gpt-3.5-turbo", diff --git a/TypeChatExamples.Tests/TypeChatExamples.Tests.csproj b/TypeChatExamples.Tests/TypeChatExamples.Tests.csproj index 242c74d..1b4e012 100644 --- a/TypeChatExamples.Tests/TypeChatExamples.Tests.csproj +++ b/TypeChatExamples.Tests/TypeChatExamples.Tests.csproj @@ -20,6 +20,7 @@ + diff --git a/TypeChatExamples/Configure.Gpt.cs b/TypeChatExamples/Configure.Gpt.cs index cad92ea..4afbebc 100644 --- a/TypeChatExamples/Configure.Gpt.cs +++ b/TypeChatExamples/Configure.Gpt.cs @@ -33,12 +33,13 @@ public void Configure(IWebHostBuilder builder) => builder var gptProvider = context.Configuration.GetValue("TypeChatProvider"); if (gptProvider == nameof(KernelTypeChat)) { - var kernel = new KernelBuilder().WithOpenAIChatCompletionService( + var kernel = Kernel.CreateBuilder() + .AddOpenAIChatCompletion( Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-3.5-turbo", Environment.GetEnvironmentVariable("OPENAI_API_KEY")!) .Build(); services.AddSingleton(kernel); - services.AddSingleton(c => new KernelTypeChat(c.GetRequiredService())); + services.AddSingleton(c => new KernelTypeChat(c.GetRequiredService())); } else if (gptProvider == nameof(NodeTypeChat)) { diff --git a/TypeChatExamples/TypeChatExamples.csproj b/TypeChatExamples/TypeChatExamples.csproj index e5c1fba..41163af 100644 --- a/TypeChatExamples/TypeChatExamples.csproj +++ b/TypeChatExamples/TypeChatExamples.csproj @@ -34,11 +34,11 @@ - + + -