Junaid.GoogleGemini.Net 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Junaid.GoogleGemini.Net --version 1.0.1                
NuGet\Install-Package Junaid.GoogleGemini.Net -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Junaid.GoogleGemini.Net" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Junaid.GoogleGemini.Net --version 1.0.1                
#r "nuget: Junaid.GoogleGemini.Net, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Junaid.GoogleGemini.Net as a Cake Addin
#addin nuget:?package=Junaid.GoogleGemini.Net&version=1.0.1

// Install Junaid.GoogleGemini.Net as a Cake Tool
#tool nuget:?package=Junaid.GoogleGemini.Net&version=1.0.1                

Junaid.GoogleGemini.Net

An open-source .NET library to use Gemini API based on Google�s largest and most capable AI model yet.

Installation

.NET CLI:

> dotnet add package Junaid.GoogleGemini.Net

Package Manager:

PM > Install-Package Junaid.GoogleGemini.Net

Usage

Authentication

Get an API key from Google's AI Studio here. Use GeminiConfiguration.ApiKey property to set the secret key.

GeminiConfiguration.ApiKey = "xxxxxxxxxxxxxxxxx";

TextService

TextService is used to generate text-only content. The GenereateContentAsync method takes a string (text prompt) as an argument and returns the textual data.

var service = new TextService();
var result = await service.GenereateContentAsync("Say Hi to me!");

VisionService

VisionService is used to generate content with both text and image inputs. The GenereateContentAsync method takes a string (text prompt) and FileObject (file bytes and file name) as an argument and returns the textual data.

string filePath = "path/<imageName.imageExtension>";
var fileName = Path.GetFileName(filePath);
byte[] fileBytes = Array.Empty<byte>();
try
{
    using (var imageStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
    using (var memoryStream = new MemoryStream())
    {
        imageStream.CopyTo(memoryStream);
        fileBytes = memoryStream.ToArray();
    }
    Console.WriteLine($"Image loaded successfully. Byte array length: {fileBytes.Length}");
}
catch (Exception ex)
{
    Console.WriteLine($"Error: {ex.Message}");
}

var service = new VisionService();
var result = await service.GenereateContentAsync("Explain this image?", new Junaid.GoogleGemini.Net.Models.Requests.FileObject(fileBytes, fileName));

Contributing

Feel free to improve the library by adding new functionality, removing outdated functionality, updating broken functionality and refactoring code by using better Software Engineering practices, styles and patterns.

Getting Started

  1. Start by forking the repository.
  2. Clone the forked repository.
  3. Create a new branch for your contribution.

Contribution Guidelines

  • Adhere to the established code style within the project.
  • Use meaningful commit messages.
  • Please test your code and document the changes before creating a pull request.
  • Push your changes to your fork and initiate a pull request against the master branch.
  • Ensure your changes do not break existing functionality.
  • While creating issues include detailed information, steps to reproduce the issue and check for existing issues to avoid duplicates.

Feel free to open an issue or contact me if you have any questions or suggestions.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 1,361 1/20/2024
3.2.0 237 12/31/2023
3.1.1 121 12/30/2023
3.1.0 120 12/30/2023
3.0.0 119 12/30/2023
2.1.0 128 12/30/2023
2.0.0 133 12/29/2023
1.0.4 140 12/27/2023
1.0.3 123 12/26/2023
1.0.2 119 12/25/2023
1.0.1 139 12/25/2023
1.0.0 120 12/24/2023

Added vision service to use Gemini Content API using Text-and-image input.