Dsxir.Adapter behaviour (dsxir v0.1.0)

Copy Markdown

Adapter behaviour: turn a signature + inputs + demos into LM messages, and parse the LM response back into a typed field map.

Two implementations ship in v0:

Summary

Types

adapter_error()

lm_response()

@type lm_response() :: String.t()

messages()

@type messages() :: [Sycophant.Message.t()]

signature()

@type signature() :: module() | Dsxir.Signature.Compiled.t()

Callbacks

format(signature, map, list, keyword)

@callback format(signature(), map(), list(), keyword()) :: messages()

format_and_call(signature, map, list, keyword)

(optional)
@callback format_and_call(signature(), map(), list(), keyword()) ::
  {:ok, map(), Dsxir.LM.usage(), term()} | {:fallback, Exception.t()}

lm_mode()

(optional)
@callback lm_mode() :: :text | :object

parse(signature, arg2, keyword)

@callback parse(signature(), lm_response() | map(), keyword()) ::
  {:ok, map()} | {:error, adapter_error()}