From 687d1105025259abc2a43a1d4dcadd97486ea101 Mon Sep 17 00:00:00 2001 From: Guilherme Martin Date: Sat, 16 Mar 2024 23:08:16 -0300 Subject: [PATCH] Gel model and models --- src/DotnetGeminiSDK/Client/GeminiClient.cs | 29 ++++++++++++ .../Client/Interfaces/IGeminiClient.cs | 4 ++ .../Config/GoogleGeminiConfig.cs | 1 + .../Model/Response/GeminiModelResponse.cs | 44 +++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 src/DotnetGeminiSDK/Model/Response/GeminiModelResponse.cs diff --git a/src/DotnetGeminiSDK/Client/GeminiClient.cs b/src/DotnetGeminiSDK/Client/GeminiClient.cs index dec0d6e..e4e2aee 100644 --- a/src/DotnetGeminiSDK/Client/GeminiClient.cs +++ b/src/DotnetGeminiSDK/Client/GeminiClient.cs @@ -260,6 +260,35 @@ public Task StreamTextPrompt( return await _apiRequester.PostAsync(promptUrl, request); } + /// + /// Get a model from Google Gemini API + /// + /// REF: https://ai.google.dev/tutorials/rest_quickstart#get_model + /// + /// Model name to find + /// + /// A GeminiModelResponse containing the model information + public async Task 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(modelUrl); + } + + /// + /// Get all models from Google Gemini API + /// + /// REF: https://ai.google.dev/tutorials/rest_quickstart#get_model + /// + /// A List of GeminiModelResponse containing the model information + /// + public async Task GetModels() + { + var modelUrl = $"{_config.ModelBaseUrl}?key={_config.ApiKey}"; + return await _apiRequester.GetAsync(modelUrl); + } + /// /// Build a GeminiMessageRequest object to process image from a string message, base 64 and mimetype /// diff --git a/src/DotnetGeminiSDK/Client/Interfaces/IGeminiClient.cs b/src/DotnetGeminiSDK/Client/Interfaces/IGeminiClient.cs index 50ab0e9..e47c386 100644 --- a/src/DotnetGeminiSDK/Client/Interfaces/IGeminiClient.cs +++ b/src/DotnetGeminiSDK/Client/Interfaces/IGeminiClient.cs @@ -60,5 +60,9 @@ Task StreamTextPrompt( Task ImagePrompt(string message, byte[] image, ImageMimeType imageMimeType); Task ImagePrompt(string message, string base64Image, ImageMimeType imageMimeType); + + Task GetModel(string modelName); + + Task GetModels(); } } \ No newline at end of file diff --git a/src/DotnetGeminiSDK/Config/GoogleGeminiConfig.cs b/src/DotnetGeminiSDK/Config/GoogleGeminiConfig.cs index 60a2f8f..435bbe7 100644 --- a/src/DotnetGeminiSDK/Config/GoogleGeminiConfig.cs +++ b/src/DotnetGeminiSDK/Config/GoogleGeminiConfig.cs @@ -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"; } } \ No newline at end of file diff --git a/src/DotnetGeminiSDK/Model/Response/GeminiModelResponse.cs b/src/DotnetGeminiSDK/Model/Response/GeminiModelResponse.cs new file mode 100644 index 0000000..1056a6e --- /dev/null +++ b/src/DotnetGeminiSDK/Model/Response/GeminiModelResponse.cs @@ -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 GeminiModelResponses { get; set; } = new List(); + } + + 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 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; } + } +} \ No newline at end of file