"GoogleGemini" (Service Connection)
Connecting & Authenticating
Requests
Text
"Chat" — create a response for the given chat conversation
| "Messages" | (required) | a list of messages in the conversation | |
| "Model" | Automatic | name of the model to use | |
| "N" | Automatic | number of completions to return (1 to 8) | |
| "Temperature" | Automatic | sampling temperature (between 0 and 1) | |
| "TopProbabilities" | Automatic | sample only among the k highest-probability classes | |
| "TotalProbabilityCutoff" | None | sample among the most probable classes with an accumulated probability of at least p (nucleus sampling) |
"Embedding" — create an embedding vector representing the input text
| "Text" | (required) | a list of messages in the conversation | |
| "Model" | Automatic | name of the model to use |
"TokenCount" — run a model's tokenizer on a prompt and return the token count
| "Content" | (required) | name of the model to use | |
| "Model" | Automatic | name of the model to use |
Model Lists
"ChatModelList" — list models available for the "Chat" request
Examples
open all close allBasic Examples (1)
Scope (9)
Chat (6)
Respond to a chat containing multiple messages:
ServiceExecute["GoogleGemini", "Chat", {"Messages" -> {
<|"Role" -> "User", "Content" -> "tell me three colors"|>}}]Change the sampling temperature:
ServiceExecute["GoogleGemini", "Chat", {"Messages" -> {<|"Role" -> "User", "Content" -> "tell me three colors"|>}, "Temperature" -> 0}]ServiceExecute["GoogleGemini", "Chat", {"Messages" -> {<|"Role" -> "User", "Content" -> "say: the cat is on the mat"|>}, "StopTokens" -> {"cat"}}]Specify a maximum amount of tokens:
ServiceExecute["GoogleGemini", "Chat", {"Messages" -> {<|"Role" -> "User", "Content" -> "say: the cat is on the mat"|>}, "MaxTokens" -> 4}]Specify a cutoff on the total probability (nucleus sampling):
ServiceExecute["GoogleGemini", "Chat", {"Messages" -> {<|"Role" -> "User", "Content" -> "who are you?"|>}, "TotalProbabilityCutoff" -> .2}]//Lookup["Content"]Sample only among the top
tokens by probability:
ServiceExecute["GoogleGemini", "Chat", {"Messages" -> {<|"Role" -> "User", "Content" -> "who are you?"|>}, "TopProbabilities" -> 3}]//Lookup["Content"]Embedding (2)
Compute the vector embedding of some text:
ServiceExecute["GoogleGemini", "Embedding", {"Text" -> "ciao"}]//ShortCompute the distance between vector embeddings to find semantic similarities:
embeddings =
Table[
ServiceExecute["GoogleGemini", "Embedding", {"Text" -> text}],
{text, {"Paris", "London", "I love rock'n'roll"}}
];DistanceMatrix[embeddings]//MatrixPlotSee Also
ServiceExecute ▪ ServiceConnect ▪ LLMFunction ▪ LLMSynthesize ▪ ChatEvaluate ▪ LLMConfiguration
Service Connections: AlephAlpha ▪ Anthropic ▪ Cohere ▪ DeepSeek ▪ Groq ▪ MistralAI ▪ OpenAI ▪ TogetherAI
History
Introduced in 2024 (14.1)