Table of Contents

Class GenerativeAIImageGenerator

Namespace
GenerativeAI.Microsoft
Assembly
GenerativeAI.Microsoft.dll

Implements Microsoft.Extensions.AI.IImageGenerator using the Google_GenerativeAI SDK by creating a GenerateContentRequest that requests image modality and forwarding it to GenerateContentAsync(GenerateContentRequest, CancellationToken).

public sealed class GenerativeAIImageGenerator : IImageGenerator, IDisposable
Inheritance
GenerativeAIImageGenerator
Implements
IImageGenerator
Inherited Members
Extension Methods

Constructors

GenerativeAIImageGenerator(IPlatformAdapter, string)

Creates a new instance using a platform adapter and optional model name.

public GenerativeAIImageGenerator(IPlatformAdapter adapter, string modelName = "models/gemini-nano-banana-2.1")

Parameters

adapter IPlatformAdapter
modelName string

GenerativeAIImageGenerator(string, string)

Creates a new instance using an API key and optional model name.

public GenerativeAIImageGenerator(string apiKey, string modelName = "models/gemini-nano-banana-2.1")

Parameters

apiKey string
modelName string

Properties

model

Underlying GenerativeModel instance.

public GenerativeModel model { get; }

Property Value

GenerativeModel

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GenerateAsync(ImageGenerationRequest, ImageGenerationOptions?, CancellationToken)

Sends an image generation request and returns the generated image as a Microsoft.Extensions.AI.ImageGenerationResponse.

public Task<ImageGenerationResponse> GenerateAsync(ImageGenerationRequest request, ImageGenerationOptions? options = null, CancellationToken cancellationToken = default)

Parameters

request ImageGenerationRequest

The image generation request containing the prompt and optional original images for editing.

options ImageGenerationOptions

The image generation options to configure the request.

cancellationToken CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

Task<ImageGenerationResponse>

The images generated by the Microsoft.Extensions.AI.ImageGenerationRequest.

Exceptions

ArgumentNullException

request is null.

GetService(Type, object?)

Asks the Microsoft.Extensions.AI.IImageGenerator for an object of the specified type serviceType.

public object? GetService(Type serviceType, object? serviceKey = null)

Parameters

serviceType Type

The type of object being requested.

serviceKey object

An optional key that can be used to help identify the target service.

Returns

object

The found object, otherwise null.

Remarks

The purpose of this method is to allow for the retrieval of strongly typed services that might be provided by the Microsoft.Extensions.AI.IImageGenerator, including itself or any services it might be wrapping.

Exceptions

ArgumentNullException

serviceType is null.