-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into wael/human-input-mode-annot
- Loading branch information
Showing
51 changed files
with
2,768 additions
and
143 deletions.
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
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
19 changes: 19 additions & 0 deletions
19
dotnet/sample/AutoGen.Gemini.Sample/AutoGen.Gemini.Sample.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,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
38
dotnet/sample/AutoGen.Gemini.Sample/Chat_With_Google_Gemini.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,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
39
dotnet/sample/AutoGen.Gemini.Sample/Chat_With_Vertex_Gemini.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,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
129
dotnet/sample/AutoGen.Gemini.Sample/Function_Call_With_Gemini.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,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 | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
dotnet/sample/AutoGen.Gemini.Sample/Image_Chat_With_Vertex_Gemini.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,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 | ||
} | ||
} |
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,6 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Program.cs | ||
|
||
using AutoGen.Gemini.Sample; | ||
|
||
Image_Chat_With_Vertex_Gemini.RunAsync().Wait(); |
Oops, something went wrong.