Context for managing AI provider configurations.
Summary
Functions
Builds the "pricing" key in a params map from raw form string inputs.
Returns a changeset for tracking provider changes.
Creates a new provider.
Resolves the LLMDB default pricing for a given provider atom and model string.
Deletes a provider.
Fetches models grouped into active and deprecated sets.
Fetches available models for a given provider type.
Gets a provider by ID, raising if not found.
Lists all providers in the system.
Extracts pricing-related virtual field values from a persisted provider.
Updates an existing provider.
Functions
Builds the "pricing" key in a params map from raw form string inputs.
When custom_pricing_enabled is true, parses "pricing_input" and
"pricing_output" from params into numeric rates and sets "pricing".
Invalid strings are forwarded as-is so changeset validation surfaces the
error. When disabled, "pricing" is set to nil.
@spec change_provider(Aludel.Providers.Provider.t(), map()) :: Ecto.Changeset.t()
Returns a changeset for tracking provider changes.
@spec create_provider(map()) :: {:ok, Aludel.Providers.Provider.t()} | {:error, Ecto.Changeset.t()}
Creates a new provider.
@spec default_pricing(atom() | binary() | nil, String.t() | nil) :: %{input: float(), output: float()} | nil
Resolves the LLMDB default pricing for a given provider atom and model string.
Returns nil when either argument is nil/empty or when no pricing data is found.
@spec delete_provider(Aludel.Providers.Provider.t()) :: {:ok, Aludel.Providers.Provider.t()} | {:error, Ecto.Changeset.t()}
Deletes a provider.
Fetches models grouped into active and deprecated sets.
Fetches available models for a given provider type.
@spec get_provider!(binary()) :: Aludel.Providers.Provider.t()
Gets a provider by ID, raising if not found.
@spec list_providers() :: [Aludel.Providers.Provider.t()]
Lists all providers in the system.
@spec pricing_form_attrs(Aludel.Providers.Provider.t()) :: %{ custom_pricing_enabled: boolean(), pricing_input: String.t(), pricing_output: String.t() }
Extracts pricing-related virtual field values from a persisted provider.
Returns a map suitable for merging into changeset attrs or socket assigns when re-hydrating the provider form on edit.
@spec update_provider(Aludel.Providers.Provider.t(), map()) :: {:ok, Aludel.Providers.Provider.t()} | {:error, Ecto.Changeset.t()}
Updates an existing provider.