Class GeminiChatAgent
public class GeminiChatAgent : IStreamingAgent, IAgent, IAgentMetaInformation
- Inheritance
-
GeminiChatAgent
- Implements
- Inherited Members
- Extension Methods
Constructors
GeminiChatAgent(IGeminiClient, string, string, string?, ToolConfig?, Tool[]?, RepeatedField<SafetySetting>?, string)
Create GeminiChatAgent that connects to Gemini.
public GeminiChatAgent(IGeminiClient client, string name, string model, string? systemMessage = null, ToolConfig? toolConfig = null, Tool[]? tools = null, RepeatedField<SafetySetting>? safetySettings = null, string responseMimeType = "text/plain")
Parameters
client
IGeminiClientthe gemini client to use. e.g. AutoGen.Gemini.VertexGeminiClient
name
stringagent name
model
stringthe model id. It needs to be in the format of 'projects/{project}/locations/{location}/publishers/{provider}/models/{model}' if the
client
is AutoGen.Gemini.VertexGeminiClientsystemMessage
stringsystem message
toolConfig
ToolConfigtool config
tools
Tool[]tools
safetySettings
RepeatedField<SafetySetting>safety settings
responseMimeType
stringresponse mime type, available values are ['application/json', 'text/plain'], default is 'text/plain'
GeminiChatAgent(string, string, string, string, ToolConfig?, Tool[]?, RepeatedField<SafetySetting>?, string)
Create GeminiChatAgent that connects to Gemini using GoogleGeminiClient
public GeminiChatAgent(string name, string model, string apiKey, string systemMessage = "You are a helpful AI assistant", ToolConfig? toolConfig = null, Tool[]? tools = null, RepeatedField<SafetySetting>? safetySettings = null, string responseMimeType = "text/plain")
Parameters
name
stringagent name
model
stringthe name of gemini model, e.g. gemini-1.5-flash-001
apiKey
stringgoogle gemini api key
systemMessage
stringsystem message
toolConfig
ToolConfigtool config
tools
Tool[]tools
safetySettings
RepeatedField<SafetySetting>responseMimeType
stringresponse mime type, available values are ['application/json', 'text/plain'], default is 'text/plain'
Examples
var apiKey = Environment.GetEnvironmentVariable("GOOGLE_GEMINI_API_KEY");
if (apiKey is null)
{
Console.WriteLine("Please set GOOGLE_GEMINI_API_KEY environment variable.");
return;
}
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();
GeminiChatAgent(string, string, string, string, string, string?, ToolConfig?, Tool[]?, RepeatedField<SafetySetting>?, string)
Create GeminiChatAgent that connects to Vertex AI.
public GeminiChatAgent(string name, string model, string project, string location, string provider = "google", string? systemMessage = null, ToolConfig? toolConfig = null, Tool[]? tools = null, RepeatedField<SafetySetting>? safetySettings = null, string responseMimeType = "text/plain")
Parameters
name
stringagent name
model
stringthe name of gemini model, e.g. gemini-1.5-flash-001
project
stringproject id
location
stringmodel location
provider
stringmodel provider, default is 'google'
systemMessage
stringsystem message
toolConfig
ToolConfigtool config
tools
Tool[]tools
safetySettings
RepeatedField<SafetySetting>responseMimeType
stringresponse mime type, available values are ['application/json', 'text/plain'], default is 'text/plain'
Examples
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-east1",
project: projectID,
systemMessage: "You are a helpful C# engineer, put your code between ```csharp and ```, don't explain the code")
.RegisterMessageConnector()
.RegisterPrintMessage();
Properties
Name
public string Name { get; }
Property Value
Methods
GenerateReplyAsync(IEnumerable<IMessage>, GenerateReplyOptions?, CancellationToken)
Generate reply
public Task<IMessage> GenerateReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, CancellationToken cancellationToken = default)
Parameters
messages
IEnumerable<IMessage>conversation history
options
GenerateReplyOptionscompletion option. If provided, it should override existing option if there's any
cancellationToken
CancellationToken
Returns
GenerateStreamingReplyAsync(IEnumerable<IMessage>, GenerateReplyOptions?, CancellationToken)
public IAsyncEnumerable<IMessage> GenerateStreamingReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, CancellationToken cancellationToken = default)
Parameters
messages
IEnumerable<IMessage>options
GenerateReplyOptionscancellationToken
CancellationToken