This example shows how to use Gemini
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.
Note
You can find the complete sample code here
Step 1: Install AutoGen.Gemini
First, install the AutoGen.Gemini package using the following command:
dotnet add package AutoGen.Gemini
Step 2: Add using statement
using AutoGen.Core;
Step 3: Create a Gemini agent
var projectID = Environment.GetEnvironmentVariable("GCP_VERTEX_PROJECT_ID");
if (projectID is null)
{
Console.WriteLine("Please set GCP_VERTEX_PROJECT_ID environment variable.");
return;
}
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();
Step 4: Send image to Gemini
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]);