Class GeminiManager
The class for accessing the Gemini API!
public class GeminiManager : Singleton<GeminiManager>
- Inheritance
-
GeminiManager
- Extension Methods
Fields
BaseServiceUri
The base URI to the Generative Language service.
public const string BaseServiceUri = "https://generativelanguage.googleapis.com"
Field Value
BetaApiUri
The v1 beta API URI to the Generative Language service.
public const string BetaApiUri = "https://generativelanguage.googleapis.com/v1beta"
Field Value
EmptyJsonObject
An empty JSON object.
private const string EmptyJsonObject = "{}"
Field Value
MultiPartFormDataSeperator
Seperator for Multi-Part Form Data.
private const string MultiPartFormDataSeperator = "xxxxxxxxxx"
Field Value
ProductionApiUri
The production v1 API URI to the Generative Language service.
public const string ProductionApiUri = "https://generativelanguage.googleapis.com/v1"
Field Value
_geminiApiKey
private string _geminiApiKey
Field Value
Methods
CheckWebRequest(UnityWebRequest)
Checks the given UnityWebRequest for errors.
private void CheckWebRequest(UnityWebRequest webRequest)
Parameters
webRequestUnityWebRequestThe request to check.
Exceptions
- GeminiRequestException
Thrown if the request was not successful.
ComputeRequest(IGeminiRequest, UnityWebRequest)
Sets up, sends and verifies a UnityWebRequest.
private Task ComputeRequest(IGeminiRequest request, UnityWebRequest webRequest)
Parameters
requestIGeminiRequestThe request data.
webRequestUnityWebRequestThe UnityWebRequest to compute.
Returns
ConfirmResponse(UnityWebRequest)
Checks if the downloaded response was empty, as to be expected of some endpoints.
private void ConfirmResponse(UnityWebRequest request)
Parameters
requestUnityWebRequestThe web request.
Exceptions
- GeminiResponseParsingException
Thrown if the response was not empty.
ConfirmResponse<TResponse>(UnityWebRequest)
Checks if the downloaded response was correct.
private TResponse ConfirmResponse<TResponse>(UnityWebRequest request)
Parameters
requestUnityWebRequestThe web request.
Returns
- TResponse
Type Parameters
TResponseThe expected response type.
Exceptions
- GeminiResponseParsingException
Thrown if the response could not be parsed.
Request(IGeminiDeleteRequest)
Computes a DELETE request on the Gemini API.
public Task Request(IGeminiDeleteRequest request)
Parameters
requestIGeminiDeleteRequestThe request object.
Returns
Exceptions
- GeminiRequestException
Thrown if the API request fails.
- GeminiResponseParsingException
Thrown if the response was not empty.
Request(IGeminiPostRequest)
Computes a POST request on the Gemini API.
public Task Request(IGeminiPostRequest request)
Parameters
requestIGeminiPostRequestThe request object.
Returns
Exceptions
- GeminiRequestException
Thrown if the API request fails.
- GeminiResponseParsingException
Thrown if the response was not empty.
Request<TResponse>(IGeminiGetRequest)
Computes a GET request on the Gemini API.
public Task<TResponse> Request<TResponse>(IGeminiGetRequest request)
Parameters
requestIGeminiGetRequestThe request object.
Returns
- Task<TResponse>
The computed response.
Type Parameters
TResponseThe response type. For example, a request of type GeminiChatRequest corresponds to a response type of GeminiChatResponse, and a request of type GeminiTokenCountRequest corresponds to a response of type GeminiTokenCountResponse.
Exceptions
- GeminiRequestException
Thrown if the API request fails.
- GeminiResponseParsingException
Thrown if the response could not be parsed.
Request<TResponse>(IGeminiMultiPartPostRequest)
Computes a multi-part POST request on the Gemini API.
public Task<TResponse> Request<TResponse>(IGeminiMultiPartPostRequest request)
Parameters
requestIGeminiMultiPartPostRequestThe request object.
Returns
- Task<TResponse>
The computed response.
Type Parameters
TResponseThe response type. For example, a request of type GeminiChatRequest corresponds to a response type of GeminiChatResponse, and a request of type GeminiTokenCountRequest corresponds to a response of type GeminiTokenCountResponse.
Exceptions
- GeminiRequestException
Thrown if the API request fails.
- GeminiResponseParsingException
Thrown if the response could not be parsed.
Request<TResponse>(IGeminiPatchRequest)
Computes a PATCH request on the Gemini API.
public Task<TResponse> Request<TResponse>(IGeminiPatchRequest request)
Parameters
requestIGeminiPatchRequestThe request object.
Returns
- Task<TResponse>
The computed response.
Type Parameters
TResponseThe response type. For example, a request of type GeminiChatRequest corresponds to a response type of GeminiChatResponse, and a request of type GeminiTokenCountRequest corresponds to a response of type GeminiTokenCountResponse.
Exceptions
- GeminiRequestException
Thrown if the API request fails.
- GeminiResponseParsingException
Thrown if the response could not be parsed.
Request<TResponse>(IGeminiPostRequest)
Computes a POST request on the Gemini API.
public Task<TResponse> Request<TResponse>(IGeminiPostRequest request)
Parameters
requestIGeminiPostRequestThe request object.
Returns
- Task<TResponse>
The computed response.
Type Parameters
TResponseThe response type. For example, a request of type GeminiChatRequest corresponds to a response type of GeminiChatResponse, and a request of type GeminiTokenCountRequest corresponds to a response of type GeminiTokenCountResponse.
Exceptions
- GeminiRequestException
Thrown if the API request fails.
- GeminiResponseParsingException
Thrown if the response could not be parsed.
SetApiKey(string)
Sets the Gemini API key.
public void SetApiKey(string apiKey)
Parameters
apiKeystringThe new API key.
SetupWebRequest(IGeminiRequest, UnityWebRequest)
Sets up the UnityWebRequest with API keys and disposal settings.
private void SetupWebRequest(IGeminiRequest request, UnityWebRequest webRequest)
Parameters
requestIGeminiRequestThe request data.
webRequestUnityWebRequestThe request to set up.
Exceptions
- GeminiOAuthException
Thrown if the request could not be authenticated.