Skip to content

Commit

Permalink
Upgrade to Microsoft.SemanticKernel v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Feb 6, 2024
1 parent 7eaa9b5 commit daffe0d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
7 changes: 0 additions & 7 deletions NuGet.Config

This file was deleted.

25 changes: 21 additions & 4 deletions TypeChatExamples.Tests/GptTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<ITypeChat>(c => new KernelTypeChat(c.Resolve<IKernel>()));
services.AddSingleton<ITypeChat>(c => new KernelTypeChat(c.Resolve<Kernel>()));
services.AddSingleton<CoffeeShopPromptProvider>();
services.AddSingleton<SentimentPromptProvider>();
services.AddSingleton<CalendarPromptProvider>();
Expand Down Expand Up @@ -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<SentimentPromptProvider>();
var prompt = await service.CreatePromptAsync("i wanna latte macchiato with vanilla");
prompt.Print();
var typeChat = appHost.Resolve<ITypeChat>();
var response = await typeChat.TranslateMessageAsync(new TypeChatRequest(null, prompt, null));

"Response:".Print();
response.PrintDump();
}

[Test]
public async Task Execute_Raw_Prompt()
{
Expand All @@ -124,7 +142,6 @@ export interface Syrups {
",
});


var dto = new Dictionary<string, object>
{
["model"] = "gpt-3.5-turbo",
Expand Down
1 change: 1 addition & 0 deletions TypeChatExamples.Tests/TypeChatExamples.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<PackageReference Include="ServiceStack.Kestrel" Version="8.*" />
<PackageReference Include="Google.Cloud.Storage.V1" Version="4.7.0" />
<PackageReference Include="Google.Cloud.Speech.V2" Version="1.0.0-beta07" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.3.0" />

<PackageReference Include="AWSSDK.Core" Version="3.7.*" />
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.*" />
Expand Down
5 changes: 3 additions & 2 deletions TypeChatExamples/Configure.Gpt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ public void Configure(IWebHostBuilder builder) => builder
var gptProvider = context.Configuration.GetValue<string>("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<ITypeChat>(c => new KernelTypeChat(c.GetRequiredService<IKernel>()));
services.AddSingleton<ITypeChat>(c => new KernelTypeChat(c.GetRequiredService<Kernel>()));
}
else if (gptProvider == nameof(NodeTypeChat))
{
Expand Down
4 changes: 2 additions & 2 deletions TypeChatExamples/TypeChatExamples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
<PackageReference Include="ServiceStack.Azure" Version="8.*" />
<PackageReference Include="Google.Cloud.Storage.V1" Version="4.7.0" />
<PackageReference Include="Google.Cloud.Speech.V2" Version="1.0.0-beta07" />
<PackageReference Include="Microsoft.CognitiveServices.Speech" Version="1.33.0" />
<PackageReference Include="Microsoft.CognitiveServices.Speech" Version="1.35.0" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.3.0" />

<!-- Required for Razor compilation on change: https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-5.0 -->
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.*" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.0.0-beta6" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit daffe0d

Please sign in to comment.