-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Changes from 10 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
1486f4b
refactor message
LittleLittleCloud f876431
refactor over IMessage
LittleLittleCloud e9a472f
add more tests
LittleLittleCloud 8919058
add more test
LittleLittleCloud f99659e
fix build error
LittleLittleCloud 1e3364b
rename header
LittleLittleCloud 01e492e
add semantic kernel project
LittleLittleCloud bccfbc5
update sk example
LittleLittleCloud a4e592c
Merge branch 'dotnet' into u/xiaoyun/dotnet/message
LittleLittleCloud 1935f70
update dotnet version
LittleLittleCloud 4d24b68
Merge branch 'dotnet' into u/xiaoyun/dotnet/message
LittleLittleCloud 53a481d
Merge branch 'dotnet' into u/xiaoyun/dotnet/message
LittleLittleCloud 3682e8e
Merge branch 'dotnet' into u/xiaoyun/dotnet/message
LittleLittleCloud 4068373
Merge branch 'dotnet' into u/xiaoyun/dotnet/message
LittleLittleCloud f079405
use IMessage
LittleLittleCloud 5194e23
more updates
LittleLittleCloud da89fb0
update
LittleLittleCloud fb36566
fix test
LittleLittleCloud bc3e1df
add comments
LittleLittleCloud 0d5fdac
use FunctionContract to replace FunctionDefinition
LittleLittleCloud 4a1e288
move AutoGen contrac to AutoGen.Core
LittleLittleCloud 5ed491d
update installation
LittleLittleCloud 273b283
refactor streamingAgent by adding StreamingMessage type
LittleLittleCloud 40265e6
update sample
LittleLittleCloud a392b23
update samples
LittleLittleCloud 6a268a7
update
LittleLittleCloud d301ea3
update
LittleLittleCloud f9ff7e6
add test
LittleLittleCloud b32f5b5
fix test
LittleLittleCloud 9bb9fd9
bump version
LittleLittleCloud cbacdc7
add openaichat test
LittleLittleCloud 222a57c
update
LittleLittleCloud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"sdk": { | ||
"version": "8.0.101", | ||
"rollForward": "latestMajor" | ||
"rollForward": "latestMinor" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
dotnet/sample/AutoGen.BasicSamples/Example09_SemanticKernel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
|
||
using AutoGen.BasicSample; | ||
|
||
await Example08_LMStudio.RunAsync(); | ||
await Example09_SemanticKernel.RunAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
dotnet/src/AutoGen.SemanticKernel/AutoGen.SemanticKernel.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
dotnet/src/AutoGen.SemanticKernel/Extension/KernelExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?