Class GenAI
- Namespace
- GenerativeAI
- Assembly
- GenerativeAI.dll
Represents the base class for generative AI services. This class provides a framework for generative AI capabilities, including the management of AI models, creation of generative and embedding models, and interacting with generative AI infrastructure.
public abstract class GenAI
- Inheritance
-
GenAI
- Derived
- Inherited Members
- Extension Methods
Constructors
GenAI(IPlatformAdapter, HttpClient?, ILogger?)
Initializes a new instance of the GenAI class.
protected GenAI(IPlatformAdapter platformAdapter, HttpClient? client = null, ILogger? logger = null)
Parameters
platformAdapterIPlatformAdapterThe platform adapter for API communication.
clientHttpClientOptional HTTP client for API requests.
loggerILoggerOptional logger for diagnostic output.
Properties
BatchClient
Gets the instance of the BatchClient class for batch processing operations. This property provides access to functionality for creating, managing, and monitoring batch jobs for content generation and embedding operations.
public BatchClient BatchClient { get; }
Property Value
HttpClient
Gets the underlying HttpClient instance used to perform HTTP requests to Google's AI platform. This property allows for custom configuration of network communication, including request headers, timeouts, and other HTTP-specific settings, enabling seamless interaction with Google's generative and embedding models.
protected HttpClient? HttpClient { get; }
Property Value
Logger
Gets the logger instance used by the GoogleAi class for logging diagnostic messages, errors, and other runtime information. This property provides a mechanism to track and debug the internal operations of the class and its related components.
protected ILogger? Logger { get; }
Property Value
ModelClient
Gets the instance of the ModelClient class associated with the GoogleAi instance. This property allows access to functionality for interacting with the Gemini API Models endpoint, enabling operations such as retrieving and listing AI models.
public ModelClient ModelClient { get; }
Property Value
Platform
Gets the underlying platform adapter instance utilized by the GoogleAi class. This property provides essential platform-specific functionality, such as URL generation, authorization handling, and API versioning, enabling seamless communication with Google's generative AI services.
protected IPlatformAdapter Platform { get; }
Property Value
Methods
CreateAgentsClient()
Creates a client for the managed Agents API.
public AgentsClient CreateAgentsClient()
Returns
- AgentsClient
An AgentsClient that uses this instance's platform, HTTP client and logger.
CreateCredentialsClient()
Creates a client for the Credentials API (secrets used by agent environments).
public CredentialsClient CreateCredentialsClient()
Returns
- CredentialsClient
A CredentialsClient that uses this instance's platform, HTTP client and logger.
CreateDecisionsClient()
Creates a client for the Decisions API (structured yes/no, choice and score questions).
public DecisionsClient CreateDecisionsClient()
Returns
- DecisionsClient
A DecisionsClient that uses this instance's platform, HTTP client and logger.
CreateEmbeddingModel(string)
Creates and initializes an embedding model for use in embedding-related AI tasks. The created model is configured with the provided model name and integrates with the underlying platform adapter.
public EmbeddingModel CreateEmbeddingModel(string modelName)
Parameters
modelNamestringThe name of the embedding model to initialize, used to identify the specific AI model for embeddings.
Returns
- EmbeddingModel
An instance of EmbeddingModel initialized with the specified model name and platform configurations.
CreateEnvironmentsClient()
Creates a client for the Environments API (agent sandbox environments and their workspace files).
public EnvironmentsClient CreateEnvironmentsClient()
Returns
- EnvironmentsClient
An EnvironmentsClient that uses this instance's platform, HTTP client and logger.
CreateGenerativeModel(string, GenerationConfig?, ICollection<SafetySetting>?, string?)
Creates and initializes a generative model for use with Google's generative AI platform. This method allows the specification of model configuration, safety settings, and system-level instructions for controlling model behavior.
public virtual GenerativeModel CreateGenerativeModel(string modelName, GenerationConfig? config = null, ICollection<SafetySetting>? safetyRatings = null, string? systemInstruction = null)
Parameters
modelNamestringThe name of the generative model to initialize.
configGenerationConfigOptional configuration settings for generation, such as temperature, max tokens, or other generation parameters.
safetyRatingsICollection<SafetySetting>Optional safety settings to define behavior constraints or safety parameters for the generative model.
systemInstructionstringOptional system-wide instruction to apply when the model processes requests or generates responses.
Returns
- GenerativeModel
An instance of GenerativeModel configured with the specified parameters.
CreateImageModel(string)
Creates and initializes an image generation model for use with the Imagen image generation API. This method configures the model to generate images based on provided prompts or inputs.
public ImagenModel CreateImageModel(string modelName)
Parameters
modelNamestringThe name of the image generation model to initialize.
Returns
- ImagenModel
An instance of ImagenModel configured for generating images using the specified model name.
CreateInteractionsClient()
Creates a client for the Interactions API (stateful model and agent interactions such as Deep Research and Antigravity, with background execution, streaming and continuation).
public InteractionsClient CreateInteractionsClient()
Returns
- InteractionsClient
An InteractionsClient that uses this instance's platform, HTTP client and logger.
CreateTriggersClient()
Creates a client for the Triggers API (scheduled agent interactions).
public TriggersClient CreateTriggersClient()
Returns
- TriggersClient
A TriggersClient that uses this instance's platform, HTTP client and logger.
CreateTuningClient()
Creates a client for model tuning (Vertex AI tuning jobs or Gemini API tuned models).
public TuningClient CreateTuningClient()
Returns
- TuningClient
A TuningClient that uses this instance's platform, HTTP client and logger.
CreateVoicesClient()
Creates a client for the Voices API (voice design, remixing and replication for text-to-speech).
public VoicesClient CreateVoicesClient()
Returns
- VoicesClient
A VoicesClient that uses this instance's platform, HTTP client and logger.
CreateWebhooksClient()
Creates a client for the Webhooks API (event notifications for batch jobs, interactions and video generation, plus signing secret rotation).
public WebhooksClient CreateWebhooksClient()
Returns
- WebhooksClient
A WebhooksClient that uses this instance's platform, HTTP client and logger.
GetModelAsync(string, CancellationToken)
Retrieves a specific AI model by its name asynchronously from the Google's AI platform.
public Task<Model> GetModelAsync(string modelName, CancellationToken cancellationToken = default)
Parameters
modelNamestringThe unique name of the model to retrieve.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- Task<Model>
A task representing the asynchronous operation, containing the requested model details as a Model object.
GetPlatformAdapter()
Retrieves the platform adapter associated with this instance. The platform adapter provides core functionalities, such as authorization, URL creation, and API version management, for interacting with the underlying platform.
public IPlatformAdapter GetPlatformAdapter()
Returns
- IPlatformAdapter
The platform adapter instance implementing IPlatformAdapter.
ListModelsAsync(int?, string?, CancellationToken)
Asynchronously retrieves a list of AI models available in Google's AI platform. This method supports pagination to fetch models in batches using the specified page size and page token, enabling efficient handling of large model datasets.
public Task<ListModelsResponse> ListModelsAsync(int? pageSize = null, string? pageToken = null, CancellationToken cancellationToken = default)
Parameters
pageSizeint?Optional parameter specifying the maximum number of models to retrieve per page. Defaults to null for the API's standard page size.
pageTokenstringOptional parameter indicating the token for the next page of results, as provided in a previous response.
cancellationTokenCancellationTokenOptional parameter for propagating cancellation signals, allowing the operation to be canceled if needed.
Returns
- Task<ListModelsResponse>
A task representing the asynchronous operation, which contains a ListModelsResponse with the retrieved models and pagination details.