Table of Contents

Class GeminiModel

Namespace
GenerativeAI
Assembly
GenerativeAI.dll

The GeminiModel class is a specialized implementation of the GenerativeModel, designed to provide capabilities for generative AI tasks. It supports multiple constructors for flexibility, allowing users to configure the model according to their specific requirements, including platform, API key, configuration, safety settings, and various other parameters.

public class GeminiModel : GenerativeModel, IGenerativeModel
Inheritance
GeminiModel
Implements
Inherited Members
Extension Methods

Remarks

This class extends the functionality of the GenerativeModel and exposes additional configuration options, such as file management through the FileClient property. The GeminiModel is intended to support diverse generative AI use-cases.

Constructors

GeminiModel(IPlatformAdapter, string, GenerationConfig?, ICollection<SafetySetting>?, string?, HttpClient?, ILogger?)

public GeminiModel(IPlatformAdapter platform, string model, GenerationConfig? config = null, ICollection<SafetySetting>? safetySettings = null, string? systemInstruction = null, HttpClient? httpClient = null, ILogger? logger = null)

Parameters

platform IPlatformAdapter
model string
config GenerationConfig
safetySettings ICollection<SafetySetting>
systemInstruction string
httpClient HttpClient
logger ILogger

GeminiModel(string, ModelParams, HttpClient?, ILogger?)

public GeminiModel(string apiKey, ModelParams modelParams, HttpClient? client = null, ILogger? logger = null)

Parameters

apiKey string
modelParams ModelParams
client HttpClient
logger ILogger

Properties

Files

Represents a property to interact with files associated with the GeminiModel.

public FileClient? Files { get; set; }

Property Value

FileClient

Remarks

This property is used to access and manage files through the FileClient, allowing operations such as uploading, retrieving, deleting, and listing files.

TimeoutForFileStateCheck

Gets or sets the timeout value, in seconds, used for checking the state of a uploaded file.

public int TimeoutForFileStateCheck { get; set; }

Property Value

int

Remarks

This property determines the maximum duration to wait while verifying the state of operations related to files, such as uploads or processing.

Methods

AwaitForFileStateActive(RemoteFile, int, CancellationToken)

Waits for a remote file to reach the "Active" state within a specified time limit.

public Task AwaitForFileStateActive(RemoteFile file, int maxSeconds = 300, CancellationToken cancellationToken = default)

Parameters

file RemoteFile

The remote file whose state is being monitored.

maxSeconds int

The maximum number of seconds to wait for the file to become "Active".

cancellationToken CancellationToken

An optional token to monitor for cancellation requests.

Returns

Task

A task that represents the asynchronous operation.

GenerateContentAsync(string, string, CancellationToken)

Generates content asynchronously based on the given text prompt and the specified file path.

public Task<GenerateContentResponse> GenerateContentAsync(string prompt, string filePath, CancellationToken cancellationToken = default)

Parameters

prompt string

The textual input used as the basis for content generation.

filePath string

The path to the file that should be included in the content generation request.

cancellationToken CancellationToken

A cancellation token used to propagate notifications that the operation should be canceled.

Returns

Task<GenerateContentResponse>

A task representing the asynchronous operation, containing the GenerateContentResponse or null if the operation fails.

See Also

GetFileAsync(string, CancellationToken)

Retrieves metadata of a file asynchronously from the API.

public Task<RemoteFile> GetFileAsync(string fileId, CancellationToken cancellationToken = default)

Parameters

fileId string

The unique identifier of the file whose metadata is to be retrieved.

cancellationToken CancellationToken

An optional token to monitor for cancellation requests.

Returns

Task<RemoteFile>

A RemoteFile object containing metadata details of the requested file.

StreamContentAsync(string, string, CancellationToken)

Streams content generation asynchronously based on the provided text prompt, file path, and cancellation token.

public IAsyncEnumerable<GenerateContentResponse> StreamContentAsync(string prompt, string filePath, CancellationToken cancellationToken = default)

Parameters

prompt string

The input text prompt used to guide the content generation process.

filePath string

The local file path

cancellationToken CancellationToken

A token to monitor for cancellation requests during the streaming process.

Returns

IAsyncEnumerable<GenerateContentResponse>

An asynchronous enumerable of GenerateContentResponse instances representing the streamed content generation results.

See Also

UploadFileAsync(string, Action<double>?, CancellationToken)

Uploads a file asynchronously to the API and tracks its upload progress.

public Task<RemoteFile> UploadFileAsync(string filePath, Action<double>? progressCallback, CancellationToken cancellationToken = default)

Parameters

filePath string

The local path of the file to be uploaded.

progressCallback Action<double>

An optional callback to receive updates on upload progress as a percentage.

cancellationToken CancellationToken

An optional token to monitor for cancellation requests.

Returns

Task<RemoteFile>

A RemoteFile object representing the uploaded file on the API.