Cantrip.LLM behaviour (Cantrip v1.3.3)

Copy Markdown View Source

Implement this behaviour to provide a model backend. The runtime calls query/2 with a normalized request and expects a normalized response or an error tuple with updated provider state.

LLM behaviour and contract validator.

Summary

Functions

Resolve the configured LLM from the process environment.

Types

request()

@type request() :: map()

response()

@type response() :: Cantrip.LLM.Response.t()

Callbacks

query(state, request)

@callback query(state :: term(), request()) ::
  {:ok, response() | map(), term()} | {:error, term(), term()}

Functions

from_env(opts \\ [])

@spec from_env(keyword() | map()) :: {:ok, {module(), map()}} | {:error, String.t()}

Resolve the configured LLM from the process environment.

ReqLLM is the only built-in provider adapter. CANTRIP_LLM_PROVIDER selects the ReqLLM provider prefix and defaults to openai_compatible. Provider-specific env vars override the generic CANTRIP_* values.

request(module, state, req)

@spec request(module(), term(), request()) ::
  {:ok, Cantrip.LLM.Response.t(), term()} | {:error, term(), term()}

validate_response(response)

@spec validate_response(Cantrip.LLM.Response.t()) :: :ok | {:error, String.t()}