Mscc.GenerativeAI.Microsoft 1.9.0-preview

This is a prerelease version of Mscc.GenerativeAI.Microsoft.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Mscc.GenerativeAI.Microsoft --version 1.9.0-preview                
NuGet\Install-Package Mscc.GenerativeAI.Microsoft -Version 1.9.0-preview                
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="Mscc.GenerativeAI.Microsoft" Version="1.9.0-preview" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Mscc.GenerativeAI.Microsoft --version 1.9.0-preview                
#r "nuget: Mscc.GenerativeAI.Microsoft, 1.9.0-preview"                
#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 Mscc.GenerativeAI.Microsoft as a Cake Addin
#addin nuget:?package=Mscc.GenerativeAI.Microsoft&version=1.9.0-preview&prerelease

// Install Mscc.GenerativeAI.Microsoft as a Cake Tool
#tool nuget:?package=Mscc.GenerativeAI.Microsoft&version=1.9.0-preview&prerelease                

MSCC GenerativeAI for .NET integrating with Microsoft.Extensions.AI and Microsoft Semantic Kernel.

GitHub GitHub last commit

Integrate Gemini API into your .NET applications using Microsoft.Extensions.AI. This package implements the IChatClient and IEmbeddingGenerator interfaces offering a unified experience for .NET applications and libraries.

Benefits of Microsoft.Extensions.AI

Microsoft.Extensions.AI offers a unified API abstraction for AI services, similar to our successful logging and dependency injection (DI) abstractions. Our goal is to provide standard implementations for caching, telemetry, tool calling, and other common tasks that work with any provider.

Read more Introducing Microsoft.Extensions.AI Preview – Unified AI Building Blocks for .NET

Getting started

To get started, you can create a console application and install the Mscc.GenerativeAI.Microsoft package. Have your API key from Google AI Studio and you're ready to go.

Chat

using Microsoft.Extensions.AI;
using Mscc.GenerativeAI.Microsoft;

// Chat with Gemini API.
var apiKey = Environment.GetEnvironmentVariable("GOOGLE_API_KEY");
var model = "gemini-1.5-pro-latest";
var prompt = "What is AI?";

IChatClient chatClient = new GeminiChatClient(apiKey, model);

var response = await chatClient.CompleteAsync(prompt);
Console.WriteLine(response.Message);

response = await chatClient.CompleteAsync( 
    "Translate the following text into Pig Latin: I love .NET and AI"); 
Console.WriteLine(response.Message);

Embeddings

using Microsoft.Extensions.AI;
using Mscc.GenerativeAI.Microsoft;

// Create embeddings using the appropriate model.
var apiKey = Environment.GetEnvironmentVariable("GOOGLE_API_KEY");
var model = "text-embedding-004";
var prompt = "What is AI?";

IEmbeddingGenerator<string,Embedding<float>> generator = 
    new GeminiEmbeddingGenerator(apiKey, model);

var embeddings = await generator.GenerateAsync([prompt]);
Console.WriteLine(string.Join(", ", embeddings[0].Vector.ToArray()));

More examples

The folders samples and tests contain more examples.

Troubleshooting

tba

Feedback

You can create issues at the https://github.com/mscraftsman/generative-ai repository.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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 is compatible.  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.  net9.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
1.9.6-preview 36 11/26/2024
1.9.5-preview 42 11/22/2024
1.9.4 43 11/21/2024
1.9.3 41 11/20/2024
1.9.2 40 11/18/2024
1.9.1 39 11/13/2024
1.9.0-preview 39 11/4/2024
1.8.3-preview 39 11/1/2024
1.8.2-preview 42 10/31/2024

# Changelog (Release Notes)

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
### Changed
### Fixed

## 1.9.0

### Changed

- bump version

## 1.8.3

### Changed

- bump version

## 1.8.2

### Added

- initial release