ElixirScope.AI.LLM.Response (elixir_scope v0.0.1)

Standardized response format for LLM providers.

This module defines a common response structure that all providers (Gemini, Mock, future providers) must return, ensuring consistent handling throughout ElixirScope.

Summary

Functions

Gets the error message, returning nil for successful responses.

Gets the response text, returning empty string for errors.

Checks if the response is successful.

Types

t()

@type t() :: %ElixirScope.AI.LLM.Response{
  confidence: float(),
  error: String.t() | nil,
  metadata: map(),
  provider: atom(),
  success: boolean(),
  text: String.t(),
  timestamp: DateTime.t()
}

Functions

error(error_message, provider, metadata \\ %{})

@spec error(String.t(), atom(), map()) :: t()

Creates an error response.

Examples

iex> ElixirScope.AI.LLM.Response.error("API timeout", :gemini)
%ElixirScope.AI.LLM.Response{
  text: "",
  confidence: 0.0,
  provider: :gemini,
  success: false,
  error: "API timeout"
}

get_error(response)

@spec get_error(t()) :: String.t() | nil

Gets the error message, returning nil for successful responses.

get_text(response)

@spec get_text(t()) :: String.t()

Gets the response text, returning empty string for errors.

success(text, confidence \\ 1.0, provider, metadata \\ %{})

@spec success(String.t(), float(), atom(), map()) :: t()

Creates a successful response.

Examples

iex> ElixirScope.AI.LLM.Response.success("Analysis complete", 0.95, :gemini)
%ElixirScope.AI.LLM.Response{
  text: "Analysis complete",
  confidence: 0.95,
  provider: :gemini,
  success: true,
  error: nil
}

success?(response)

@spec success?(t()) :: boolean()

Checks if the response is successful.