Arcanum.Provider behaviour (arcanum v0.1.4)

Copy Markdown View Source

Behaviour for inference provider adapters.

Each adapter (Ollama, OpenAI, Anthropic, etc.) implements this behaviour to provide a uniform interface for chat completion, model listing, embeddings, and media generation.

All provider/model-specific serialization decisions are driven by ModelProfile.

Usage

use Arcanum.Provider

Optional callbacks (embed/3, generate_image/3, generate_video/3) return {:error, :not_supported} by default. Override only what the adapter supports.

Summary

Callbacks

Sends a chat completion request and returns the full response.

Generates embeddings for the given text input.

Generates images from a text prompt.

Generates videos from a text prompt.

Lists available models from the provider.

Sends a streaming chat completion request. Returns a stream of {:data, response} events, terminated by :done.

Types

stream_event()

@type stream_event() :: {:data, Arcanum.Response.t()} | {:error, term()} | :done

Callbacks

chat(provider, intent, profile)

@callback chat(
  provider :: map(),
  intent :: Arcanum.Intent.t(),
  profile :: Arcanum.ModelProfile.t()
) ::
  {:ok, Arcanum.Response.t()} | {:error, term()}

Sends a chat completion request and returns the full response.

embed(provider, model, input)

@callback embed(provider :: map(), model :: String.t(), input :: String.t()) ::
  {:ok, [float()]} | {:error, term()}

Generates embeddings for the given text input.

generate_image(provider, intent, profile)

@callback generate_image(
  provider :: map(),
  intent :: Arcanum.Intent.t(),
  profile :: Arcanum.ModelProfile.t()
) :: {:ok, Arcanum.Response.t()} | {:error, term()}

Generates images from a text prompt.

generate_video(provider, intent, profile)

@callback generate_video(
  provider :: map(),
  intent :: Arcanum.Intent.t(),
  profile :: Arcanum.ModelProfile.t()
) :: {:ok, Arcanum.Response.t()} | {:error, term()}

Generates videos from a text prompt.

list_models(provider)

@callback list_models(provider :: map()) :: {:ok, [String.t()]} | {:error, term()}

Lists available models from the provider.

stream(provider, intent, profile)

@callback stream(
  provider :: map(),
  intent :: Arcanum.Intent.t(),
  profile :: Arcanum.ModelProfile.t()
) ::
  {:ok, Enumerable.t()} | {:error, term()}

Sends a streaming chat completion request. Returns a stream of {:data, response} events, terminated by :done.