Gemini.Live.Message (GeminiEx v0.8.2)

View Source

Message types for Gemini Live API WebSocket communication.

This module defines the structure of messages sent to and received from the Gemini Live API WebSocket endpoint.

Message Flow

  1. Client sends setup message to configure the session
  2. Server responds with setupComplete
  3. Client sends content via clientContent or realtimeInput
  4. Server responds with serverContent containing model responses
  5. Client can send toolResponse to respond to function calls

Example

# Setup message
setup = %ClientMessage{
  setup: %LiveClientSetup{
    model: "gemini-2.0-flash-exp",
    generation_config: %{temperature: 0.8}
  }
}

# Client content message
content = %ClientMessage{
  client_content: %{
    turns: [%{role: "user", parts: [%{text: "Hello!"}]}],
    turn_complete: true
  }
}

Summary

Functions

Convert API map to ServerMessage struct.

Parse JSON from WebSocket into ServerMessage.

Convert ClientMessage to API map format.

Convert ClientMessage to JSON for WebSocket transmission.

Functions

from_api_map(data)

@spec from_api_map(map()) :: Gemini.Live.Message.ServerMessage.t()

Convert API map to ServerMessage struct.

from_json(json)

@spec from_json(String.t()) ::
  {:ok, Gemini.Live.Message.ServerMessage.t()} | {:error, term()}

Parse JSON from WebSocket into ServerMessage.

to_api_map(client_message)

@spec to_api_map(Gemini.Live.Message.ClientMessage.t()) :: map()

Convert ClientMessage to API map format.

to_json(message)

@spec to_json(Gemini.Live.Message.ClientMessage.t()) ::
  {:ok, String.t()} | {:error, term()}

Convert ClientMessage to JSON for WebSocket transmission.