Gemini.Types.Operation (GeminiEx v0.8.2)
View SourceType definitions for long-running operations.
Long-running operations are used for tasks that may take significant time to complete, such as video generation, file imports, model tuning, and batch processing.
Operation Lifecycle
- Initiated - Operation is created,
done: false - Running - Operation is processing,
done: false - Completed - Operation finished successfully,
done: true,responsepopulated - Failed - Operation failed,
done: true,errorpopulated
Polling Pattern
{:ok, operation} = some_long_running_call()
# Poll until complete
{:ok, completed} = Gemini.APIs.Operations.wait(operation.name,
poll_interval: 5000,
timeout: 300_000
)
case completed do
%{done: true, error: nil, response: response} ->
IO.puts("Success: #{inspect(response)}")
%{done: true, error: error} ->
IO.puts("Failed: #{error.message}")
endExample
# Video generation returns an operation
{:ok, op} = Gemini.generate_video("A cat playing piano")
# Wait for completion
{:ok, completed} = Gemini.APIs.Operations.wait(op.name)
# Get the result
video_uri = completed.response["generatedVideos"]
Summary
Functions
Checks if the operation is complete (successfully or failed).
Checks if the operation failed.
Creates an Operation from API response.
Extracts the operation ID from the full name.
Gets the progress percentage from metadata, if available.
Checks if the operation is still running.
Checks if the operation completed successfully.
Types
@type operation_error() :: %{ optional(:code) => integer(), optional(:message) => String.t(), optional(:details) => [map()] }
Operation error details.
@type t() :: %Gemini.Types.Operation{ done: boolean(), error: operation_error() | nil, metadata: map() | nil, name: String.t() | nil, response: map() | nil }
Represents a long-running operation.
Fields
name- Server-assigned unique identifier (e.g., "operations/abc123")metadata- Service-specific metadata about the operation progressdone- Whether the operation is complete (true = finished, false = in progress)error- Error result if the operation failed (mutually exclusive with response)response- Success result if the operation completed (mutually exclusive with error)
Functions
Checks if the operation is complete (successfully or failed).
Checks if the operation failed.
Creates an Operation from API response.
Parameters
response- Map from API response with string keys
Examples
response = %{
"name" => "operations/abc123",
"done" => false,
"metadata" => %{"@type" => "...", "progress" => 50}
}
op = Gemini.Types.Operation.from_api_response(response)
Extracts the operation ID from the full name.
Examples
op = %Operation{name: "operations/abc123"}
Operation.get_id(op)
# => "abc123"
Gets the progress percentage from metadata, if available.
Returns nil if progress information is not available in metadata.
Checks if the operation is still running.
Checks if the operation completed successfully.