View Source Nexlm.Providers.Google (Nexlm v0.1.5)

Provider implementation for Google's Gemini API.

Model Names

Models should be prefixed with "google/", for example:

  • "google/gemini-1.5-flash-latest"
  • "google/gemini-1.5-pro-latest"

Message Formats

Supports the following message types:

  • Text messages: Simple string content
  • System messages: Special instructions using systemInstruction format
  • Image messages: Base64 encoded images with mime type

Configuration

Required:

  • API key in runtime config (:nexlm, Nexlm.Providers.Google, api_key: "key")
  • Model name in request

Optional:

  • temperature: Float between 0 and 1 (default: 0.0)
  • max_tokens: Integer for response length limit
  • top_p: Float between 0 and 1 (default: 0.95)

Examples

# Simple text completion
config = Google.init(model: "google/gemini-1.5-flash-latest")
messages = [%{"role" => "user", "content" => "Hello"}]
{:ok, response} = Google.call(config, messages)

# With system instruction
messages = [
  %{"role" => "system", "content" => "You are a helpful assistant"},
  %{"role" => "user", "content" => "Hello"}
]

# With image input
messages = [
  %{
    "role" => "user",
    "content" => [
      %{"type" => "text", "text" => "What's in this image?"},
      %{
        "type" => "image",
        "mime_type" => "image/jpeg",
        "data" => "base64_encoded_data"
      }
    ]
  }
]

Safety Settings

Default safety settings are applied to prevent harmful content:

  • HARM_CATEGORY_HATE_SPEECH
  • HARM_CATEGORY_DANGEROUS_CONTENT
  • HARM_CATEGORY_SEXUALLY_EXPLICIT
  • HARM_CATEGORY_HARASSMENT