Class GenerativeAIImagenGenerator
- Namespace
- GenerativeAI.Microsoft
- Assembly
- GenerativeAI.Microsoft.dll
Implements Microsoft.Extensions.AI.IImageGenerator by creating an ImagenModel via GenAI.CreateImageModel and calling GenerateImagesAsync(GenerateImageRequest, CancellationToken).
public sealed class GenerativeAIImagenGenerator : IImageGenerator, IDisposable
- Inheritance
-
GenerativeAIImagenGenerator
- Implements
-
IImageGenerator
- Inherited Members
- Extension Methods
Constructors
GenerativeAIImagenGenerator(GenAI, string)
Creates a new instance using an existing GenAI factory and optional model name.
public GenerativeAIImagenGenerator(GenAI genai, string modelName = "models/imagen-3.0-generate-002")
Parameters
GenerativeAIImagenGenerator(string, string)
Creates a new instance using an API key and optional model name.
public GenerativeAIImagenGenerator(string apiKey, string modelName = "models/imagen-3.0-generate-002")
Parameters
Properties
model
Underlying ImagenModel instance created from the provided GenAI factory.
public ImagenModel 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.