ExLLM.Core.Models (ex_llm v0.8.1)

View Source

Model discovery and management across LLM providers.

This module provides unified access to model information, configuration, and discovery across all ExLLM providers.

Summary

Functions

Compare models across different providers.

Find models by capability.

Find models within a cost range (per 1M tokens).

Find models by minimum context window size.

Get the default model for a provider.

Get detailed information about a specific model.

List all available models for all providers.

List models for a specific provider.

Functions

compare(model_ids)

@spec compare([String.t()]) :: {:ok, map()} | {:error, term()}

Compare models across different providers.

Returns a comparison matrix showing capabilities, pricing, and context windows.

Examples

iex> ExLLM.Core.Models.compare(["claude-3-5-sonnet-20241022", "gpt-4-turbo", "gemini-1.5-pro"])
{:ok, %{
  models: [...],
  capabilities: %{vision: [...], streaming: [...]},
  pricing: %{...},
  context_windows: %{...}
}}

find_by_capabilities(capabilities)

@spec find_by_capabilities([atom()]) :: {:ok, [map()]} | {:error, term()}

Find models by capability.

Returns models that support all the specified capabilities.

Examples

iex> ExLLM.Core.Models.find_by_capabilities([:vision, :streaming])
{:ok, [
  %{provider: :anthropic, id: "claude-3-5-sonnet-20241022", ...},
  %{provider: :openai, id: "gpt-4-turbo", ...}
]}

find_by_cost_range(cost_filters)

@spec find_by_cost_range(keyword()) :: {:ok, [map()]} | {:error, term()}

Find models within a cost range (per 1M tokens).

Examples

iex> ExLLM.Core.Models.find_by_cost_range(input: {0, 5.0}, output: {0, 20.0})
{:ok, [%{provider: :openai, id: "gpt-3.5-turbo", pricing: %{input: 0.5, output: 1.5}}, ...]}

find_by_min_context(min_context)

@spec find_by_min_context(pos_integer()) :: {:ok, [map()]} | {:error, term()}

Find models by minimum context window size.

Examples

iex> ExLLM.Core.Models.find_by_min_context(100_000)
{:ok, [%{provider: :anthropic, id: "claude-3-5-sonnet-20241022", context_window: 200_000}, ...]}

get_default(provider)

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

Get the default model for a provider.

Examples

iex> ExLLM.Core.Models.get_default(:anthropic)
{:ok, "claude-3-5-sonnet-latest"}

get_info(provider, model_id)

@spec get_info(atom(), String.t()) :: {:ok, map()} | {:error, term()}

Get detailed information about a specific model.

Examples

iex> ExLLM.Core.Models.get_info(:anthropic, "claude-3-5-sonnet-20241022")
{:ok, %{
  id: "claude-3-5-sonnet-20241022",
  provider: :anthropic,
  name: "Claude 3.5 Sonnet",
  context_window: 200_000,
  max_output_tokens: 4_096,
  capabilities: [:streaming, :vision, :function_calling],
  pricing: %{input: 3.0, output: 15.0}
}}

list_all()

@spec list_all() :: {:ok, [map()]} | {:error, term()}

List all available models for all providers.

Returns a list of model information including provider, model ID, and capabilities.

Examples

iex> ExLLM.Core.Models.list_all()
{:ok, [
  %{provider: :anthropic, id: "claude-3-5-sonnet-20241022", ...},
  %{provider: :openai, id: "gpt-4-turbo", ...},
  ...
]}

list_for_provider(provider)

@spec list_for_provider(atom()) :: {:ok, [map()]} | {:error, term()}

List models for a specific provider.

Examples

iex> ExLLM.Core.Models.list_for_provider(:anthropic)
{:ok, [
  %{id: "claude-3-5-sonnet-20241022", name: "Claude 3.5 Sonnet", ...},
  %{id: "claude-3-5-haiku-20241022", name: "Claude 3.5 Haiku", ...}
]}