From 129e72ce9c1d9570cdf49e2cbf9f1f438f7c4c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20Kirst=C3=A4tter?= <7329802+jochenkirstaetter@users.noreply.github.com> Date: Thu, 30 Jan 2025 21:30:26 +0400 Subject: [PATCH] add constructors for VertexAI #63 --- .../GeminiChatClient.cs | 19 +++++++++++++++--- .../GeminiEmbeddingGenerator.cs | 20 ++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/Mscc.GenerativeAI.Microsoft/GeminiChatClient.cs b/src/Mscc.GenerativeAI.Microsoft/GeminiChatClient.cs index b3e9c46..970ae06 100644 --- a/src/Mscc.GenerativeAI.Microsoft/GeminiChatClient.cs +++ b/src/Mscc.GenerativeAI.Microsoft/GeminiChatClient.cs @@ -22,17 +22,30 @@ public sealed class GeminiChatClient : mea.IChatClient public mea.ChatClientMetadata Metadata { get; } /// - /// Creates an instance of the Gemini API client. + /// Creates an instance of the Gemini API client using Google AI. /// /// API key provided by Google AI Studio - /// Model to use - public GeminiChatClient(string apiKey, string model = "") + /// Model to use. + public GeminiChatClient(string apiKey, string model = Model.Gemini15Pro) { var genAi = new GoogleAI(apiKey); _client = genAi.GenerativeModel(model); Metadata = new(ProviderName, null, model); } + /// + /// Creates an instance of the Gemini API client using Vertex AI. + /// + /// Identifier of the Google Cloud project. + /// Optional. Region to use (default: "us-central1"). + /// Model to use. + public GeminiChatClient(string projectId, string? region = null, string model = Model.Gemini15Pro) + { + var genAi = new VertexAI(projectId, region); + _client = genAi.GenerativeModel(model); + Metadata = new(ProviderName, null, model); + } + /// public async Task CompleteAsync( IList chatMessages, diff --git a/src/Mscc.GenerativeAI.Microsoft/GeminiEmbeddingGenerator.cs b/src/Mscc.GenerativeAI.Microsoft/GeminiEmbeddingGenerator.cs index a689de2..f635f80 100644 --- a/src/Mscc.GenerativeAI.Microsoft/GeminiEmbeddingGenerator.cs +++ b/src/Mscc.GenerativeAI.Microsoft/GeminiEmbeddingGenerator.cs @@ -20,13 +20,31 @@ public class GeminiEmbeddingGenerator : IEmbeddingGenerator public EmbeddingGeneratorMetadata Metadata { get; } - public GeminiEmbeddingGenerator(string apiKey, string model = "") + /// + /// Creates an instance of the Gemini API client using Google AI. + /// + /// API key provided by Google AI Studio + /// Model to use. + public GeminiEmbeddingGenerator(string apiKey, string model = Model.Embedding) { var genAi = new GoogleAI(apiKey); _client = genAi.GenerativeModel(model); Metadata = new(providerName, null, model); } + /// + /// Creates an instance of the Gemini API client using Vertex AI. + /// + /// Identifier of the Google Cloud project. + /// Optional. Region to use (default: "us-central1"). + /// Model to use. + public GeminiEmbeddingGenerator(string projectId, string? region = null, string model = Model.Embedding) + { + var genAi = new VertexAI(projectId, region); + _client = genAi.GenerativeModel(model); + Metadata = new(providerName, null, model); + } + /// public async Task>> GenerateAsync( IEnumerable values,