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

Create Autogen assistant #21

Merged
merged 4 commits into from
Feb 10, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
matrix:
package:
- Assistants
- Assistants.AutoGen

steps:
- uses: actions/checkout@v4
Expand Down
60 changes: 59 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ It runs locally planners and plugins for the assistants.
It provides different scenarios for the usage of assistants such as:
- **Assistant with Semantic Kernel plugins**
- **Multi-Assistant conversation**
- **AutoGen conversation** (see [AutoGen](#autogen) for more details)

As the assistants are using the Semantic Kernel, you can use your own model for the assistants and host them locally (see: [Bring you own model](#bring-you-own-model-) for more details.).

Expand Down Expand Up @@ -44,7 +45,7 @@ proprietary data.
To install the assistant Framework, you need to add the required nuget package to your project:

```dotnetcli
dotnet add package SemanticKernel.Assistants --version 1.2.0-preview
dotnet add package SemanticKernel.Assistants
```

## Usage
Expand Down Expand Up @@ -113,6 +114,63 @@ assistant = AssistantBuilder.FromTemplate("./Assistants/Butler.yaml")
.Build();
```

## AutoGen

AutoGen is based on the approach proposed by [Microsoft's Auto-Gen](https://github.com/microsoft/autogen).

It is realized through 2 assistants working together to code and execute the code needed to respond to user requests.

- __AssistantAgent (NL 2 Code)__: this agent takes charge of the user's request and produces Python code to respond to the user's request.
- __CodeInterpreter__: This agent takes as input the various parameters required to execute the Python code supplied by the AssistantAgent.

> Note:
> Through its native plugin, the CodeInterpreter interacts with Docker to start a container, install the necessary dependencies and execute the Python code in this container, then returns the result.

```csharp
string azureOpenAIEndpoint = configuration["AzureOpenAIEndpoint"]!;
string azureOpenAIGPT4DeploymentName = configuration["AzureOpenAIGPT4DeploymentName"]!;
string azureOpenAIGPT35DeploymentName = configuration["AzureOpenAIGPT35DeploymentName"]!;
string azureOpenAIKey = configuration["AzureOpenAIAPIKey"]!;
string ollamaEndpoint = configuration["OllamaEndpoint"]!;

var codeInterpretionOptions = new CodeInterpretionPluginOptions();
configuration!.Bind("CodeInterpreter", codeInterpretionOptions);

IAssistant CreateCodeInterpreter(CodeInterpretionPluginOptions codeInterpretionOptions, string azureOpenAIDeploymentName, string azureOpenAIEndpoint, string azureOpenAIKey)
{
var kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(azureOpenAIDeploymentName, azureOpenAIEndpoint, azureOpenAIKey)
.Build();

kernel.ImportPluginFromObject(new CodeInterpretionPlugin(codeInterpretionOptions, loggerFactory), "code");

return CodeInterpreterBuilder.CreateBuilder()
.WithKernel(kernel)
.Build();
}

IAssistant CreateAssistantAgent()
{
var codeInterpretionOptions = new CodeInterpretionPluginOptions();
configuration!.Bind("CodeInterpreter", codeInterpretionOptions);

var butlerKernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(azureOpenAIGPT4DeploymentName, azureOpenAIEndpoint, azureOpenAIKey)
.Build();

butlerKernel.ImportPluginFromObject(new FileAccessPlugin(codeInterpretionOptions.OutputFilePath, loggerFactory), "file");
butlerKernel.ImportPluginFromAssistant(CreateCodeInterpreter(codeInterpretionOptions, azureOpenAIGPT35DeploymentName, azureOpenAIEndpoint, azureOpenAIKey));

assistant = AssistantAgentBuilder.CreateBuilder()
.WithKernel(butlerKernel)
.Build();
}

var thread = CreateAssistantAgent().CreateThread();

var answer = await thread.InvokeAsync(prompt).ConfigureAwait(true);
```

## License

This project is licensed under the [MIT License](LICENSE).
9 changes: 9 additions & 0 deletions SemanticKernel.Assistants.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "02-autogen", "samples\02-autogen\02-autogen.csproj", "{F5C5DEF1-3AB7-4DAF-A29D-A46483875287}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SemanticKernel.Assistants.AutoGen", "src\Assistants.AutoGen\SemanticKernel.Assistants.AutoGen.csproj", "{B3BD3FAC-3CD7-4127-A09F-D1ABC640B32A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -66,6 +68,12 @@ Global
{F5C5DEF1-3AB7-4DAF-A29D-A46483875287}.Publish|Any CPU.Build.0 = Debug|Any CPU
{F5C5DEF1-3AB7-4DAF-A29D-A46483875287}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F5C5DEF1-3AB7-4DAF-A29D-A46483875287}.Release|Any CPU.Build.0 = Release|Any CPU
{B3BD3FAC-3CD7-4127-A09F-D1ABC640B32A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3BD3FAC-3CD7-4127-A09F-D1ABC640B32A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3BD3FAC-3CD7-4127-A09F-D1ABC640B32A}.Publish|Any CPU.ActiveCfg = Debug|Any CPU
{B3BD3FAC-3CD7-4127-A09F-D1ABC640B32A}.Publish|Any CPU.Build.0 = Debug|Any CPU
{B3BD3FAC-3CD7-4127-A09F-D1ABC640B32A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3BD3FAC-3CD7-4127-A09F-D1ABC640B32A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -76,6 +84,7 @@ Global
{BBC6C36F-DC43-4FD3-9706-ECA4738F8F57} = {803BA424-8745-4689-9C1D-72CA4384E6AC}
{B69AC62F-2CB1-4BCD-AB94-2C558AD3DB29} = {324300B5-4DBA-4DF0-957C-75458CCF93CE}
{F5C5DEF1-3AB7-4DAF-A29D-A46483875287} = {803BA424-8745-4689-9C1D-72CA4384E6AC}
{B3BD3FAC-3CD7-4127-A09F-D1ABC640B32A} = {96B59E8F-BF38-4918-8312-63DA3363B20B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3252A8D5-644E-45F0-B096-AC8C2F0A15B4}
Expand Down
8 changes: 2 additions & 6 deletions samples/02-autogen/02-autogen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
</ItemGroup>

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

<ItemGroup>
Expand All @@ -35,12 +37,6 @@
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Assistants\AssistantAgent.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Assistants\CodeInterpreter.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="vgsales.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
12 changes: 0 additions & 12 deletions samples/02-autogen/Defaults.cs

This file was deleted.

19 changes: 0 additions & 19 deletions samples/02-autogen/Exceptions/CodeInterpreterException.cs

This file was deleted.

Loading
Loading