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

[.Net] Bring Semantic-Kernel to AutoGen && Propose a new message abstraction to support multi-modal/parallel function call && potential breaking change from openai api #1676

Merged
merged 32 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1486f4b
refactor message
LittleLittleCloud Feb 13, 2024
f876431
refactor over IMessage
LittleLittleCloud Feb 14, 2024
e9a472f
add more tests
LittleLittleCloud Feb 14, 2024
8919058
add more test
LittleLittleCloud Feb 14, 2024
f99659e
fix build error
LittleLittleCloud Feb 14, 2024
1e3364b
rename header
LittleLittleCloud Feb 14, 2024
01e492e
add semantic kernel project
LittleLittleCloud Feb 14, 2024
bccfbc5
update sk example
LittleLittleCloud Feb 14, 2024
a4e592c
Merge branch 'dotnet' into u/xiaoyun/dotnet/message
LittleLittleCloud Feb 14, 2024
1935f70
update dotnet version
LittleLittleCloud Feb 14, 2024
4d24b68
Merge branch 'dotnet' into u/xiaoyun/dotnet/message
LittleLittleCloud Feb 20, 2024
53a481d
Merge branch 'dotnet' into u/xiaoyun/dotnet/message
LittleLittleCloud Feb 28, 2024
3682e8e
Merge branch 'dotnet' into u/xiaoyun/dotnet/message
LittleLittleCloud Feb 29, 2024
4068373
Merge branch 'dotnet' into u/xiaoyun/dotnet/message
LittleLittleCloud Feb 29, 2024
f079405
use IMessage
LittleLittleCloud Feb 29, 2024
5194e23
more updates
LittleLittleCloud Feb 29, 2024
da89fb0
update
LittleLittleCloud Mar 1, 2024
fb36566
fix test
LittleLittleCloud Mar 1, 2024
bc3e1df
add comments
LittleLittleCloud Mar 1, 2024
0d5fdac
use FunctionContract to replace FunctionDefinition
LittleLittleCloud Mar 1, 2024
4a1e288
move AutoGen contrac to AutoGen.Core
LittleLittleCloud Mar 1, 2024
5ed491d
update installation
LittleLittleCloud Mar 1, 2024
273b283
refactor streamingAgent by adding StreamingMessage type
LittleLittleCloud Mar 1, 2024
40265e6
update sample
LittleLittleCloud Mar 1, 2024
a392b23
update samples
LittleLittleCloud Mar 2, 2024
6a268a7
update
LittleLittleCloud Mar 2, 2024
d301ea3
update
LittleLittleCloud Mar 2, 2024
f9ff7e6
add test
LittleLittleCloud Mar 3, 2024
b32f5b5
fix test
LittleLittleCloud Mar 3, 2024
9bb9fd9
bump version
LittleLittleCloud Mar 3, 2024
cbacdc7
add openaichat test
LittleLittleCloud Mar 3, 2024
222a57c
update
LittleLittleCloud Mar 3, 2024
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
3 changes: 0 additions & 3 deletions dotnet/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ dotnet_diagnostic.IDE0005.severity = error
# IDE0069: Remove unused local variable
dotnet_diagnostic.IDE0069.severity = error

# IDE0060: Remove unused parameter
dotnet_diagnostic.IDE0060.severity = warning

# disable CS1573: Parameter has no matching param tag in the XML comment for
dotnet_diagnostic.CS1573.severity = none

Expand Down
9 changes: 8 additions & 1 deletion dotnet/AutoGen.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{FBFEAD
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.DotnetInteractive", "src\AutoGen.DotnetInteractive\AutoGen.DotnetInteractive.csproj", "{B61D8008-7FB7-4C0E-8044-3A74AA63A596}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.LMStudio", "src\AutoGen.LMStudio\AutoGen.LMStudio.csproj", "{F98BDA9B-8657-4BA8-9B03-BAEA454CAE60}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.LMStudio", "src\AutoGen.LMStudio\AutoGen.LMStudio.csproj", "{F98BDA9B-8657-4BA8-9B03-BAEA454CAE60}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.SemanticKernel", "src\AutoGen.SemanticKernel\AutoGen.SemanticKernel.csproj", "{45D6FC80-36F3-4967-9663-E20B63824621}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -57,6 +59,10 @@ Global
{F98BDA9B-8657-4BA8-9B03-BAEA454CAE60}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F98BDA9B-8657-4BA8-9B03-BAEA454CAE60}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F98BDA9B-8657-4BA8-9B03-BAEA454CAE60}.Release|Any CPU.Build.0 = Release|Any CPU
{45D6FC80-36F3-4967-9663-E20B63824621}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45D6FC80-36F3-4967-9663-E20B63824621}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45D6FC80-36F3-4967-9663-E20B63824621}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45D6FC80-36F3-4967-9663-E20B63824621}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -69,6 +75,7 @@ Global
{7EBF916A-A7B1-4B74-AF10-D705B7A18F58} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9}
{B61D8008-7FB7-4C0E-8044-3A74AA63A596} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{F98BDA9B-8657-4BA8-9B03-BAEA454CAE60} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{45D6FC80-36F3-4967-9663-E20B63824621} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {93384647-528D-46C8-922C-8DB36A382F0B}
Expand Down
2 changes: 2 additions & 0 deletions dotnet/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<NoWarn>$(NoWarn);$(CSNoWarn);NU5104</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
<EnableNetAnalyzers>true</EnableNetAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>

<PropertyGroup>
Expand Down
7 changes: 4 additions & 3 deletions dotnet/eng/Version.props
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AzureOpenAIVersion>1.0.0-beta.12</AzureOpenAIVersion>
<SemanticKernelVersion>1.0.1</SemanticKernelVersion>
<AzureOpenAIVersion>1.0.0-beta.13</AzureOpenAIVersion>
<SemanticKernelVersion>1.4.0</SemanticKernelVersion>
<SemanticKernelExperimentalVersion>1.4.0-alpha</SemanticKernelExperimentalVersion>
<SystemCodeDomVersion>5.0.0</SystemCodeDomVersion>
<MicrosoftCodeAnalysisVersion>4.3.0</MicrosoftCodeAnalysisVersion>
<ApprovalTestVersion>5.2.4</ApprovalTestVersion>
<ApprovalTestVersion>6.0.0</ApprovalTestVersion>
<FluentAssertionVersion>6.8.0</FluentAssertionVersion>
<XUnitVersion>2.4.2</XUnitVersion>
<MicrosoftNETTestSdkVersion>17.7.0</MicrosoftNETTestSdkVersion>
Expand Down
2 changes: 1 addition & 1 deletion dotnet/global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.101",
"rollForward": "latestMajor"
"rollForward": "latestMinor"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS8981;CS8600;CS8602;CS8604;CS8618;CS0219</NoWarn>
<NoWarn>$(NoWarn);CS8981;CS8600;CS8602;CS8604;CS8618;CS0219;SKEXP0054</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\AutoGen.DotnetInteractive\AutoGen.DotnetInteractive.csproj" />
<ProjectReference Include="..\..\src\AutoGen.LMStudio\AutoGen.LMStudio.csproj" />
<ProjectReference Include="..\..\src\AutoGen.SemanticKernel\AutoGen.SemanticKernel.csproj" />
<ProjectReference Include="..\..\src\AutoGen.SourceGenerator\AutoGen.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\..\src\AutoGen\AutoGen.csproj" />
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionVersion)" />
<PackageReference Include="Microsoft.SemanticKernel.Plugins.Web" Version="$(SemanticKernelExperimentalVersion)" />
</ItemGroup>
</Project>
61 changes: 61 additions & 0 deletions dotnet/sample/AutoGen.BasicSamples/Example09_SemanticKernel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Example09_SemanticKernel.cs

using System.ComponentModel;
using AutoGen.SemanticKernel.Extension;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
namespace AutoGen.BasicSample;

public class LightPlugin
{
public bool IsOn { get; set; } = false;

[KernelFunction]
[Description("Gets the state of the light.")]
public string GetState() => this.IsOn ? "on" : "off";

[KernelFunction]
[Description("Changes the state of the light.'")]
public string ChangeState(bool newState)
{
this.IsOn = newState;
var state = this.GetState();

// Print the state to the console
Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.WriteLine($"[Light is now {state}]");
Console.ResetColor();

return state;
}
}

public class Example09_SemanticKernel
{
public static async Task RunAsync()
{
var openAIKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new Exception("Please set OPENAI_API_KEY environment variable.");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthewbolanos Any suggestion on making a better example with AutoGen + SemanticKernel?

var modelId = "gpt-3.5-turbo";
var builder = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(modelId: modelId, apiKey: openAIKey);
var kernel = builder.Build();
var settings = new OpenAIPromptExecutionSettings
{
ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions,
};

kernel.Plugins.AddFromObject(new LightPlugin());
var assistantAgent = kernel
.ToSemanticKernelAgent(name: "assistant", systemMessage: "You control the light", settings)
.RegisterPrintFormatMessageHook();


var userProxyAgent = new UserProxyAgent(name: "user", humanInputMode: ConversableAgent.HumanInputMode.ALWAYS);
await userProxyAgent.InitiateChatAsync(
receiver: assistantAgent,
message: "Hey assistant, please help me to do some tasks.",
maxRound: 10);
}

}
2 changes: 1 addition & 1 deletion dotnet/sample/AutoGen.BasicSamples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

using AutoGen.BasicSample;

await Example08_LMStudio.RunAsync();
await Example09_SemanticKernel.RunAsync();
2 changes: 1 addition & 1 deletion dotnet/src/AutoGen.LMStudio/LMStudioAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class LMStudioAgent : IAgent
functionMap: functionMap);
}

public string? Name => innerAgent.Name;
public string Name => innerAgent.Name;

public Task<Message> GenerateReplyAsync(
IEnumerable<Message> messages,
Expand Down
27 changes: 27 additions & 0 deletions dotnet/src/AutoGen.SemanticKernel/AutoGen.SemanticKernel.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>AutoGen.SemanticKernel</RootNamespace>
</PropertyGroup>

<Import Project="$(RepoRoot)/dotnet/nuget/nuget-package.props" />

<PropertyGroup>
<!-- NuGet Package Settings -->
<Title>AutoGen.SemanticKernel</Title>
<Description>
This package contains the semantic kernel integration for AutoGen
</Description>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\AutoGen\AutoGen.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="$(AzureOpenAIVersion)" />
<PackageReference Include="Microsoft.SemanticKernel" Version="$(SemanticKernelVersion)" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions dotnet/src/AutoGen.SemanticKernel/Extension/KernelExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// KernelExtension.cs

using Microsoft.SemanticKernel;

namespace AutoGen.SemanticKernel.Extension;

public static class KernelExtension
{
public static SemanticKernelAgent ToSemanticKernelAgent(this Kernel kernel, string name, string systemMessage = "You are a helpful AI assistant", PromptExecutionSettings? settings = null)
{
return new SemanticKernelAgent(kernel, name, systemMessage, settings);
}
}
Loading
Loading