Behaviour for a model provider.
A provider owns one model API. SuperPi.AI.Providers selects the provider for a model name.
To serve a model that Super-Pi does not support, write a module that implements this
behaviour and register it in the application environment:
config :super_pi, :providers, [MyApp.MyProvider, SuperPi.AI.Providers.Gemini]Providers earlier in the list win. generate/2 receives the request payload (:model,
:messages, :tools, and so on) and an :on_delta callback. It returns {:ok, message}
or {:error, reason}. The message has the shape %{"role" => "assistant", "content" => [...], "usage" => %{...}}. Call on_delta with the events that SuperPi.AI.StreamNormalizer emits.
Summary
Types
Streaming callback. Receives StreamNormalizer events.
Callbacks
Returns true when the provider has the credentials and settings that it needs.
Runs a generation request.
Returns true when this provider serves model.
Stable provider identifier, for example "gemini".
Models to list in catalogs. Each entry has "id" and "label".
Maps a requested name (for example a harness alias) to the model sent to the API.
Functions
Readable text for a generate/2 error reason. Strings pass through unchanged, so text
formatted once is not escaped again.
Types
Callbacks
@callback configured?() :: boolean()
Returns true when the provider has the credentials and settings that it needs.
@callback generate(payload :: map(), opts :: [{:on_delta, on_delta()}]) :: {:ok, map()} | {:error, term()}
Runs a generation request.
Returns true when this provider serves model.
@callback id() :: String.t()
Stable provider identifier, for example "gemini".
Models to list in catalogs. Each entry has "id" and "label".
Maps a requested name (for example a harness alias) to the model sent to the API.