"GoogleGemini" (Service Connection)

This service connection requires an external account »

Use the Google Gemini API with the Wolfram Language.

Connecting & Authenticating

ServiceConnect["GoogleGemini"] creates a connection to the Google Gemini API. If a previously saved connection can be found, it will be used; otherwise, a new authentication request will be launched.
Use of this connection requires internet access and a Google account.

Requests

ServiceExecute["GoogleGemini","request",params] sends a request to the Google Gemini API using parameters params. The following gives possible requests.

Text

Request:

"Chat" create a response for the given chat conversation

Parameters:
  • "Messages"(required)a list of messages in the conversation
    "Model"Automaticname of the model to use
    "N"Automaticnumber of completions to return (1 to 8)
    "Temperature"Automaticsampling temperature (between 0 and 1)
    "TopProbabilities"Automaticsample only among the k highest-probability classes
    "TotalProbabilityCutoff"Nonesample among the most probable classes with an accumulated probability of at least p (nucleus sampling)
  • Request:

    "Embedding" create an embedding vector representing the input text

    Parameters:
  • "Text"(required)a list of messages in the conversation
    "Model"Automaticname of the model to use
  • Request:

    "TokenCount" run a model's tokenizer on a prompt and return the token count

    Parameters:
  • "Content"(required)name of the model to use
    "Model"Automaticname of the model to use
  • Model Lists

    Request:

    "ChatModelList" list models available for the "Chat" request

    Examples

    open allclose all

    Basic Examples  (1)

    Create a new connection:

    Generate a response from a chat:

    Scope  (9)

    Chat  (6)

    Respond to a chat containing multiple messages:

    Change the sampling temperature:

    Specify stop tokens:

    Specify a maximum amount of tokens:

    Specify a cutoff on the total probability (nucleus sampling):

    Sample only among the top tokens by probability:

    Embedding  (2)

    Compute the vector embedding of some text:

    Compute the distance between vector embeddings to find semantic similarities:

    TokenCount  (1)

    Get a token count for a string prompt: