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
adapterIPlatformAdaptermodelNamestring
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
Properties
model
Underlying GenerativeModel instance.
public GenerativeModel model { get; }
Property Value
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
requestImageGenerationRequestThe image generation request containing the prompt and optional original images for editing.
optionsImageGenerationOptionsThe image generation options to configure the request.
cancellationTokenCancellationTokenThe CancellationToken to monitor for cancellation requests. The default is None.
Returns
- Task<ImageGenerationResponse>
The images generated by the Microsoft.Extensions.AI.ImageGenerationRequest.
Exceptions
- ArgumentNullException
requestis 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
serviceTypeTypeThe type of object being requested.
serviceKeyobjectAn optional key that can be used to help identify the target service.
Returns
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
serviceTypeis null.