View Source GoogleAI.Content (google_ai v0.1.1)
The module provides an implementation of the Google AI content generation APIs. The API reference can be found at https://ai.google.dev/tutorials/rest_quickstart.
Summary
Types
The structure of a GoogleAI count tokens response.
Options that allow the configuration of the model output.
The structure of a Google content generation request.
The structure of a GoogleAI embedding response.
The message role assigned to the content.
A list of safety settings for the model.
Functions
Generates a model completion for a given prompt or conversation.
Counts the number of tokens in the given prompt
using the given model.
Generates a model completion for a given prompt or conversation.
Types
The structure of a GoogleAI count tokens response.
Has the following format:
%{
"totalTokens" => 8
}
@type generation_config() :: %{ optional(:candidateCount) => integer(), optional(:stopSequences) => [String.t()], optional(:maxOutputTokens) => integer(), optional(:temperature) => float(), optional(:topP) => float(), optional(:topK) => float() }
Options that allow the configuration of the model output.
@type generation_request() :: %{ :contents => [%{optional(:role) => role(), parts: [%{text: String.t()}]}], optional(:generationConfig) => generation_config(), optional(:safetySettings) => safety_settings() }
The structure of a Google content generation request.
@type generation_response() :: %{ required(String.t()) => [ %{ required(String.t()) => %{ required(String.t()) => String.t(), required(String.t()) => [%{required(String.t()) => String.t()}] }, required(String.t()) => String.t() } ] }
The structure of a GoogleAI embedding response.
Has the following format:
%{
"candidates" => [
%{
"content" => %{
"role" => "model",
"parts" => [
%{
"text" => "This is a test."
}
]
},
"finishReason" => "STOP",
"index" => 0,
}
]
}
@type role() :: :user | :model
The message role assigned to the content.
A list of safety settings for the model.
Functions
@spec count_tokens(GoogleAI.Model.t(), String.t()) :: GoogleAI.Http.response(count_tokens_response())
Generates a model completion for a given prompt or conversation.
Counts the number of tokens in the given prompt
using the given model.
Arguments
:model
- TheGoogleAI.Model
to use for this request.:prompt
- The text prompt to count the tokens in.
Returns
A map containing the fields of the content tokens response.
See https://ai.google.dev/tutorials/rest_quickstart#count_tokens.
@spec generate(GoogleAI.Model.t(), String.t(), Keyword.t()) :: GoogleAI.Http.response(generation_response())
Generates a model completion for a given prompt or conversation.
Arguments
:model
- TheGoogleAI.Model
to use for this request.:prompt
- The text-only input or multi-turn conversation to send as a prompt to the AI model.:opts
- A keyword list of options that can be used to configure the request.
Returns
A map containing the fields of the content generation response.
See https://ai.google.dev/tutorials/rest_quickstart#text-only_input.