LemonAi.Provider behaviour (lemon_ai v0.1.0)

View Source

Behaviour for LLM provider implementations.

Each provider (Anthropic, OpenAI, Google, etc.) implements this behaviour to provide a unified streaming interface.

Implementing a Provider

defmodule LemonAi.Providers.Anthropic do
  @behaviour LemonAi.Provider

  @impl true
  def stream(model, context, opts) do
    # Implementation...
  end
end

Summary

Callbacks

API identifier atom.

Get the API key from environment variables for this provider.

Provider identifier atom.

Start streaming a response from the provider.

Callbacks

api_id()

@callback api_id() :: atom()

API identifier atom.

get_env_api_key()

(optional)
@callback get_env_api_key() :: String.t() | nil

Get the API key from environment variables for this provider.

provider_id()

@callback provider_id() :: atom()

Provider identifier atom.

stream(t, t, t)

Start streaming a response from the provider.

Returns an EventStream that emits events as the response is generated. The caller should consume events using EventStream.events/1 or wait for the final result with EventStream.result/1.