Skip to content

Commit

Permalink
add constructors for VertexAI #63
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenkirstaetter committed Jan 30, 2025
1 parent 89b462d commit 129e72c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/Mscc.GenerativeAI.Microsoft/GeminiChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,30 @@ public sealed class GeminiChatClient : mea.IChatClient
public mea.ChatClientMetadata Metadata { get; }

/// <summary>
/// Creates an instance of the Gemini API client.
/// Creates an instance of the Gemini API client using Google AI.
/// </summary>
/// <param name="apiKey">API key provided by Google AI Studio</param>
/// <param name="model">Model to use</param>
public GeminiChatClient(string apiKey, string model = "")
/// <param name="model">Model to use.</param>
public GeminiChatClient(string apiKey, string model = Model.Gemini15Pro)
{
var genAi = new GoogleAI(apiKey);
_client = genAi.GenerativeModel(model);
Metadata = new(ProviderName, null, model);
}

/// <summary>
/// Creates an instance of the Gemini API client using Vertex AI.
/// </summary>
/// <param name="projectId">Identifier of the Google Cloud project.</param>
/// <param name="region">Optional. Region to use (default: "us-central1").</param>
/// <param name="model">Model to use.</param>
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);
}

/// <inheritdoc/>
public async Task<mea.ChatCompletion> CompleteAsync(
IList<mea.ChatMessage> chatMessages,
Expand Down
20 changes: 19 additions & 1 deletion src/Mscc.GenerativeAI.Microsoft/GeminiEmbeddingGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,31 @@ public class GeminiEmbeddingGenerator : IEmbeddingGenerator<string, Embedding<fl
/// <inheritdoc/>
public EmbeddingGeneratorMetadata Metadata { get; }

public GeminiEmbeddingGenerator(string apiKey, string model = "")
/// <summary>
/// Creates an instance of the Gemini API client using Google AI.
/// </summary>
/// <param name="apiKey">API key provided by Google AI Studio</param>
/// <param name="model">Model to use.</param>
public GeminiEmbeddingGenerator(string apiKey, string model = Model.Embedding)
{
var genAi = new GoogleAI(apiKey);
_client = genAi.GenerativeModel(model);
Metadata = new(providerName, null, model);
}

/// <summary>
/// Creates an instance of the Gemini API client using Vertex AI.
/// </summary>
/// <param name="projectId">Identifier of the Google Cloud project.</param>
/// <param name="region">Optional. Region to use (default: "us-central1").</param>
/// <param name="model">Model to use.</param>
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);
}

/// <inheritdoc/>
public async Task<GeneratedEmbeddings<Embedding<float>>> GenerateAsync(
IEnumerable<string> values,
Expand Down

0 comments on commit 129e72c

Please sign in to comment.