Jido.AI.Model (Jido AI v0.5.2)

View Source

Summary

Functions

Creates a model struct from various input formats.

Creates a new model configuration with the given provider and options.

Validates a model configuration.

Validates model options for use in an action.

Types

t()

@type t() :: %Jido.AI.Model{
  api_key: String.t() | nil,
  architecture: Jido.AI.Model.Architecture.t() | nil,
  base_url: String.t() | nil,
  created: integer() | nil,
  description: String.t() | nil,
  endpoints: [Jido.AI.Model.Endpoint.t()] | nil,
  id: String.t() | nil,
  max_retries: non_neg_integer(),
  max_tokens: non_neg_integer(),
  model: String.t() | nil,
  name: String.t() | nil,
  provider: atom() | nil,
  temperature: float()
}

Functions

from(input)

@spec from(term()) :: {:ok, t()} | {:error, String.t()}

Creates a model struct from various input formats.

This is the main entry point for creating a model struct. It handles:

  • An existing %Jido.AI.Model{} struct (pass-through)
  • A tuple of {provider, opts} where provider is an atom and opts is a keyword list
  • A category tuple of {:category, category, class}

Parameters

  • input: The input to create a model from

Returns

  • {:ok, %Jido.AI.Model{}} - on success
  • {:error, reason} - on failure

Examples

iex> Jido.AI.Model.from({:anthropic, [model: "claude-3-5-haiku"]})
{:ok, %Jido.AI.Model{provider: :anthropic, model: "claude-3-5-haiku", ...}}

iex> Jido.AI.Model.from(%Jido.AI.Model{provider: :openai, model: "gpt-4"})
{:ok, %Jido.AI.Model{provider: :openai, model: "gpt-4", ...}}

new!(provider_or_tuple, opts \\ [])

@spec new!(
  atom() | {atom(), keyword()},
  keyword()
) :: atom() | {atom(), keyword()}

Creates a new model configuration with the given provider and options.

Parameters

  • provider_or_tuple - Either an atom representing the provider (e.g., :openrouter) or a tuple with provider and options.
  • opts - Keyword list of options for the model (optional when using tuple format).

Examples

# Using provider atom and options separately
iex> Jido.AI.Model.new!(:openrouter, model: "anthropic/claude-3.5-haiku")

# Using tuple shorthand
iex> Jido.AI.Model.new!({:anthropic, capabilities: [:chat], tier: :small})

Returns

A model configuration that can be used with Jido.AI.Agent.

@deprecated Use Jido.AI.Model.from/1 instead

validate(provider)

@spec validate(term()) :: {:ok, term()} | {:error, String.t()}

Validates a model configuration.

Parameters

  • model_config - The model configuration to validate.

Returns

  • {:ok, model_config} - The model configuration is valid.
  • {:error, reason} - The model configuration is invalid.

@deprecated Use Jido.AI.Model.from/1 instead

validate_model_opts(opts)

@spec validate_model_opts(term()) :: {:ok, t()} | {:error, String.t()}

Validates model options for use in an action.

Parameters

  • opts: The options to validate

Returns

  • {:ok, %Jido.AI.Model{}} - on success
  • {:error, reason} - on failure