Aludel.Providers (aludel v0.2.0)

Copy Markdown View Source

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

build_pricing_attrs(params, arg2)

@spec build_pricing_attrs(map(), boolean()) :: map()

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.

change_provider(provider, attrs \\ %{})

@spec change_provider(Aludel.Providers.Provider.t(), map()) :: Ecto.Changeset.t()

Returns a changeset for tracking provider changes.

create_provider(attrs \\ %{})

@spec create_provider(map()) ::
  {:ok, Aludel.Providers.Provider.t()} | {:error, Ecto.Changeset.t()}

Creates a new provider.

default_pricing(provider, model)

@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.

delete_provider(provider)

@spec delete_provider(Aludel.Providers.Provider.t()) ::
  {:ok, Aludel.Providers.Provider.t()} | {:error, Ecto.Changeset.t()}

Deletes a provider.

fetch_model_groups(provider_type)

@spec fetch_model_groups(nil | binary() | atom()) :: %{
  active: [map()],
  deprecated: [map()]
}

Fetches models grouped into active and deprecated sets.

fetch_models(provider_type)

@spec fetch_models(nil | binary() | atom()) :: [map()]

Fetches available models for a given provider type.

get_provider!(id)

@spec get_provider!(binary()) :: Aludel.Providers.Provider.t()

Gets a provider by ID, raising if not found.

list_providers()

@spec list_providers() :: [Aludel.Providers.Provider.t()]

Lists all providers in the system.

pricing_form_attrs(provider)

@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.

update_provider(provider, attrs)

@spec update_provider(Aludel.Providers.Provider.t(), map()) ::
  {:ok, Aludel.Providers.Provider.t()} | {:error, Ecto.Changeset.t()}

Updates an existing provider.