View Source GoogleAI.Content (google_ai v0.1.0)

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

Link to this type

count_tokens_response()

View Source
@type count_tokens_response() :: %{required(String.t()) => integer()}

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.

@type safety_settings() :: [%{category: String.t(), threshold: String.t()}]

A list of safety settings for the model.

Functions

Link to this function

count_tokens(model, prompt)

View Source

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 - The GoogleAI.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.

Link to this function

generate(model, prompt, opts \\ [])

View Source

Generates a model completion for a given prompt or conversation.

Arguments

  • :model - The GoogleAI.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.