Skip to content

Commit

Permalink
Merge branch 'main' into wael/human-input-mode-annot
Browse files Browse the repository at this point in the history
  • Loading branch information
WaelKarkoub authored Jun 10, 2024
2 parents 705dacc + d578d0d commit 7729468
Show file tree
Hide file tree
Showing 51 changed files with 2,768 additions and 143 deletions.
20 changes: 20 additions & 0 deletions dotnet/AutoGen.sln
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Anthropic.Tests", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Anthropic.Samples", "sample\AutoGen.Anthropic.Samples\AutoGen.Anthropic.Samples.csproj", "{834B4E85-64E5-4382-8465-548F332E5298}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Gemini", "src\AutoGen.Gemini\AutoGen.Gemini.csproj", "{EFE0DC86-80FC-4D52-95B7-07654BA1A769}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Gemini.Tests", "test\AutoGen.Gemini.Tests\AutoGen.Gemini.Tests.csproj", "{8EA16BAB-465A-4C07-ABC4-1070D40067E9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.Gemini.Sample", "sample\AutoGen.Gemini.Sample\AutoGen.Gemini.Sample.csproj", "{19679B75-CE3A-4DF0-A3F0-CA369D2760A4}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.AotCompatibility.Tests", "test\AutoGen.AotCompatibility.Tests\AutoGen.AotCompatibility.Tests.csproj", "{6B82F26D-5040-4453-B21B-C8D1F913CE4C}"
EndProject
Global
Expand Down Expand Up @@ -149,6 +154,18 @@ Global
{834B4E85-64E5-4382-8465-548F332E5298}.Debug|Any CPU.Build.0 = Debug|Any CPU
{834B4E85-64E5-4382-8465-548F332E5298}.Release|Any CPU.ActiveCfg = Release|Any CPU
{834B4E85-64E5-4382-8465-548F332E5298}.Release|Any CPU.Build.0 = Release|Any CPU
{EFE0DC86-80FC-4D52-95B7-07654BA1A769}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EFE0DC86-80FC-4D52-95B7-07654BA1A769}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EFE0DC86-80FC-4D52-95B7-07654BA1A769}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EFE0DC86-80FC-4D52-95B7-07654BA1A769}.Release|Any CPU.Build.0 = Release|Any CPU
{8EA16BAB-465A-4C07-ABC4-1070D40067E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8EA16BAB-465A-4C07-ABC4-1070D40067E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8EA16BAB-465A-4C07-ABC4-1070D40067E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8EA16BAB-465A-4C07-ABC4-1070D40067E9}.Release|Any CPU.Build.0 = Release|Any CPU
{19679B75-CE3A-4DF0-A3F0-CA369D2760A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19679B75-CE3A-4DF0-A3F0-CA369D2760A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19679B75-CE3A-4DF0-A3F0-CA369D2760A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19679B75-CE3A-4DF0-A3F0-CA369D2760A4}.Release|Any CPU.Build.0 = Release|Any CPU
{6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -180,6 +197,9 @@ Global
{6A95E113-B824-4524-8F13-CD0C3E1C8804} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{815E937E-86D6-4476-9EC6-B7FBCBBB5DB6} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
{834B4E85-64E5-4382-8465-548F332E5298} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9}
{EFE0DC86-80FC-4D52-95B7-07654BA1A769} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{8EA16BAB-465A-4C07-ABC4-1070D40067E9} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
{19679B75-CE3A-4DF0-A3F0-CA369D2760A4} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9}
{6B82F26D-5040-4453-B21B-C8D1F913CE4C} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
25 changes: 25 additions & 0 deletions dotnet/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,37 @@
<CSNoWarn>CS1998;CS1591</CSNoWarn>
<NoWarn>$(NoWarn);$(CSNoWarn);NU5104</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPackable>false</IsPackable>
<EnableNetAnalyzers>true</EnableNetAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<IsTestProject>false</IsTestProject>
</PropertyGroup>

<PropertyGroup>
<RepoRoot>$(MSBuildThisFileDirectory)</RepoRoot>
</PropertyGroup>

<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<PackageReference Include="ApprovalTests" Version="$(ApprovalTestVersion)" />
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageReference Include="xunit" Version="$(XUnitVersion)" />
<PackageReference Include="xunit.runner.console" Version="$(XUnitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitVersion)" />
</ItemGroup>

<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<Content Include="$(RepoRoot)resource/**/*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>testData/%(RecursiveDir)%(Filename)%(Extension)</Link>
</Content>
</ItemGroup>

<ItemGroup Condition="'$(IncludeResourceFolder)' == 'true'">
<Content Include="$(RepoRoot)resource/**/*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>resource/%(RecursiveDir)%(Filename)%(Extension)</Link>
</Content>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions dotnet/eng/Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<MicrosoftNETTestSdkVersion>17.7.0</MicrosoftNETTestSdkVersion>
<MicrosoftDotnetInteractive>1.0.0-beta.24229.4</MicrosoftDotnetInteractive>
<MicrosoftSourceLinkGitHubVersion>8.0.0</MicrosoftSourceLinkGitHubVersion>
<GoogleCloudAPIPlatformVersion>3.0.0</GoogleCloudAPIPlatformVersion>
<JsonSchemaVersion>4.3.0.2</JsonSchemaVersion>
</PropertyGroup>
</Project>
File renamed without changes
3 changes: 3 additions & 0 deletions dotnet/resource/images/square.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static async Task RunAsync()
if (reply.GetContent() is string content && content.Contains("IMAGE_GENERATION"))
{
var imageUrl = content.Split("\n").Last();
var imageMessage = new ImageMessage(Role.Assistant, imageUrl, from: reply.From);
var imageMessage = new ImageMessage(Role.Assistant, imageUrl, from: reply.From, mimeType: "image/png");
Console.WriteLine($"download image from {imageUrl} to {imagePath}");
var httpClient = new HttpClient();
Expand Down
19 changes: 19 additions & 0 deletions dotnet/sample/AutoGen.Gemini.Sample/AutoGen.Gemini.Sample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IncludeResourceFolder>true</IncludeResourceFolder>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\AutoGen\AutoGen.csproj" />
<ProjectReference Include="..\..\src\AutoGen.Gemini\AutoGen.Gemini.csproj" />
<ProjectReference Include="..\..\src\AutoGen.SourceGenerator\AutoGen.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionVersion)" />
</ItemGroup>

</Project>
38 changes: 38 additions & 0 deletions dotnet/sample/AutoGen.Gemini.Sample/Chat_With_Google_Gemini.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Chat_With_Google_Gemini.cs

using AutoGen.Core;
using AutoGen.Gemini.Middleware;
using FluentAssertions;

namespace AutoGen.Gemini.Sample;

public class Chat_With_Google_Gemini
{
public static async Task RunAsync()
{
var apiKey = Environment.GetEnvironmentVariable("GOOGLE_GEMINI_API_KEY");

if (apiKey is null)
{
Console.WriteLine("Please set GOOGLE_GEMINI_API_KEY environment variable.");
return;
}

#region Create_Gemini_Agent
var geminiAgent = new GeminiChatAgent(
name: "gemini",
model: "gemini-1.5-flash-001",
apiKey: apiKey,
systemMessage: "You are a helpful C# engineer, put your code between ```csharp and ```, don't explain the code")
.RegisterMessageConnector()
.RegisterPrintMessage();
#endregion Create_Gemini_Agent

var reply = await geminiAgent.SendAsync("Can you write a piece of C# code to calculate 100th of fibonacci?");

#region verify_reply
reply.Should().BeOfType<TextMessage>();
#endregion verify_reply
}
}
39 changes: 39 additions & 0 deletions dotnet/sample/AutoGen.Gemini.Sample/Chat_With_Vertex_Gemini.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Chat_With_Vertex_Gemini.cs

using AutoGen.Core;
using AutoGen.Gemini.Middleware;
using FluentAssertions;

namespace AutoGen.Gemini.Sample;

public class Chat_With_Vertex_Gemini
{
public static async Task RunAsync()
{
var projectID = Environment.GetEnvironmentVariable("GCP_VERTEX_PROJECT_ID");

if (projectID is null)
{
Console.WriteLine("Please set GCP_VERTEX_PROJECT_ID environment variable.");
return;
}

#region Create_Gemini_Agent
var geminiAgent = new GeminiChatAgent(
name: "gemini",
model: "gemini-1.5-flash-001",
location: "us-east1",
project: projectID,
systemMessage: "You are a helpful C# engineer, put your code between ```csharp and ```, don't explain the code")
.RegisterMessageConnector()
.RegisterPrintMessage();
#endregion Create_Gemini_Agent

var reply = await geminiAgent.SendAsync("Can you write a piece of C# code to calculate 100th of fibonacci?");

#region verify_reply
reply.Should().BeOfType<TextMessage>();
#endregion verify_reply
}
}
129 changes: 129 additions & 0 deletions dotnet/sample/AutoGen.Gemini.Sample/Function_Call_With_Gemini.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Function_Call_With_Gemini.cs

using AutoGen.Core;
using AutoGen.Gemini.Middleware;
using FluentAssertions;
using Google.Cloud.AIPlatform.V1;

namespace AutoGen.Gemini.Sample;

public partial class MovieFunction
{
/// <summary>
/// find movie titles currently playing in theaters based on any description, genre, title words, etc.
/// </summary>
/// <param name="location">The city and state, e.g. San Francisco, CA or a zip code e.g. 95616</param>
/// <param name="description">Any kind of description including category or genre, title words, attributes, etc.</param>
/// <returns></returns>
[Function]
public async Task<string> FindMovies(string location, string description)
{
// dummy implementation
var movies = new List<string> { "Barbie", "Spiderman", "Batman" };
var result = $"Movies playing in {location} based on {description} are: {string.Join(", ", movies)}";

return result;
}

/// <summary>
/// find theaters based on location and optionally movie title which is currently playing in theaters
/// </summary>
/// <param name="location">The city and state, e.g. San Francisco, CA or a zip code e.g. 95616</param>
/// <param name="movie">Any movie title</param>
[Function]
public async Task<string> FindTheaters(string location, string movie)
{
// dummy implementation
var theaters = new List<string> { "AMC", "Regal", "Cinemark" };
var result = $"Theaters playing {movie} in {location} are: {string.Join(", ", theaters)}";

return result;
}

/// <summary>
/// Find the start times for movies playing in a specific theater
/// </summary>
/// <param name="location">The city and state, e.g. San Francisco, CA or a zip code e.g. 95616</param>
/// <param name="movie">Any movie title</param>
/// <param name="theater">Name of the theater</param>
/// <param name="date">Date for requested showtime</param>
/// <returns></returns>
[Function]
public async Task<string> GetShowtimes(string location, string movie, string theater, string date)
{
// dummy implementation
var showtimes = new List<string> { "10:00 AM", "12:00 PM", "2:00 PM", "4:00 PM", "6:00 PM", "8:00 PM" };
var result = $"Showtimes for {movie} at {theater} in {location} are: {string.Join(", ", showtimes)}";

return result;
}

}

/// <summary>
/// Modified from https://ai.google.dev/gemini-api/docs/function-calling
/// </summary>
public partial class Function_Call_With_Gemini
{
public static async Task RunAsync()
{
var projectID = Environment.GetEnvironmentVariable("GCP_VERTEX_PROJECT_ID");

if (projectID is null)
{
Console.WriteLine("Please set GCP_VERTEX_PROJECT_ID environment variable.");
return;
}

var movieFunction = new MovieFunction();
var functionMiddleware = new FunctionCallMiddleware(
functions: [
movieFunction.FindMoviesFunctionContract,
movieFunction.FindTheatersFunctionContract,
movieFunction.GetShowtimesFunctionContract
],
functionMap: new Dictionary<string, Func<string, Task<string>>>
{
{ movieFunction.FindMoviesFunctionContract.Name!, movieFunction.FindMoviesWrapper },
{ movieFunction.FindTheatersFunctionContract.Name!, movieFunction.FindTheatersWrapper },
{ movieFunction.GetShowtimesFunctionContract.Name!, movieFunction.GetShowtimesWrapper },
});

#region Create_Gemini_Agent
var geminiAgent = new GeminiChatAgent(
name: "gemini",
model: "gemini-1.5-flash-001",
location: "us-central1",
project: projectID,
systemMessage: "You are a helpful AI assistant",
toolConfig: new ToolConfig()
{
FunctionCallingConfig = new FunctionCallingConfig()
{
Mode = FunctionCallingConfig.Types.Mode.Auto,
}
})
.RegisterMessageConnector()
.RegisterPrintMessage()
.RegisterStreamingMiddleware(functionMiddleware);
#endregion Create_Gemini_Agent

#region Single_turn
var question = new TextMessage(Role.User, "What movies are showing in North Seattle tonight?");
var functionCallReply = await geminiAgent.SendAsync(question);
#endregion Single_turn

#region Single_turn_verify_reply
functionCallReply.Should().BeOfType<ToolCallAggregateMessage>();
#endregion Single_turn_verify_reply

#region Multi_turn
var finalReply = await geminiAgent.SendAsync(chatHistory: [question, functionCallReply]);
#endregion Multi_turn

#region Multi_turn_verify_reply
finalReply.Should().BeOfType<TextMessage>();
#endregion Multi_turn_verify_reply
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Image_Chat_With_Vertex_Gemini.cs

using AutoGen.Core;
using AutoGen.Gemini.Middleware;
using FluentAssertions;

namespace AutoGen.Gemini.Sample;

public class Image_Chat_With_Vertex_Gemini
{
public static async Task RunAsync()
{
var projectID = Environment.GetEnvironmentVariable("GCP_VERTEX_PROJECT_ID");

if (projectID is null)
{
Console.WriteLine("Please set GCP_VERTEX_PROJECT_ID environment variable.");
return;
}

#region Create_Gemini_Agent
var geminiAgent = new GeminiChatAgent(
name: "gemini",
model: "gemini-1.5-flash-001",
location: "us-east4",
project: projectID,
systemMessage: "You explain image content to user")
.RegisterMessageConnector()
.RegisterPrintMessage();
#endregion Create_Gemini_Agent

#region Send_Image_Request
var imagePath = Path.Combine("resource", "images", "background.png");
var image = await File.ReadAllBytesAsync(imagePath);
var imageMessage = new ImageMessage(Role.User, BinaryData.FromBytes(image, "image/png"));
var reply = await geminiAgent.SendAsync("what's in the image", [imageMessage]);
#endregion Send_Image_Request

#region Verify_Reply
reply.Should().BeOfType<TextMessage>();
#endregion Verify_Reply
}
}
6 changes: 6 additions & 0 deletions dotnet/sample/AutoGen.Gemini.Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Program.cs

using AutoGen.Gemini.Sample;

Image_Chat_With_Vertex_Gemini.RunAsync().Wait();
Loading

0 comments on commit 7729468

Please sign in to comment.