Table of Contents

Class GeminiManager

Namespace
Uralstech.UGemini

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

string

BetaApiUri

The v1 beta API URI to the Generative Language service.

public const string BetaApiUri = "https://generativelanguage.googleapis.com/v1beta"

Field Value

string

EmptyJsonObject

An empty JSON object.

private const string EmptyJsonObject = "{}"

Field Value

string

MultiPartFormDataSeperator

Seperator for Multi-Part Form Data.

private const string MultiPartFormDataSeperator = "xxxxxxxxxx"

Field Value

string

ProductionApiUri

The production v1 API URI to the Generative Language service.

public const string ProductionApiUri = "https://generativelanguage.googleapis.com/v1"

Field Value

string

_geminiApiKey

private string _geminiApiKey

Field Value

string

Methods

CheckWebRequest(UnityWebRequest)

Checks the given UnityWebRequest for errors.

private void CheckWebRequest(UnityWebRequest webRequest)

Parameters

webRequest UnityWebRequest

The 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

request IGeminiRequest

The request data.

webRequest UnityWebRequest

The UnityWebRequest to compute.

Returns

Task

ConfirmResponse(UnityWebRequest)

Checks if the downloaded response was empty, as to be expected of some endpoints.

private void ConfirmResponse(UnityWebRequest request)

Parameters

request UnityWebRequest

The 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

request UnityWebRequest

The web request.

Returns

TResponse

Type Parameters

TResponse

The 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

request IGeminiDeleteRequest

The request object.

Returns

Task

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

request IGeminiPostRequest

The request object.

Returns

Task

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

request IGeminiGetRequest

The request object.

Returns

Task<TResponse>

The computed response.

Type Parameters

TResponse

The 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

request IGeminiMultiPartPostRequest

The request object.

Returns

Task<TResponse>

The computed response.

Type Parameters

TResponse

The 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

request IGeminiPatchRequest

The request object.

Returns

Task<TResponse>

The computed response.

Type Parameters

TResponse

The 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

request IGeminiPostRequest

The request object.

Returns

Task<TResponse>

The computed response.

Type Parameters

TResponse

The 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

apiKey string

The new API key.

SetupWebRequest(IGeminiRequest, UnityWebRequest)

Sets up the UnityWebRequest with API keys and disposal settings.

private void SetupWebRequest(IGeminiRequest request, UnityWebRequest webRequest)

Parameters

request IGeminiRequest

The request data.

webRequest UnityWebRequest

The request to set up.

Exceptions

GeminiOAuthException

Thrown if the request could not be authenticated.