GenAI.Helpers (GenAI Core v0.1.1)
A collection of helper functions for VNextGenAI.
Link to this section Summary
Link to this section Functions
Link to this function
on_error(response, action, value)
Handle error tuple response.
examples
Examples
iex> {:ok, :return_me} |> GenAI.Helpers.on_error(:label, :unexpected)
iex> {:ok, nil} |> GenAI.Helpers.on_error(:label, :unexpected)
iex> {:error, :foo} |> GenAI.Helpers.on_error(:return_value, :bar)
iex> {:error, :foo} |> GenAI.Helpers.on_error(:return_error, :bar)
iex> {:error, :foo} |> GenAI.Helpers.on_error(:return, :bar) :bar
iex> {:error, :foo} |> GenAI.Helpers.on_error(:call, fn -> :biz end) :biz
iex> {:error, :foo} |> GenAI.Helpers.on_error(:call, fn x -> {:biz, x} end) {:biz, {:error, :foo}}
iex> {:error, :foo} |> GenAI.Helpers.on_error(:label, :wrap) {:error, {:wrap, :foo}}
Link to this function
on_nil(response, action, value)
Handle {:ok, nil} tuple response. ## Examples
iex> {:ok, 5} |> GenAI.Helpers.on_nil(:label, :unexpected)
{:ok, 5}
iex> {:ok, nil} |> GenAI.Helpers.on_nil(:return_value, :bar)
{:ok, :bar}
iex> {:ok, nil} |> GenAI.Helpers.on_nil(:return_error, :bar)
{:error, :bar}
iex> {:ok, nil} |> GenAI.Helpers.on_nil(:return, :bar)
:bar
iex> {:ok, nil} |> GenAI.Helpers.on_nil(:call, fn -> :biz end)
:biz
iex> {:ok, nil} |> GenAI.Helpers.on_nil(:label, :wrap)
{:error, {:wrap, :is_nil}}
iex> {:error, :foo} |> GenAI.Helpers.on_nil(:label, :wrap)
{:error, :foo}