Skip to content

Commit

Permalink
Merge pull request #17 from gsilvamartin/16-add-get-model-and-list-mo…
Browse files Browse the repository at this point in the history
…del-method

Gel model and models
  • Loading branch information
gsilvamartin authored Mar 17, 2024
2 parents ad29db2 + 687d110 commit 99496b6
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/DotnetGeminiSDK/Client/GeminiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,35 @@ public Task StreamTextPrompt(
return await _apiRequester.PostAsync<GeminiMessageResponse>(promptUrl, request);
}

/// <summary>
/// Get a model from Google Gemini API
///
/// REF: https://ai.google.dev/tutorials/rest_quickstart#get_model
/// </summary>
/// <param name="modelName">Model name to find</param>
/// <returns></returns>
/// <returns>A GeminiModelResponse containing the model information</returns>
public async Task<GeminiModelResponse?> GetModel(string modelName)
{
if (string.IsNullOrEmpty(modelName)) throw new ArgumentException("Model name cannot be empty.");

var modelUrl = $"{_config.ModelBaseUrl}/{modelName}?key={_config.ApiKey}";
return await _apiRequester.GetAsync<GeminiModelResponse>(modelUrl);
}

/// <summary>
/// Get all models from Google Gemini API
///
/// REF: https://ai.google.dev/tutorials/rest_quickstart#get_model
/// </summary>
/// <returns>A List of GeminiModelResponse containing the model information</returns>
/// <exception cref="NotImplementedException"></exception>
public async Task<RootGeminiModelResponse> GetModels()
{
var modelUrl = $"{_config.ModelBaseUrl}?key={_config.ApiKey}";
return await _apiRequester.GetAsync<RootGeminiModelResponse>(modelUrl);
}

/// <summary>
/// Build a GeminiMessageRequest object to process image from a string message, base 64 and mimetype
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions src/DotnetGeminiSDK/Client/Interfaces/IGeminiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,9 @@ Task StreamTextPrompt(
Task<GeminiMessageResponse?> ImagePrompt(string message, byte[] image, ImageMimeType imageMimeType);

Task<GeminiMessageResponse?> ImagePrompt(string message, string base64Image, ImageMimeType imageMimeType);

Task<GeminiModelResponse?> GetModel(string modelName);

Task<RootGeminiModelResponse> GetModels();
}
}
1 change: 1 addition & 0 deletions src/DotnetGeminiSDK/Config/GoogleGeminiConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public class GoogleGeminiConfig
public string TextBaseUrl { get; set; } = "https://generativelanguage.googleapis.com/v1/models/gemini-pro";
public string ImageBaseUrl { get; set; } =
"https://generativelanguage.googleapis.com/v1beta/models/gemini-pro-vision";
public string ModelBaseUrl { get; set; } = "https://generativelanguage.googleapis.com/v1beta/models";
}
}
44 changes: 44 additions & 0 deletions src/DotnetGeminiSDK/Model/Response/GeminiModelResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace DotnetGeminiSDK.Model.Response
{
public class RootGeminiModelResponse
{
[JsonProperty("models", NullValueHandling = NullValueHandling.Ignore)]
public IEnumerable<GeminiModelResponse?> GeminiModelResponses { get; set; } = new List<GeminiModelResponse>();
}

public class GeminiModelResponse
{
[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
public string Name { get; set; }

[JsonProperty("version", NullValueHandling = NullValueHandling.Ignore)]
public string Version { get; set; }

[JsonProperty("displayName", NullValueHandling = NullValueHandling.Ignore)]
public string DisplayName { get; set; }

[JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)]
public string Description { get; set; }

[JsonProperty("inputTokenLimit", NullValueHandling = NullValueHandling.Ignore)]
public int InputTokenLimit { get; set; }

[JsonProperty("outputTokenLimit", NullValueHandling = NullValueHandling.Ignore)]
public int OutputTokenLimit { get; set; }

[JsonProperty("supportedGenerationMethods", NullValueHandling = NullValueHandling.Ignore)]
public List<string> SupportedGenerationMethods { get; set; }

[JsonProperty("temperature", NullValueHandling = NullValueHandling.Ignore)]
public double Temperature { get; set; }

[JsonProperty("topP", NullValueHandling = NullValueHandling.Ignore)]
public double TopP { get; set; }

[JsonProperty("topK", NullValueHandling = NullValueHandling.Ignore)]
public double TopK { get; set; }
}
}

0 comments on commit 99496b6

Please sign in to comment.