Gemini.Config (GeminiEx v0.2.1)

View Source

Unified configuration management for both Gemini and Vertex AI authentication.

Supports multiple authentication strategies:

  • Gemini: API key authentication
  • Vertex AI: OAuth2 or Service Account authentication

Summary

Functions

Get the API key from environment or application config. (Legacy function for backward compatibility)

Get the authentication configuration.

Get the base URL for the current authentication type. (Legacy function - now determined by auth strategy)

Get the default model to use.

Detect authentication type based on environment variables.

Detect authentication type based on configuration map.

Get configuration based on environment variables and application config. Returns a structured configuration map.

Get configuration with overrides.

Get authentication configuration for a specific strategy.

Get a model name by its key or return the string if it's already a model name.

Check if a model key exists.

Get all available model definitions.

Check if telemetry is enabled.

Get HTTP timeout in milliseconds.

Validate that required configuration is present.

Types

auth_config()

@type auth_config() :: %{type: :gemini | :vertex_ai, credentials: map()}

Functions

api_key()

Get the API key from environment or application config. (Legacy function for backward compatibility)

auth_config()

Get the authentication configuration.

Returns a map with the authentication type and credentials. Priority order:

  1. Environment variables
  2. Application configuration
  3. Default to Gemini with API key

base_url()

Get the base URL for the current authentication type. (Legacy function - now determined by auth strategy)

default_model()

Get the default model to use.

detect_auth_type()

Detect authentication type based on environment variables.

detect_auth_type(map)

Detect authentication type based on configuration map.

get()

Get configuration based on environment variables and application config. Returns a structured configuration map.

get(overrides)

Get configuration with overrides.

get_auth_config(arg1)

@spec get_auth_config(:gemini | :vertex_ai) :: map()

Get authentication configuration for a specific strategy.

Parameters

  • strategy: The authentication strategy (:gemini or :vertex_ai)

Returns

  • A map containing configuration for the specified strategy
  • Returns empty map if no configuration found

Examples

iex> Gemini.Config.get_auth_config(:gemini)
%{api_key: "your_api_key"}

iex> Gemini.Config.get_auth_config(:vertex_ai)
%{project_id: "your-project", location: "us-central1"}

get_model(model_key)

@spec get_model(atom() | String.t()) :: String.t()

Get a model name by its key or return the string if it's already a model name.

Examples

iex> Gemini.Config.get_model(:flash_2_0)
"gemini-2.0-flash"

iex> Gemini.Config.get_model("gemini-1.5-pro")
"gemini-1.5-pro"

iex> Gemini.Config.get_model(:default)
"gemini-2.0-flash"

has_model?(model_key)

@spec has_model?(atom()) :: boolean()

Check if a model key exists.

Examples

iex> Gemini.Config.has_model?(:flash_2_0)
true

iex> Gemini.Config.has_model?(:unknown)
false

models()

@spec models() :: map()

Get all available model definitions.

Returns

A map of model keys to model names.

telemetry_enabled?()

@spec telemetry_enabled?() :: boolean()

Check if telemetry is enabled.

Determines whether telemetry events should be emitted based on the application configuration. Telemetry is enabled by default unless explicitly disabled.

Configuration

Set :telemetry_enabled to false in your application config to disable:

config :gemini, telemetry_enabled: false

Returns

  • true - Telemetry is enabled (default)
  • false - Telemetry is explicitly disabled

Examples

iex> # Default behavior (telemetry enabled)
iex> Gemini.Config.telemetry_enabled?()
true

iex> # Explicitly disabled
iex> Application.put_env(:gemini, :telemetry_enabled, false)
iex> Gemini.Config.telemetry_enabled?()
false

iex> # Any other value defaults to enabled
iex> Application.put_env(:gemini, :telemetry_enabled, :maybe)
iex> Gemini.Config.telemetry_enabled?()
true

timeout()

Get HTTP timeout in milliseconds.

validate!()

Validate that required configuration is present.