PhoenixKitAI.Web.EndpointForm (PhoenixKitAI v0.2.1)

Copy Markdown View Source

LiveView for creating and editing AI endpoints.

An endpoint combines provider credentials, model selection, and generation parameters into a single configuration.

Summary

Functions

Formats a number with thousands separators.

Formats a per-token model price as a per-million-tokens display.

Returns parameters supported by the model, filtered to ones we have UI for. Groups them by :basic and :advanced.

Renders a single model option as a clickable card with name, ID, context-length / max-output badges, and prompt / completion pricing.

Gets the max tokens limit for the selected model.

Parameter definitions with type, constraints, and UI metadata. Only parameters we support in the UI are defined here.

Callback implementation for Phoenix.LiveView.render/1.

Functions

format_number(num)

Formats a number with thousands separators.

format_price(value)

@spec format_price(number() | String.t() | nil) :: String.t() | nil

Formats a per-token model price as a per-million-tokens display.

OpenRouter pricing comes back in two shapes — newer rows use a JSON number, older rows use a stringified float. This helper accepts either and returns a rounded "$X.XX" string. Returns nil for empty/missing values so the template can render-or-skip cleanly.

Examples

iex> EndpointForm.format_price(0.0000015)
"$1.50"

iex> EndpointForm.format_price("0.0000015")
"$1.50"

iex> EndpointForm.format_price(nil)
nil

get_supported_params(model)

Returns parameters supported by the model, filtered to ones we have UI for. Groups them by :basic and :advanced.

model_card(assigns)

Renders a single model option as a clickable card with name, ID, context-length / max-output badges, and prompt / completion pricing.

The same card is used in two places:

  • Inside the model grid — the operator's browse surface. Click selects. The currently-selected card is excluded from the grid (it's hoisted to the top — see below) so each model appears in exactly one location.
  • Hoisted above the grid as the "Current Model" — when @selected_model is set, the card moves out of the grid to the top of the section. show_clear: true adds an "X" button that deselects (drops the card back into the grid). Clicking the card body itself is a no-op (selecting an already-selected model has no effect).

This keeps a single source of truth for the rich model display — badges + pricing — instead of duplicating the layout between a separate summary panel and the grid.

Attributes

  • model (:map) (required)
  • selected (:boolean) (required)
  • show_clear (:boolean) - Defaults to false.

model_max_tokens(model)

Gets the max tokens limit for the selected model.

param_input(assigns)

Attributes

  • key (:string) (required)
  • definition (:map) (required)
  • form (:map) (required)
  • endpoint (:any) - Defaults to nil.
  • selected_model (:map) - Defaults to nil.
  • size (:string) - Defaults to "md".

parameter_definitions()

Parameter definitions with type, constraints, and UI metadata. Only parameters we support in the UI are defined here.

render(assigns)

Callback implementation for Phoenix.LiveView.render/1.