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

Add C# simple planner #598

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions dotnet/SK-dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SemanticKernel.MetaPackage"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImportDocument", "..\samples\apps\copilot-chat-app\importdocument\ImportDocument.csproj", "{94E14913-D600-4448-A5C5-A268C23B2C3B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Planning.ActionPlanner", "src\Extensions\Planning.ActionPlanner\Planning.ActionPlanner.csproj", "{994BEF0B-E277-4D10-BB13-FE670D26620D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "extensions", "extensions", "{078F96B4-09E1-4E0E-B214-F71A4F4BF633}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Extensions.UnitTests", "src\Extensions\Extensions.UnitTests\Extensions.UnitTests.csproj", "{F51017A9-15C8-472D-893C-080046D710A6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Planning.SequentialPlanner", "src\Extensions\Planning.SequentialPlanner\Planning.SequentialPlanner.csproj", "{A350933D-F9D5-4AD3-8C4F-B856B5020297}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -177,6 +185,18 @@ Global
{94E14913-D600-4448-A5C5-A268C23B2C3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94E14913-D600-4448-A5C5-A268C23B2C3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94E14913-D600-4448-A5C5-A268C23B2C3B}.Release|Any CPU.Build.0 = Release|Any CPU
{994BEF0B-E277-4D10-BB13-FE670D26620D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{994BEF0B-E277-4D10-BB13-FE670D26620D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{994BEF0B-E277-4D10-BB13-FE670D26620D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{994BEF0B-E277-4D10-BB13-FE670D26620D}.Release|Any CPU.Build.0 = Release|Any CPU
{F51017A9-15C8-472D-893C-080046D710A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F51017A9-15C8-472D-893C-080046D710A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F51017A9-15C8-472D-893C-080046D710A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F51017A9-15C8-472D-893C-080046D710A6}.Release|Any CPU.Build.0 = Release|Any CPU
{A350933D-F9D5-4AD3-8C4F-B856B5020297}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A350933D-F9D5-4AD3-8C4F-B856B5020297}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A350933D-F9D5-4AD3-8C4F-B856B5020297}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A350933D-F9D5-4AD3-8C4F-B856B5020297}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -209,6 +229,10 @@ Global
{627742DB-1E52-468A-99BD-6FF1A542D25B} = {831DDCA2-7D2C-4C31-80DB-6BDB3E1F7AE0}
{E3299033-EB81-4C4C-BCD9-E8DC40937969} = {831DDCA2-7D2C-4C31-80DB-6BDB3E1F7AE0}
{94E14913-D600-4448-A5C5-A268C23B2C3B} = {FA3720F1-C99A-49B2-9577-A940257098BF}
{078F96B4-09E1-4E0E-B214-F71A4F4BF633} = {831DDCA2-7D2C-4C31-80DB-6BDB3E1F7AE0}
{994BEF0B-E277-4D10-BB13-FE670D26620D} = {078F96B4-09E1-4E0E-B214-F71A4F4BF633}
{F51017A9-15C8-472D-893C-080046D710A6} = {078F96B4-09E1-4E0E-B214-F71A4F4BF633}
{A350933D-F9D5-4AD3-8C4F-B856B5020297} = {078F96B4-09E1-4E0E-B214-F71A4F4BF633}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FBDC56A3-86AD-4323-AA0F-201E59123B83}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
using Microsoft.SemanticKernel.Connectors.AI.OpenAI.TextEmbedding;
using Microsoft.SemanticKernel.Diagnostics;

// ReSharper disable once CheckNamespace // Extension methods
#pragma warning disable IDE0130
// ReSharper disable once CheckNamespace - Using NS of KernelConfig
namespace Microsoft.SemanticKernel;
#pragma warning restore IDE0130

public static class KernelConfigOpenAIExtensions
{
Expand Down
5 changes: 5 additions & 0 deletions dotnet/src/Extensions/Extensions.UnitTests/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Suppressing errors for Test projects under dotnet folder
[*.cs]
dotnet_diagnostic.CA2007.severity = none # Do not directly await a Task
dotnet_diagnostic.VSTHRD111.severity = none # Use .ConfigureAwait(bool) is hidden by default, set to none to prevent IDE from changing on autosave

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

<PropertyGroup>
<AssemblyName>SemanticKernel.Extensions.UnitTests</AssemblyName>
<RootNamespace>SemanticKernel.Extensions.UnitTests</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
<IsPackable>false</IsPackable>
<NoWarn>CA2007,VSTHRD111</NoWarn>
dluc marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Planning.ActionPlanner\Planning.ActionPlanner.csproj" />
<ProjectReference Include="..\Planning.SequentialPlanner\Planning.SequentialPlanner.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
using System.Threading.Tasks;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.Planning.Planners;
using Microsoft.SemanticKernel.Planning.Sequential;
using Microsoft.SemanticKernel.SkillDefinition;
using Moq;
using SemanticKernel.UnitTests.XunitHelpers;
using SemanticKernel.Extensions.UnitTests.XunitHelpers;
using Xunit;

namespace SemanticKernel.UnitTests.Planning;
namespace SemanticKernel.Extensions.UnitTests.Planning.SequentialPlanner;

public class SKContextExtensionsTests
{
Expand All @@ -22,7 +22,7 @@ public async Task CanCallGetAvailableFunctionsWithNoFunctionsAsync()
// Arrange
var variables = new ContextVariables();
var skills = new SkillCollection();
var logger = ConsoleLogger.Log;
var logger = TestConsoleLogger.Log;
var cancellationToken = default(CancellationToken);

// Arrange Mock Memory and Result
Expand All @@ -44,7 +44,7 @@ public async Task CanCallGetAvailableFunctionsWithNoFunctionsAsync()

// Arrange GetAvailableFunctionsAsync parameters
var context = new SKContext(variables, memory.Object, skills.ReadOnlySkillCollection, logger, cancellationToken);
var config = new PlannerConfig();
var config = new SequentialPlannerConfig();
var semanticQuery = "test";

// Act
Expand All @@ -62,7 +62,7 @@ public async Task CanCallGetAvailableFunctionsWithFunctionsAsync()
{
// Arrange
var variables = new ContextVariables();
var logger = ConsoleLogger.Log;
var logger = TestConsoleLogger.Log;
var cancellationToken = default(CancellationToken);

// Arrange FunctionView
Expand Down Expand Up @@ -103,7 +103,7 @@ public async Task CanCallGetAvailableFunctionsWithFunctionsAsync()

// Arrange GetAvailableFunctionsAsync parameters
var context = new SKContext(variables, memory.Object, skills.Object, logger, cancellationToken);
var config = new PlannerConfig();
var config = new SequentialPlannerConfig();
var semanticQuery = "test";

// Act
Expand Down Expand Up @@ -132,7 +132,7 @@ public async Task CanCallGetAvailableFunctionsWithFunctionsWithRelevancyAsync()
{
// Arrange
var variables = new ContextVariables();
var logger = ConsoleLogger.Log;
var logger = TestConsoleLogger.Log;
var cancellationToken = default(CancellationToken);

// Arrange FunctionView
Expand Down Expand Up @@ -173,7 +173,7 @@ public async Task CanCallGetAvailableFunctionsWithFunctionsWithRelevancyAsync()

// Arrange GetAvailableFunctionsAsync parameters
var context = new SKContext(variables, memory.Object, skills.Object, logger, cancellationToken);
var config = new PlannerConfig() { RelevancyThreshold = 0.78 };
var config = new SequentialPlannerConfig { RelevancyThreshold = 0.78 };
var semanticQuery = "test";

// Act
Expand Down Expand Up @@ -203,7 +203,7 @@ public async Task CanCallGetAvailableFunctionsAsyncWithDefaultRelevancyAsync()
// Arrange
var variables = new ContextVariables();
var skills = new SkillCollection();
var logger = ConsoleLogger.Log;
var logger = TestConsoleLogger.Log;
var cancellationToken = default(CancellationToken);

// Arrange Mock Memory and Result
Expand All @@ -226,7 +226,7 @@ public async Task CanCallGetAvailableFunctionsAsyncWithDefaultRelevancyAsync()

// Arrange GetAvailableFunctionsAsync parameters
var context = new SKContext(variables, memory.Object, skills.ReadOnlySkillCollection, logger, cancellationToken);
var config = new PlannerConfig() { RelevancyThreshold = 0.78 };
var config = new SequentialPlannerConfig { RelevancyThreshold = 0.78 };
var semanticQuery = "test";

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.Planning;
using Microsoft.SemanticKernel.Planning.Sequential;
using Microsoft.SemanticKernel.SemanticFunctions;
using Microsoft.SemanticKernel.SkillDefinition;
using Moq;
using Xunit;
using Xunit.Abstractions;

namespace SemanticKernel.UnitTests.Planning;
namespace SemanticKernel.Extensions.UnitTests.Planning.SequentialPlanner;

public class SequentialPlanParserTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
using Microsoft.SemanticKernel.AI.TextCompletion;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.Planning.Planners;
using Microsoft.SemanticKernel.SemanticFunctions;
using Microsoft.SemanticKernel.SkillDefinition;
using Moq;
using Xunit;

namespace SemanticKernel.UnitTests.Planning;
namespace SemanticKernel.Extensions.UnitTests.Planning.SequentialPlanner;

public sealed class PlanningTests
public sealed class SequentialPlannerTests
{
[Theory]
[InlineData("Write a poem or joke and send it in an e-mail to Kai.")]
Expand Down Expand Up @@ -116,7 +115,7 @@ public async Task ItCanCreatePlanAsync(string goal)
It.IsAny<SemanticFunctionConfig>()
)).Returns(mockFunctionFlowFunction.Object);

var planner = new SequentialPlanner(kernel.Object);
var planner = new Microsoft.SemanticKernel.Planning.SequentialPlanner(kernel.Object);

// Act
var plan = await planner.CreatePlanAsync(goal);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using Microsoft.Extensions.Logging;

namespace SemanticKernel.Extensions.UnitTests.XunitHelpers;

/// <summary>
/// Basic logger printing to console
/// </summary>
internal static class TestConsoleLogger
{
internal static ILogger Log => LogFactory.CreateLogger<object>();

private static ILoggerFactory LogFactory => s_loggerFactory.Value;
private static readonly Lazy<ILoggerFactory> s_loggerFactory = new(LogBuilder);

private static ILoggerFactory LogBuilder()
{
return LoggerFactory.Create(builder =>
{
builder.SetMinimumLevel(LogLevel.Trace);
// builder.AddFilter("Microsoft", LogLevel.Trace);
// builder.AddFilter("Microsoft", LogLevel.Debug);
// builder.AddFilter("Microsoft", LogLevel.Information);
// builder.AddFilter("Microsoft", LogLevel.Warning);
// builder.AddFilter("Microsoft", LogLevel.Error);
builder.AddConsole();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Collections.Generic;

namespace Microsoft.SemanticKernel.Planning.Action;

/// <summary>
/// Plan data structure returned by the basic planner semantic function
/// </summary>
internal sealed class ActionPlanResponse
{
public class PlanData
{
/// <summary>
/// Rationale given by the LLM for choosing the function
/// </summary>
public string Rationale { get; set; } = string.Empty;

/// <summary>
/// Name of the function chosen
/// </summary>
public string Function { get; set; } = string.Empty;

/// <summary>
/// Parameter values
/// </summary>
public Dictionary<string, string> Parameters { get; set; } = new();
}

/// <summary>
/// Plan information
/// </summary>
public PlanData Plan { get; set; } = new();
}