Inference.Adapter behaviour (inference v0.2.0)

Copy Markdown View Source

Behaviour implemented by inference adapter modules.

Direct provider adapters use the default :explicit credential mode. A managed authority adapter must explicitly report :managed_materialization and owns lease redemption and transient provider material outside this package.

Summary

Callbacks

Reports what this adapter can do for the given client's provider binding.

Functions

Resolves the capabilities of a configured client.

Reports an adapter's credential mode; existing direct adapters are explicit.

Returns the closed set of credential modes.

Returns the closed set of valid provider kinds.

Reports whether a value belongs to the closed provider-kind set.

Types

credential_mode()

@type credential_mode() :: :explicit | :managed_materialization

provider_kind()

@type provider_kind() :: :model_endpoint | :local_model_endpoint | :agent_session

Callbacks

capabilities(t)

(optional)
@callback capabilities(Inference.Client.t()) :: [Inference.Capability.t()]

Reports what this adapter can do for the given client's provider binding.

Adapters that can answer capability questions implement this callback; the answer must come from a real provider feature declaration, never a guess.

complete(t, t)

@callback complete(Inference.Client.t(), Inference.Request.t()) ::
  {:ok, Inference.Response.t()} | {:error, Inference.Error.t()}

credential_mode()

(optional)
@callback credential_mode() :: credential_mode()

provider_kind()

@callback provider_kind() :: provider_kind()

stream(t, t)

(optional)
@callback stream(Inference.Client.t(), Inference.Request.t()) ::
  {:ok, Enumerable.t()} | {:error, Inference.Error.t()}

Functions

capabilities(client)

@spec capabilities(Inference.Client.t()) :: [Inference.Capability.t()]

Resolves the capabilities of a configured client.

Adapters that implement capabilities/1 answer for their provider binding. Adapters that do not fall back to the client's declared capabilities.

credential_mode(adapter)

@spec credential_mode(module()) :: credential_mode() | :invalid

Reports an adapter's credential mode; existing direct adapters are explicit.

credential_modes()

@spec credential_modes() :: [credential_mode()]

Returns the closed set of credential modes.

provider_kinds()

@spec provider_kinds() :: [provider_kind()]

Returns the closed set of valid provider kinds.

valid_provider_kind?(kind)

@spec valid_provider_kind?(term()) :: boolean()

Reports whether a value belongs to the closed provider-kind set.