diff --git a/dotnet/sample/AutoGen.Gemini.Sample/Chat_With_Google_Gemini.cs b/dotnet/sample/AutoGen.Gemini.Sample/Chat_With_Google_Gemini.cs index 233c35c81222..356ae23ff007 100644 --- a/dotnet/sample/AutoGen.Gemini.Sample/Chat_With_Google_Gemini.cs +++ b/dotnet/sample/AutoGen.Gemini.Sample/Chat_With_Google_Gemini.cs @@ -1,8 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Chat_With_Google_Gemini.cs +#region Using using AutoGen.Core; -using AutoGen.Gemini.Middleware; +#endregion Using using FluentAssertions; namespace AutoGen.Gemini.Sample; @@ -11,6 +12,7 @@ public class Chat_With_Google_Gemini { public static async Task RunAsync() { + #region Create_Gemini_Agent var apiKey = Environment.GetEnvironmentVariable("GOOGLE_GEMINI_API_KEY"); if (apiKey is null) @@ -19,7 +21,6 @@ public static async Task RunAsync() return; } - #region Create_Gemini_Agent var geminiAgent = new GeminiChatAgent( name: "gemini", model: "gemini-1.5-flash-001", @@ -29,7 +30,9 @@ public static async Task RunAsync() .RegisterPrintMessage(); #endregion Create_Gemini_Agent + #region Chat_With_Google_Gemini var reply = await geminiAgent.SendAsync("Can you write a piece of C# code to calculate 100th of fibonacci?"); + #endregion Chat_With_Google_Gemini #region verify_reply reply.Should().BeOfType(); diff --git a/dotnet/sample/AutoGen.Gemini.Sample/Chat_With_Vertex_Gemini.cs b/dotnet/sample/AutoGen.Gemini.Sample/Chat_With_Vertex_Gemini.cs index 679a07ed69b9..5924ef7167a6 100644 --- a/dotnet/sample/AutoGen.Gemini.Sample/Chat_With_Vertex_Gemini.cs +++ b/dotnet/sample/AutoGen.Gemini.Sample/Chat_With_Vertex_Gemini.cs @@ -1,8 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Chat_With_Vertex_Gemini.cs +#region Using using AutoGen.Core; -using AutoGen.Gemini.Middleware; +#endregion Using using FluentAssertions; namespace AutoGen.Gemini.Sample; @@ -11,6 +12,7 @@ public class Chat_With_Vertex_Gemini { public static async Task RunAsync() { + #region Create_Gemini_Agent var projectID = Environment.GetEnvironmentVariable("GCP_VERTEX_PROJECT_ID"); if (projectID is null) @@ -19,7 +21,6 @@ public static async Task RunAsync() return; } - #region Create_Gemini_Agent var geminiAgent = new GeminiChatAgent( name: "gemini", model: "gemini-1.5-flash-001", @@ -30,7 +31,9 @@ public static async Task RunAsync() .RegisterPrintMessage(); #endregion Create_Gemini_Agent + #region Chat_With_Vertex_Gemini var reply = await geminiAgent.SendAsync("Can you write a piece of C# code to calculate 100th of fibonacci?"); + #endregion Chat_With_Vertex_Gemini #region verify_reply reply.Should().BeOfType(); diff --git a/dotnet/sample/AutoGen.Gemini.Sample/Function_Call_With_Gemini.cs b/dotnet/sample/AutoGen.Gemini.Sample/Function_Call_With_Gemini.cs index d1b681d87096..db5068a7b914 100644 --- a/dotnet/sample/AutoGen.Gemini.Sample/Function_Call_With_Gemini.cs +++ b/dotnet/sample/AutoGen.Gemini.Sample/Function_Call_With_Gemini.cs @@ -1,13 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Function_Call_With_Gemini.cs +#region Using using AutoGen.Core; -using AutoGen.Gemini.Middleware; -using FluentAssertions; using Google.Cloud.AIPlatform.V1; +#endregion Using +using FluentAssertions; namespace AutoGen.Gemini.Sample; +#region MovieFunction public partial class MovieFunction { /// @@ -58,8 +60,8 @@ public async Task GetShowtimes(string location, string movie, string the return result; } - } +#endregion MovieFunction /// /// Modified from https://ai.google.dev/gemini-api/docs/function-calling @@ -68,6 +70,7 @@ public partial class Function_Call_With_Gemini { public static async Task RunAsync() { + #region Create_Gemini_Agent var projectID = Environment.GetEnvironmentVariable("GCP_VERTEX_PROJECT_ID"); if (projectID is null) @@ -90,7 +93,6 @@ public static async Task RunAsync() { movieFunction.GetShowtimesFunctionContract.Name!, movieFunction.GetShowtimesWrapper }, }); - #region Create_Gemini_Agent var geminiAgent = new GeminiChatAgent( name: "gemini", model: "gemini-1.5-flash-001", diff --git a/dotnet/sample/AutoGen.Gemini.Sample/Image_Chat_With_Vertex_Gemini.cs b/dotnet/sample/AutoGen.Gemini.Sample/Image_Chat_With_Vertex_Gemini.cs index 86193b653d9c..ad320e7c6fad 100644 --- a/dotnet/sample/AutoGen.Gemini.Sample/Image_Chat_With_Vertex_Gemini.cs +++ b/dotnet/sample/AutoGen.Gemini.Sample/Image_Chat_With_Vertex_Gemini.cs @@ -1,8 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Image_Chat_With_Vertex_Gemini.cs +#region Using using AutoGen.Core; -using AutoGen.Gemini.Middleware; +#endregion Using using FluentAssertions; namespace AutoGen.Gemini.Sample; @@ -11,6 +12,7 @@ public class Image_Chat_With_Vertex_Gemini { public static async Task RunAsync() { + #region Create_Gemini_Agent var projectID = Environment.GetEnvironmentVariable("GCP_VERTEX_PROJECT_ID"); if (projectID is null) @@ -19,7 +21,6 @@ public static async Task RunAsync() return; } - #region Create_Gemini_Agent var geminiAgent = new GeminiChatAgent( name: "gemini", model: "gemini-1.5-flash-001", diff --git a/dotnet/src/AutoGen.Gemini/AutoGen.Gemini.csproj b/dotnet/src/AutoGen.Gemini/AutoGen.Gemini.csproj index 5a2a42ceb58c..29c4d1bb9c6f 100644 --- a/dotnet/src/AutoGen.Gemini/AutoGen.Gemini.csproj +++ b/dotnet/src/AutoGen.Gemini/AutoGen.Gemini.csproj @@ -4,6 +4,15 @@ netstandard2.0 + + + + + AutoGen.Gemini + + This package provides the intergration with Gemini. + + diff --git a/dotnet/src/AutoGen.Gemini/Middleware/GeminiAgentExtension.cs b/dotnet/src/AutoGen.Gemini/Middleware/GeminiAgentExtension.cs index 8718d54f960a..7f10c7d8e365 100644 --- a/dotnet/src/AutoGen.Gemini/Middleware/GeminiAgentExtension.cs +++ b/dotnet/src/AutoGen.Gemini/Middleware/GeminiAgentExtension.cs @@ -3,7 +3,7 @@ using AutoGen.Core; -namespace AutoGen.Gemini.Middleware; +namespace AutoGen.Gemini; public static class GeminiAgentExtension { diff --git a/dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs b/dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs index 35008ebf00c2..cb18ba084d78 100644 --- a/dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs +++ b/dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs @@ -16,7 +16,7 @@ using static Google.Cloud.AIPlatform.V1.Candidate.Types; using IMessage = AutoGen.Core.IMessage; -namespace AutoGen.Gemini.Middleware; +namespace AutoGen.Gemini; public class GeminiMessageConnector : IStreamingMiddleware { diff --git a/dotnet/src/AutoGen/AutoGen.csproj b/dotnet/src/AutoGen/AutoGen.csproj index c54b7c84a3be..ddc34a071cbf 100644 --- a/dotnet/src/AutoGen/AutoGen.csproj +++ b/dotnet/src/AutoGen/AutoGen.csproj @@ -17,6 +17,8 @@ + + diff --git a/dotnet/test/AutoGen.Gemini.Tests/GeminiAgentTests.cs b/dotnet/test/AutoGen.Gemini.Tests/GeminiAgentTests.cs index 220492d64575..872cce5e645b 100644 --- a/dotnet/test/AutoGen.Gemini.Tests/GeminiAgentTests.cs +++ b/dotnet/test/AutoGen.Gemini.Tests/GeminiAgentTests.cs @@ -8,7 +8,6 @@ using AutoGen.Gemini.Extension; using static Google.Cloud.AIPlatform.V1.Part; using Xunit.Abstractions; -using AutoGen.Gemini.Middleware; namespace AutoGen.Gemini.Tests; public class GeminiAgentTests diff --git a/dotnet/test/AutoGen.Gemini.Tests/GeminiMessageTests.cs b/dotnet/test/AutoGen.Gemini.Tests/GeminiMessageTests.cs index 7d72c18f1438..7ffb532ea9c1 100644 --- a/dotnet/test/AutoGen.Gemini.Tests/GeminiMessageTests.cs +++ b/dotnet/test/AutoGen.Gemini.Tests/GeminiMessageTests.cs @@ -2,7 +2,6 @@ // GeminiMessageTests.cs using AutoGen.Core; -using AutoGen.Gemini.Middleware; using AutoGen.Tests; using FluentAssertions; using Google.Cloud.AIPlatform.V1; diff --git a/dotnet/website/articles/AutoGen.Gemini/Chat-with-google-gemini.md b/dotnet/website/articles/AutoGen.Gemini/Chat-with-google-gemini.md new file mode 100644 index 000000000000..92907af9899a --- /dev/null +++ b/dotnet/website/articles/AutoGen.Gemini/Chat-with-google-gemini.md @@ -0,0 +1,31 @@ +This example shows how to use @AutoGen.Gemini.GeminiChatAgent to connect to Google AI Gemini and chat with Gemini model. + +To run this example, you need to have a Google AI Gemini API key. For how to get a Google Gemini API key, please refer to [Google Gemini](https://gemini.google.com/). + +> [!NOTE] +> You can find the complete sample code [here](https://github.com/microsoft/autogen/blob/main/dotnet/sample/AutoGen.Gemini.Sample/Chat_With_Google_Gemini.cs) + +> [!NOTE] +> What's the difference between Google AI Gemini and Vertex AI Gemini? +> +> Gemini is a series of large language models developed by Google. You can use it either from Google AI API or Vertex AI API. If you are relatively new to Gemini and wants to explore the feature and build some prototype for your chatbot app, Google AI APIs (with Google AI Studio) is a fast way to get started. While your app and idea matures and you'd like to leverage more MLOps tools that streamline the usage, deployment, and monitoring of models, you can move to Google Cloud Vertex AI which provides Gemini APIs along with many other features. Basically, to help you productionize your app. ([reference](https://stackoverflow.com/questions/78007243/utilizing-gemini-through-vertex-ai-or-through-google-generative-ai)) + +### Step 1: Install AutoGen.Gemini + +First, install the AutoGen.Gemini package using the following command: + +```bash +dotnet add package AutoGen.Gemini +``` + +### Step 2: Add using statement + +[!code-csharp[](../../../sample/AutoGen.Gemini.Sample/Chat_With_Google_Gemini.cs?name=Using)] + +### Step 3: Create a Gemini agent + +[!code-csharp[](../../../sample/AutoGen.Gemini.Sample/Chat_With_Google_Gemini.cs?name=Create_Gemini_Agent)] + +### Step 4: Chat with Gemini + +[!code-csharp[](../../../sample/AutoGen.Gemini.Sample/Chat_With_Google_Gemini.cs?name=Chat_With_Google_Gemini)] \ No newline at end of file diff --git a/dotnet/website/articles/AutoGen.Gemini/Chat-with-vertex-gemini.md b/dotnet/website/articles/AutoGen.Gemini/Chat-with-vertex-gemini.md new file mode 100644 index 000000000000..81f0b1c70793 --- /dev/null +++ b/dotnet/website/articles/AutoGen.Gemini/Chat-with-vertex-gemini.md @@ -0,0 +1,32 @@ +This example shows how to use @AutoGen.Gemini.GeminiChatAgent to connect to Vertex AI Gemini API and chat with Gemini model. + +To run this example, you need to have a project on Google Cloud with access to Vertex AI API. For more information please refer to [Google Vertex AI](https://cloud.google.com/vertex-ai/docs). + +> [!NOTE] +> You can find the complete sample code [here](https://github.com/microsoft/autogen/blob/main/dotnet/sample/AutoGen.Gemini.Sample/Chat_With_Vertex_Gemini.cs) + +> [!NOTE] +> What's the difference between Google AI Gemini and Vertex AI Gemini? +> +> Gemini is a series of large language models developed by Google. You can use it either from Google AI API or Vertex AI API. If you are relatively new to Gemini and wants to explore the feature and build some prototype for your chatbot app, Google AI APIs (with Google AI Studio) is a fast way to get started. While your app and idea matures and you'd like to leverage more MLOps tools that streamline the usage, deployment, and monitoring of models, you can move to Google Cloud Vertex AI which provides Gemini APIs along with many other features. Basically, to help you productionize your app. ([reference](https://stackoverflow.com/questions/78007243/utilizing-gemini-through-vertex-ai-or-through-google-generative-ai)) + +### Step 1: Install AutoGen.Gemini + +First, install the AutoGen.Gemini package using the following command: + +```bash +dotnet add package AutoGen.Gemini +``` + +### Step 2: Add using statement + +[!code-csharp[](../../../sample/AutoGen.Gemini.Sample/Chat_With_Vertex_Gemini.cs?name=Using)] + +### Step 3: Create a Gemini agent + +[!code-csharp[](../../../sample/AutoGen.Gemini.Sample/Chat_With_Vertex_Gemini.cs?name=Create_Gemini_Agent)] + + +### Step 4: Chat with Gemini + +[!code-csharp[](../../../sample/AutoGen.Gemini.Sample/Chat_With_Vertex_Gemini.cs?name=Chat_With_Vertex_Gemini)] \ No newline at end of file diff --git a/dotnet/website/articles/AutoGen.Gemini/Function-call-with-gemini.md b/dotnet/website/articles/AutoGen.Gemini/Function-call-with-gemini.md new file mode 100644 index 000000000000..354e1cd284d4 --- /dev/null +++ b/dotnet/website/articles/AutoGen.Gemini/Function-call-with-gemini.md @@ -0,0 +1,38 @@ +This example shows how to use @AutoGen.Gemini.GeminiChatAgent to make function call. This example is modified from [gemini-api function call example](https://ai.google.dev/gemini-api/docs/function-calling) + +To run this example, you need to have a project on Google Cloud with access to Vertex AI API. For more information please refer to [Google Vertex AI](https://cloud.google.com/vertex-ai/docs). + + +> [!NOTE] +> You can find the complete sample code [here](https://github.com/microsoft/autogen/blob/main/dotnet/sample/AutoGen.Gemini.Sample/Function_Call_With_Gemini.cs) + +### Step 1: Install AutoGen.Gemini and AutoGen.SourceGenerator + +First, install the AutoGen.Gemini package using the following command: + +```bash +dotnet add package AutoGen.Gemini +dotnet add package AutoGen.SourceGenerator +``` + +The AutoGen.SourceGenerator package is required to generate the @AutoGen.Core.FunctionContract. For more information, please refer to [Create-type-safe-function-call](../Create-type-safe-function-call.md) + +### Step 2: Add using statement +[!code-csharp[](../../../sample/AutoGen.Gemini.Sample/Function_call_with_gemini.cs?name=Using)] + +### Step 3: Create `MovieFunction` + +[!code-csharp[](../../../sample/AutoGen.Gemini.Sample/Function_call_with_gemini.cs?name=MovieFunction)] + +### Step 4: Create a Gemini agent + +[!code-csharp[](../../../sample/AutoGen.Gemini.Sample/Function_call_with_gemini.cs?name=Create_Gemini_Agent)] + +### Step 5: Single turn function call + +[!code-csharp[](../../../sample/AutoGen.Gemini.Sample/Function_call_with_gemini.cs?name=Single_turn)] + +### Step 6: Multi-turn function call + +[!code-csharp[](../../../sample/AutoGen.Gemini.Sample/Function_call_with_gemini.cs?name=Multi_turn)] + diff --git a/dotnet/website/articles/AutoGen.Gemini/Image-chat-with-gemini.md b/dotnet/website/articles/AutoGen.Gemini/Image-chat-with-gemini.md new file mode 100644 index 000000000000..c72159712b5c --- /dev/null +++ b/dotnet/website/articles/AutoGen.Gemini/Image-chat-with-gemini.md @@ -0,0 +1,25 @@ +This example shows how to use @AutoGen.Gemini.GeminiChatAgent for image chat with Gemini model. + +To run this example, you need to have a project on Google Cloud with access to Vertex AI API. For more information please refer to [Google Vertex AI](https://cloud.google.com/vertex-ai/docs). + + +> [!NOTE] +> You can find the complete sample code [here](https://github.com/microsoft/autogen/blob/main/dotnet/sample/AutoGen.Gemini.Sample/Image_Chat_With_Vertex_Gemini.cs) + +### Step 1: Install AutoGen.Gemini + +First, install the AutoGen.Gemini package using the following command: + +```bash +dotnet add package AutoGen.Gemini +``` + +### Step 2: Add using statement +[!code-csharp[](../../../sample/AutoGen.Gemini.Sample/Image_Chat_With_Vertex_Gemini.cs?name=Using)] + +### Step 3: Create a Gemini agent + +[!code-csharp[](../../../sample/AutoGen.Gemini.Sample/Image_Chat_With_Vertex_Gemini.cs?name=Create_Gemini_Agent)] + +### Step 4: Send image to Gemini +[!code-csharp[](../../../sample/AutoGen.Gemini.Sample/Image_Chat_With_Vertex_Gemini.cs?name=Send_Image_Request)] diff --git a/dotnet/website/articles/AutoGen.Gemini/Overview.md b/dotnet/website/articles/AutoGen.Gemini/Overview.md new file mode 100644 index 000000000000..3f921805a3eb --- /dev/null +++ b/dotnet/website/articles/AutoGen.Gemini/Overview.md @@ -0,0 +1,12 @@ +# AutoGen.Gemini Overview + +AutoGen.Gemini is a package that provides seamless integration with Google Gemini. It provides the following agent: + +- @AutoGen.Gemini.GeminiChatAgent: The agent that connects to Google Gemini or Vertex AI Gemini. It supports chat, multi-modal chat, and function call. + +AutoGen.Gemini also provides the following middleware: +- @AutoGen.Gemini.GeminiMessageConnector: The middleware that converts the Gemini message to AutoGen built-in message type. + +## Examples + +You can find more examples under the [gemini sample project](https://github.com/microsoft/autogen/tree/main/dotnet/sample/AutoGen.Gemini.Sample) \ No newline at end of file diff --git a/dotnet/website/articles/Installation.md b/dotnet/website/articles/Installation.md index 86067a6501c1..3ec5d3a470f4 100644 --- a/dotnet/website/articles/Installation.md +++ b/dotnet/website/articles/Installation.md @@ -12,6 +12,7 @@ AutoGen.Net provides the following packages, you can choose to install one or mo - `AutoGen.Anthropic`: This package provides the integration agents for [Anthropic](https://www.anthropic.com/api) - `AutoGen.LMStudio`: This package provides the integration agents from LM Studio. - `AutoGen.SemanticKernel`: This package provides the integration agents over semantic kernel. +- `AutoGen.Gemini`: This package provides the integration agents from [Google Gemini](https://gemini.google.com/). - `AutoGen.SourceGenerator`: This package carries a source generator that adds support for type-safe function definition generation. - `AutoGen.DotnetInteractive`: This packages carries dotnet interactive support to execute dotnet code snippet. diff --git a/dotnet/website/articles/toc.yml b/dotnet/website/articles/toc.yml index 2496d5d36d04..8788c682757d 100644 --- a/dotnet/website/articles/toc.yml +++ b/dotnet/website/articles/toc.yml @@ -79,6 +79,7 @@ href: AutoGen.SemanticKernel/SemanticKernelAgent-support-more-messages.md - name: Use kernel plugin in other agents href: AutoGen.SemanticKernel/Use-kernel-plugin-in-other-agents.md + - name: AutoGen.Ollama items: - name: Examples @@ -87,6 +88,22 @@ href: AutoGen.Ollama/Chat-with-LLaMA.md - name: MultiModal Chat with LLaVA href: AutoGen.Ollama/Chat-with-LLaVA.md + +- name: AutoGen.Gemini + items: + - name: Overview + href: AutoGen.Gemini/Overview.md + - name: Examples + items: + - name: Chat with Google AI Gemini + href: AutoGen.Gemini/Chat-with-google-gemini.md + - name: Chat with Vertex AI Gemini + href: AutoGen.Gemini/Chat-with-vertex-gemini.md + - name: Function call with Gemini + href: AutoGen.Gemini/Function-call-with-gemini.md + - name: Image chat with Gemini + href: AutoGen.Gemini/Image-chat-with-gemini.md + - name: AutoGen.Mistral items: - name: Overview