Class GoogleAIPlatformAdapter
- Namespace
- GenerativeAI
- Assembly
- GenerativeAI.dll
The GoogleAIPlatformAdapter class provides an implementation of the IPlatformAdapter interface to integrate with Google AI Generative API. It handles authorization, URL generation, and credential management for making requests to the Google AI platform.
public class GoogleAIPlatformAdapter : IPlatformAdapter
- Inheritance
-
GoogleAIPlatformAdapter
- Implements
- Inherited Members
- Extension Methods
Constructors
GoogleAIPlatformAdapter(string?, string?, string?, IGoogleAuthenticator?, bool, ILogger?)
public GoogleAIPlatformAdapter(string? googleApiKey, string? apiVersion = null, string? accessToken = null, IGoogleAuthenticator? authenticator = null, bool validateAccessToken = true, ILogger? logger = null)
Parameters
googleApiKeystringapiVersionstringaccessTokenstringauthenticatorIGoogleAuthenticatorvalidateAccessTokenboolloggerILogger
Properties
Authenticator
Gets or sets the authenticator used for handling Google API authentication.
public IGoogleAuthenticator? Authenticator { get; set; }
Property Value
Credentials
Gets the credentials used for authentication when making requests to the Google AI platform. This property provides an instance of GoogleAICredentials which encapsulates the API key and optionally an access token required for authorization.
public GoogleAICredentials Credentials { get; }
Property Value
DefaultApiVersion
Gets or sets the default API version used for constructing API request URLs in the integration with the Google AI platform. This property must be set to a valid version string defined in ApiVersions.
public string DefaultApiVersion { get; set; }
Property Value
Methods
AddAuthorizationAsync(HttpRequestMessage, bool, CancellationToken)
Adds the necessary authorization headers to the given HTTP request.
public Task AddAuthorizationAsync(HttpRequestMessage request, bool requireAccessToken, CancellationToken cancellationToken = default)
Parameters
requestHttpRequestMessageThe HTTP request to which authorization headers will be added.
requireAccessTokenboolSpecifies whether an access token is required for the request.
cancellationTokenCancellationTokenThe cancellation token to cancel the operation.
Returns
- Task
A task that represents the asynchronous operation.
AuthorizeAsync(CancellationToken)
Authorizes the user by acquiring necessary tokens or credentials.
public Task AuthorizeAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token to cancel the operation.
Returns
- Task
A task that represents the asynchronous operation.
CreateUrlForModel(string, string)
Constructs a URL for a specific AI model operation.
public string CreateUrlForModel(string modelId, string task)
Parameters
modelIdstringThe unique identifier of the model.
taskstringThe specific task for the model (e.g., training or evaluation).
Returns
- string
The constructed URL as a string.
CreateUrlForTunedModel(string, string)
Constructs a URL for operations involving a fine-tuned model.
public string CreateUrlForTunedModel(string modelId, string task)
Parameters
modelIdstringThe unique identifier of the fine-tuned model.
taskstringThe specific task involving the fine-tuned model.
Returns
- string
The constructed URL as a string.
GetAccessTokenAsync(CancellationToken)
Retrieves the access token required for making authenticated API requests.
public Task<AuthTokens?> GetAccessTokenAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token to cancel the operation if needed.
Returns
- Task<AuthTokens>
A task that represents the asynchronous operation, containing the authentication tokens.
GetApiVersion()
Retrieves the current API version used by the platform.
public string GetApiVersion()
Returns
- string
The API version as a string.
GetApiVersionForFile()
Retrieves the API version related to file operations.
public string GetApiVersionForFile()
Returns
- string
The API version for file operations.
GetBaseUrl(bool, bool, bool, bool)
Retrieves the base URL of the platform's API.
public string GetBaseUrl(bool appendVersion = true, bool appendPublisher = true, bool appendLocation = true, bool appendProject = true)
Parameters
appendVersionboolDetermines whether to append the API version to the URL.
appendPublisherboolDetermines whether to append the publisher identifier to the URL.
appendLocationboolappendProjectbool
Returns
- string
The base URL as a string.
GetBaseUrlForFile()
Retrieves the base URL for file-related API operations.
public string GetBaseUrlForFile()
Returns
- string
The base URL for file operations as a string.
GetFullyQualifiedModelName(string, bool)
Gets the formatted model name for multi-modal live sessions.
public string? GetFullyQualifiedModelName(string modelName, bool appendLocation = true)
Parameters
modelNamestringThe base model name to format.
appendLocationboolWhether to include the location segment in the qualified name.
Returns
- string
The formatted model name for multi-modal live sessions, or null if not applicable.
GetMultiModalLiveUrl(string)
Gets the WebSocket URL for multi-modal live sessions.
public string GetMultiModalLiveUrl(string version = "v1alpha")
Parameters
versionstringThe API version to use (default: "v1alpha").
Returns
- string
The WebSocket URL for multi-modal live sessions.
SetAuthenticator(IGoogleAuthenticator)
Sets the Google authenticator responsible for managing authentication processes for Google services.
public void SetAuthenticator(IGoogleAuthenticator authenticator)
Parameters
authenticatorIGoogleAuthenticatorThe Google authenticator to be used for handling authentication operations.
ValidateCredentialsAsync(bool, CancellationToken)
public Task ValidateCredentialsAsync(bool requireAccessToken, CancellationToken cancellationToken = default)
Parameters
requireAccessTokenboolcancellationTokenCancellationToken
Returns
ValidateCredentialsAsync(CancellationToken)
Validates user credentials before making API requests.
public Task ValidateCredentialsAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token to cancel the operation.
Returns
- Task
A task that represents the asynchronous operation.