Skip to content

Commit

Permalink
Merge pull request #43 from Encamina/@rliberoff/update_semantic_kerne…
Browse files Browse the repository at this point in the history
…l_1.0.1

@rliberoff/update semantic kernel ~1.0.1~ 1.1.0
  • Loading branch information
rliberoff authored Jan 18, 2024
2 parents c7858e5 + 19e086a commit b885080
Show file tree
Hide file tree
Showing 84 changed files with 1,278 additions and 633 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ on:
workflow_dispatch:

env:
BuildConfiguration: ${{ startsWith(github.ref, 'refs/heads/releases') && 'Release' || 'Debug' }}
BuildConfiguration: ${{ (startsWith(github.ref, 'refs/heads/releases') || startsWith(github.ref, 'refs/main')) && 'Release' || 'Debug' }}

jobs:
CI:
Expand All @@ -29,6 +29,12 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set Java for SonarCloud
uses: actions/setup-java@v4
with:
distribution: 'microsoft'
java-version: '21'

- name: Using .NET from 'global.json'
uses: actions/setup-dotnet@v3
Expand All @@ -39,7 +45,7 @@ jobs:
run: dotnet restore --configfile NuGet.config --verbosity Minimal

- name: Sonar - Install SonarCloud scanners
run: dotnet tool install --global dotnet-sonarscanner --version 5.15.0
run: dotnet tool install --global dotnet-sonarscanner --version 6.0.0

- name: Sonar - Begin Analyze
env:
Expand Down
82 changes: 80 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,97 @@ Also, any bug fix must start with the prefix �Bug fix:� followed by the desc

Previous classification is not required if changes are simple or all belong to the same category.

## [8.1.0]

### Important

This version updates the `Semantic Kernel` library from version `1.0.0-beta8` to `1.1.0`, which introduces a lot of breaking changes in the code.

Sadly, some features from `Semantic Kernel` that we might have been using, are marked as ***experimental*** and produce warnings that do not allow the compilation of the code. To use these features, these warnings must be ignored explicitly per project. The following is a list of these warnings and the affected projects:

- SKEXP0001:
- `Encamina.Enmarcha.SemanticKernel`
- SKEXP0003:
- `Encamina.Enmarcha.SemanticKernel`
- `Encamina.Enmarcha.SemanticKernel.Abstractions`
- `Encamina.Enmarcha.SemanticKernel.Connectors.Memory`
- `Encamina.Enmarcha.SemanticKernel.Plugins.Memory`
- `Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering`
- SKEXP0011:
- `Encamina.Enmarcha.SemanticKernel.Connectors.Memory`
- SKEXP0026:
- `Encamina.Enmarcha.SemanticKernel.Connectors.Memory`
- SKEXP0051:
- `Encamina.Enmarcha.SemanticKernel.Connectors.Document`

More information about these warnings is available here: https://github.com/microsoft/semantic-kernel/blob/main/dotnet/docs/EXPERIMENTS.md

### Braking Changes

- Replaced class `Completition` for `Completion` in `Encamina.Enmarcha.AI.OpenAI.Abstractions`. It was misspelled.
- Class `SemanticKernelOptions` does not exists anymore. It has been replaced by `AzureOpenAIOptions` from `Encamina.Enmarcha.AI.OpenAI.Abstractions`.
- The following references were updated due to changes in `Semantic Kernel` version `1.0.1`:
- Changed `IKernel` for `Kernel`.
- Changed `ISKFunction` for `KernelFunction` or `KernelPlugin`.
- Changed `SKFunction` for `KernelFunction`.
- Changed `ContextVariables` for `KernelArguments`.
- Changed `kernel.Functions.GetFunction(...)` for `kernel.Plugins[<name of plugin>][<name of function>]`.
- Changed `OpenAIRequestSettings` for `OpenAIPromptExecutionSettings`.
- Removed extension methods for `SKContext` because that class does not exists anymore in `Semantic Kernel`.
- Due to the breaking nature of the new version of `Semantic Kernel`, the following extension methods are not available any more and have been replace by new methods, and it was not possible to marked it as `Obsolete`:
- `GetSemanticFunctionPromptAsync` is replaced by `GetKernelFunctionPromptAsync`.
- `GetSemanticFunctionUsedTokensAsync` is replaced by `GetKernelFunctionUsedTokensAsync`.
- `ImportSemanticPluginsFromAssembly` is replaced by `ImportPromptFunctionsFromAssembly`.
- Extension method `GetSemanticFunctionPromptAsync` is no longer available. It is replaced by `GetKernelFunctionPromptAsync`.
- Extension method `ImportQuestionAnsweringPlugin` has different signature.
- Extension method `ImportQuestionAnsweringPluginWithMemory` has different signature.
- Extension method `ImportChatWithHistoryPluginUsingCosmosDb` has different signature.
- The format of prompt function configuration files `config.json` has been modified.

### Major Changes

- Updated `Semantic Kernel` from `1.0.0-beta8` to `1.1.0` (second final version of `Semantic Kernel`).
- Updated `Azure.Core` from version `1.36.0` to `1.37.0`.
- Updated `Azure.AI.OpenAI` from version `1.0.0-beta.6` to `1.0.0-beta.12`.
- Updated `Bogus` from version `34.0.2` to `35.4.0`.
- Updated `Microsoft.AspNetCore.Authentication.JwtBearer` from version `8.0.0` to `8.0.1`.
- Updated `Microsoft.AspNetCore.Authentication.OpenIdConnect` from version `8.0.0` to `8.0.1`.
- Updated `Microsoft.Azure.Cosmos` from version `3.37.0` to `3.37.1`.
- Updated `Microsoft.EntityFrameworkCore` from version `8.0.0` to `8.0.1`.
- Updated `Microsoft.Extensions.Options` from version `8.0.0` to `8.0.1`.
- Updated `SharpToken` from version `1.2.12` to `1.2.14`.
- Updated `xunit` from version `2.6.2` to `2.6.6`.
- Updated `xunit.analyzers` from version `1.6.0` to `1.10.0`.
- Updated `xunit.extensibility.core` from version `2.6.2` to `2.6.6`.
- Updated `xunit.runner.visualstudio` from version `2.5.4` to `2.5.6`.
- Updated `StyleCop.Analyzers` from version `1.2.0-beta.507` to `1.2.0-beta.556`.
- Updated `System.Text.Json` from version `8.0.0` to `8.0.1`.
- Updated version from `8.0.3` to `8.1.0` due to all the major and breaking changes.
- Updated some `README.md` files changing `IKernel` for `Kernel`.
- Updated and added new unit tests to cover the main "happy path" of implementations that use `Semantic Kernel`.

### Minor Changes

- Replaced reference `Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer` (version `5.1.0`) for `Asp.Versioning.Mvc.ApiExplorer` (version `8.0.0`) which is the new name and implementation of the ASP.NET versioning libraries.
- Updated prompt function configuration files (`config.json`) to new format.
- Renamed files `IKernelExtensions` to `KernelExtensions.cs`.
- Fixed token counting in `ChatWithHistoryPlugin.cs`.
- Updated sample projects.
- Fixed some typos and grammatical errors.

## [8.0.3]

### Minor Changes
- Add gpt-35-turbo-16k and gpt-3.5-turbo-16k model implementation allowed

## [8.0.2]

### **Major Changes**
### Major Changes
- In `Encamina.Enmarcha.SemanticKernel.Plugins.Text` Summarize Plugin, a new parameter `locale` has been added to control the output language of the generated summary. [(#34)](https://github.com/Encamina/enmarcha/issues/34)

## [8.0.1]

### **Major Changes**
### Major Changes
- In `Encamina.Enmarcha.SemanticKernel.Abstractions.ILengthFunctions`, `GptEncoding` is now cached and reused to improve performance. [(#30)](https://github.com/Encamina/enmarcha/pull/30)

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>8.0.3</VersionPrefix>
<VersionPrefix>8.1.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Diagnostics" Version="8.2.2" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
7 changes: 7 additions & 0 deletions Enmarcha.sln
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Encamina.Enmarcha.Samples.S
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Encamina.Enmarcha.Samples.SemanticKernel.QuestionAnswering", "samples\SemanticKernel\Encamina.Enmarcha.Samples.SemanticKernel.QuestionAnswering\Encamina.Enmarcha.Samples.SemanticKernel.QuestionAnswering.csproj", "{AA1E5E93-FE02-4395-9260-C7C869F22785}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Encamina.Enmarcha.SemanticKernel.Tests", "tst\Encamina.Enmarcha.SemanticKernel.Tests\Encamina.Enmarcha.SemanticKernel.Tests.csproj", "{7B6F4DC4-74E2-4013-8DBA-12B7AAAD5278}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -346,6 +348,10 @@ Global
{AA1E5E93-FE02-4395-9260-C7C869F22785}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA1E5E93-FE02-4395-9260-C7C869F22785}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA1E5E93-FE02-4395-9260-C7C869F22785}.Release|Any CPU.Build.0 = Release|Any CPU
{7B6F4DC4-74E2-4013-8DBA-12B7AAAD5278}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B6F4DC4-74E2-4013-8DBA-12B7AAAD5278}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B6F4DC4-74E2-4013-8DBA-12B7AAAD5278}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B6F4DC4-74E2-4013-8DBA-12B7AAAD5278}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -361,6 +367,7 @@ Global
{BF6C4DFC-3CB3-4C62-8B86-08C0C1537CBC} = {B9E33951-E387-4A80-A652-A908FCBB34F3}
{9E8B3AEE-AC1C-4F46-A8D2-3EF550F64005} = {43252034-27E2-4981-AC2D-EA986B287863}
{AA1E5E93-FE02-4395-9260-C7C869F22785} = {43252034-27E2-4981-AC2D-EA986B287863}
{7B6F4DC4-74E2-4013-8DBA-12B7AAAD5278} = {CBD50B5F-AFB8-4DA1-9FD7-17D98EB3ED78}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F30DF47A-541C-4383-BCEB-E4108D06A70E}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -7,7 +7,20 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;SKEXP0003;SKEXP0011;SKEXP0052;</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>1701;1702;SKEXP0003;SKEXP0011;SKEXP0052;</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SemanticKernel.Plugins.Memory" Version="1.1.0-alpha" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Encamina.Enmarcha.AI.OpenAI.Azure\Encamina.Enmarcha.AI.OpenAI.Azure.csproj" />
<ProjectReference Include="..\..\..\src\Encamina.Enmarcha.SemanticKernel.Connectors.Memory\Encamina.Enmarcha.SemanticKernel.Connectors.Memory.csproj" />
<ProjectReference Include="..\..\..\src\Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering\Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Encamina.Enmarcha.Samples.SemanticKernel.QuestionAnswering;
using Encamina.Enmarcha.AI.OpenAI.Azure;
using Encamina.Enmarcha.SemanticKernel.Abstractions;
using Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering;

Expand All @@ -14,7 +14,7 @@ internal static class ExampleQuestionAnsweringFromContext
{
public static async Task RunAsync()
{
Console.WriteLine("# Executing Example_QuestionAnsweringFromContext");
Console.WriteLine(@"# Executing Example_QuestionAnsweringFromContext");

// Create and configure builder
var hostBuilder = new HostBuilder()
Expand All @@ -27,21 +27,21 @@ public static async Task RunAsync()
hostBuilder.ConfigureServices((hostContext, services) =>
{
// Add Semantic Kernel options
services.AddOptions<SemanticKernelOptions>().Bind(hostContext.Configuration.GetSection(nameof(SemanticKernelOptions))).ValidateDataAnnotations().ValidateOnStart();
services.AddOptions<AzureOpenAIOptions>().Bind(hostContext.Configuration.GetSection(nameof(AzureOpenAIOptions))).ValidateDataAnnotations().ValidateOnStart();

services.AddScoped(sp =>
{
// Get semantic kernel options
var options = hostContext.Configuration.GetRequiredSection(nameof(SemanticKernelOptions)).Get<SemanticKernelOptions>()
?? throw new InvalidOperationException(@$"Missing configuration for {nameof(SemanticKernelOptions)}");
var options = hostContext.Configuration.GetRequiredSection(nameof(AzureOpenAIOptions)).Get<AzureOpenAIOptions>()
?? throw new InvalidOperationException(@$"Missing configuration for {nameof(AzureOpenAIOptions)}");

// Initialize semantic kernel
var kernel = new KernelBuilder()
.WithAzureOpenAIChatCompletionService(options.ChatModelDeploymentName, options.Endpoint.ToString(), options.Key)
var kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(options.ChatModelDeploymentName, options.Endpoint.ToString(), options.Key)
.Build();

// Import Question Answering plugin
kernel.ImportQuestionAnsweringPlugin(sp, ILengthFunctions.LengthByTokenCount);
kernel.ImportQuestionAnsweringPlugin(options, ILengthFunctions.LengthByTokenCount);

return kernel;
});
Expand All @@ -50,7 +50,7 @@ public static async Task RunAsync()
var host = hostBuilder.Build();

// Initialize Q&A
var testQuestionAnswering = new TestQuestionAnswering(host.Services.GetRequiredService<IKernel>());
var testQuestionAnswering = new TestQuestionAnswering(host.Services.GetRequiredService<Kernel>());

var result = await testQuestionAnswering.TestQuestionAnsweringFromContextAsync();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Encamina.Enmarcha.SemanticKernel.Abstractions;
using Encamina.Enmarcha.AI.OpenAI.Azure;
using Encamina.Enmarcha.SemanticKernel.Abstractions;
using Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering;

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.AI.OpenAI;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Plugins.Memory;

namespace Encamina.Enmarcha.Samples.SemanticKernel.QuestionAnswering;

Expand All @@ -29,26 +28,26 @@ public static async Task RunAsync()
hostBuilder.ConfigureServices((hostContext, services) =>
{
// Get semantic kernel options
var options = hostContext.Configuration.GetRequiredSection(nameof(SemanticKernelOptions)).Get<SemanticKernelOptions>()
?? throw new InvalidOperationException(@$"Missing configuration for {nameof(SemanticKernelOptions)}");
var options = hostContext.Configuration.GetRequiredSection(nameof(AzureOpenAIOptions)).Get<AzureOpenAIOptions>()
?? throw new InvalidOperationException(@$"Missing configuration for {nameof(AzureOpenAIOptions)}");

// Add Semantic Kernel options
services.AddOptions<SemanticKernelOptions>().Bind(hostContext.Configuration.GetSection(nameof(SemanticKernelOptions))).ValidateDataAnnotations().ValidateOnStart();
services.AddOptions<AzureOpenAIOptions>().Bind(hostContext.Configuration.GetSection(nameof(AzureOpenAIOptions))).ValidateDataAnnotations().ValidateOnStart();

// Here use any desired implementation (Qdrant, Volatile...)
services.AddSingleton<IMemoryStore, VolatileMemoryStore>()
.AddSemanticTextMemory();
.AddSemanticTextMemory();

services.AddScoped(sp =>
{
// Initialize semantic kernel
var kernel = new KernelBuilder()
.WithAzureOpenAIChatCompletionService(options.ChatModelDeploymentName, options.Endpoint.ToString(), options.Key)
.WithAzureOpenAITextEmbeddingGenerationService(options.EmbeddingsModelDeploymentName, options.Endpoint.ToString(), options.Key)
var kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(options.ChatModelDeploymentName, options.Endpoint.ToString(), options.Key)
.AddAzureOpenAITextEmbeddingGeneration(options.EmbeddingsModelDeploymentName, options.Endpoint.ToString(), options.Key)
.Build();

// Import Question Answering plugin
kernel.ImportQuestionAnsweringPluginWithMemory(sp, ILengthFunctions.LengthByTokenCount);
kernel.ImportQuestionAnsweringPluginWithMemory(options, sp.GetRequiredService<ISemanticTextMemory>(), ILengthFunctions.LengthByTokenCount);

return kernel;
});
Expand All @@ -64,7 +63,7 @@ public static async Task RunAsync()
await mockMemoryInformation.SaveDataMockAsync();

// Initialize Q&A from Memory
var testQuestionAnswering = new TestQuestionAnswering(host.Services.GetService<IKernel>());
var testQuestionAnswering = new TestQuestionAnswering(host.Services.GetService<Kernel>());
var result = await testQuestionAnswering.TestQuestionAnsweringFromMemoryAsync();

Console.WriteLine($@"RESULT: {result}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

internal static class Program
{
private static async Task Main(string[] args)
private static async Task Main(string[] _)
{
await ExampleQuestionAnsweringFromContext.RunAsync();
await ExampleQuestionAnsweringFromMemory.RunAsync();
Expand Down
Loading

0 comments on commit b885080

Please sign in to comment.