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
platformIPlatformAdaptermodelstringconfigGenerationConfigsafetySettingsICollection<SafetySetting>systemInstructionstringhttpClientHttpClientloggerILogger
GeminiModel(string, ModelParams, HttpClient?, ILogger?)
public GeminiModel(string apiKey, ModelParams modelParams, HttpClient? client = null, ILogger? logger = null)
Parameters
apiKeystringmodelParamsModelParamsclientHttpClientloggerILogger
Properties
Files
Represents a property to interact with files associated with the GeminiModel.
public FileClient? Files { get; set; }
Property Value
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
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
fileRemoteFileThe remote file whose state is being monitored.
maxSecondsintThe maximum number of seconds to wait for the file to become "Active".
cancellationTokenCancellationTokenAn 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
promptstringThe textual input used as the basis for content generation.
filePathstringThe path to the file that should be included in the content generation request.
cancellationTokenCancellationTokenA 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
fileIdstringThe unique identifier of the file whose metadata is to be retrieved.
cancellationTokenCancellationTokenAn 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
promptstringThe input text prompt used to guide the content generation process.
filePathstringThe local file path
cancellationTokenCancellationTokenA 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
filePathstringThe local path of the file to be uploaded.
progressCallbackAction<double>An optional callback to receive updates on upload progress as a percentage.
cancellationTokenCancellationTokenAn optional token to monitor for cancellation requests.
Returns
- Task<RemoteFile>
A RemoteFile object representing the uploaded file on the API.