Dsxir. LM behaviour
(dsxir v0.1.0)
Copy Markdown
Behaviour for LM providers.
Predictors and adapters issue LM requests through this contract; they never reach
into a specific provider SDK directly. The active impl plus its config live in
Dsxir.Settings under :lm as a {impl_module, config :: keyword()} tuple. The
dispatcher functions on this module read :lm from settings, merge per-call opts
on top of the config, and invoke the impl.
The behaviour declares the callbacks predictors and adapters call. New callbacks (structured output for the Json adapter, streaming for the Chat adapter, embeddings for the in-memory retriever) extend the behaviour when their consumers land — old impls keep working while their new-callback path raises until implemented.
In tests, stub impl callbacks with mimic rather than building bespoke fakes.
Summary
Functions
Dispatch an embed call to the impl module currently active in
Dsxir.Settings. Per-call opts are merged on top of the config. Raises
Dsxir.Errors.Invalid.Configuration when :lm is unset, malformed, or the
configured impl does not implement the optional embed/3 callback.
Empty usage map used by impls when the upstream LM did not report token
counts or cost. The shape is always present: tokens_in, tokens_out, and
cost are all nil.
Dispatch a generate_object call to the impl module currently active in
Dsxir.Settings, requesting a structured object validated against schema.
Dispatch a generate_text call to the impl module currently active in
Dsxir.Settings. Per-call opts are merged on top of the config from settings.
Raises Dsxir.Errors.Invalid.Configuration when :lm is unset or malformed.
Types
@type config() :: keyword()
@type messages() :: [map()]
@type opts() :: keyword()
@type usage() :: %{ tokens_in: nil | non_neg_integer(), tokens_out: nil | non_neg_integer(), cost: nil | float() }
Callbacks
Functions
Dispatch an embed call to the impl module currently active in
Dsxir.Settings. Per-call opts are merged on top of the config. Raises
Dsxir.Errors.Invalid.Configuration when :lm is unset, malformed, or the
configured impl does not implement the optional embed/3 callback.
@spec empty_usage() :: usage()
Empty usage map used by impls when the upstream LM did not report token
counts or cost. The shape is always present: tokens_in, tokens_out, and
cost are all nil.
Dispatch a generate_object call to the impl module currently active in
Dsxir.Settings, requesting a structured object validated against schema.
Per-call opts are merged on top of the config from settings. Raises
Dsxir.Errors.Invalid.Configuration when :lm is unset, malformed, or when
the configured impl does not implement the optional generate_object/4
callback.
Dispatch a generate_text call to the impl module currently active in
Dsxir.Settings. Per-call opts are merged on top of the config from settings.
Raises Dsxir.Errors.Invalid.Configuration when :lm is unset or malformed.