LLMDB.Model (LLM DB v2025.12.4)

View Source

Model struct with Zoi schema validation.

Represents an LLM model with complete metadata including identity, provider, dates, limits, costs, modalities, capabilities, tags, lifecycle status, and aliases.

Summary

Functions

Creates a new Model struct from a map, validating with Zoi schema.

Creates a new Model struct from a map, raising on validation errors.

Returns the Zoi schema for Model

Formats a model as a spec string in the given format.

Types

t()

@type t() :: %LLMDB.Model{
  aliases: [binary()],
  capabilities:
    nil
    | %{
        json: %{
          optional(:native) => nil | boolean(),
          optional(:strict) => nil | boolean(),
          optional(:schema) => nil | boolean()
        },
        tools: %{
          optional(:enabled) => nil | boolean(),
          optional(:strict) => nil | boolean(),
          optional(:parallel) => nil | boolean(),
          optional(:streaming) => nil | boolean(),
          optional(:forced_choice) => nil | boolean()
        },
        reasoning: %{
          optional(:enabled) => nil | boolean(),
          optional(:token_budget) => nil | integer()
        },
        streaming: %{
          optional(:text) => nil | boolean(),
          optional(:tool_calls) => nil | boolean()
        },
        chat: boolean(),
        embeddings:
          boolean()
          | %{
              optional(:min_dimensions) => nil | integer(),
              optional(:max_dimensions) => nil | integer(),
              optional(:default_dimensions) => nil | integer()
            }
      },
  cost:
    nil
    | %{
        optional(:input) => nil | number(),
        optional(:output) => nil | number(),
        optional(:request) => nil | number(),
        optional(:image) => nil | number(),
        optional(:cache_read) => nil | number(),
        optional(:cache_write) => nil | number(),
        optional(:training) => nil | number(),
        optional(:reasoning) => nil | number(),
        optional(:audio) => nil | number(),
        optional(:input_audio) => nil | number(),
        optional(:output_audio) => nil | number(),
        optional(:input_video) => nil | number(),
        optional(:output_video) => nil | number()
      },
  deprecated: boolean(),
  extra: nil | map(),
  family: nil | binary(),
  id: binary(),
  knowledge: nil | binary(),
  last_updated: nil | binary(),
  lifecycle:
    nil
    | %{
        optional(:status) => nil | binary(),
        optional(:deprecated_at) => nil | binary(),
        optional(:retires_at) => nil | binary(),
        optional(:replacement) => nil | binary()
      },
  limits:
    nil
    | %{
        optional(:output) => nil | integer(),
        optional(:context) => nil | integer()
      },
  modalities:
    nil
    | %{optional(:input) => nil | [atom()], optional(:output) => nil | [atom()]},
  model: nil | binary(),
  name: nil | binary(),
  provider: atom(),
  provider_model_id: nil | binary(),
  release_date: nil | binary(),
  tags: nil | [binary()]
}

Functions

new(attrs)

@spec new(map()) :: {:ok, t()} | {:error, term()}

Creates a new Model struct from a map, validating with Zoi schema.

Examples

iex> LLMDB.Model.new(%{id: "gpt-4", provider: :openai})
{:ok, %LLMDB.Model{id: "gpt-4", model: "gpt-4", provider: :openai}}

iex> LLMDB.Model.new(%{})
{:error, _validation_errors}

new!(attrs)

@spec new!(map()) :: t()

Creates a new Model struct from a map, raising on validation errors.

Examples

iex> LLMDB.Model.new!(%{id: "gpt-4", provider: :openai})
%LLMDB.Model{id: "gpt-4", model: "gpt-4", provider: :openai}

schema()

Returns the Zoi schema for Model

spec(model, format \\ nil)

@spec spec(t(), atom() | nil) :: String.t()

Formats a model as a spec string in the given format.

Delegates to LLMDB.Spec.format_spec/2 with the model's provider and ID. If no format is specified, uses the application config :llm_db, :model_spec_format (default: :provider_colon_model).

Parameters

  • model - The model struct
  • format - Optional format override (:provider_colon_model, :model_at_provider, :filename_safe)

Examples

iex> model = %LLMDB.Model{provider: :openai, id: "gpt-4"}
iex> LLMDB.Model.spec(model)
"openai:gpt-4"

iex> LLMDB.Model.spec(model, :model_at_provider)
"gpt-4@openai"

iex> LLMDB.Model.spec(model, :filename_safe)
"gpt-4@openai"