Octoroom.Agent.Models (octoroom_agents v0.1.0)

Copy Markdown View Source

Downloads and caches optional ONNX models that are too large to bundle in the Hex package.

Models are resolved in order:

  1. An explicit :models_dir option.
  2. OCTOROOM_MODELS_DIR or config :octoroom_agents, :models_dir.
  3. priv/models/<filename> if present locally.
  4. The OS user cache directory (octoroom_agents/models).

On a cache miss, ensure/2 downloads the file over HTTPS with Req, verifies its SHA-256 checksum, and atomically moves it into place. Set config :octoroom_agents, auto_download_models: false (or pass download: false) to disable runtime downloads and prefetch models ahead of time with mix octoroom.models.download.

Summary

Functions

Ensures every managed model is present on disk.

Returns {:ok, path} for name, downloading and verifying it if missing.

Metadata (filename, url, sha256) for a managed model.

Directory where downloaded models are cached.

Names of all models managed by this module.

Path where name lives or will be cached.

Types

name()

@type name() :: :smart_turn

Functions

download_all(opts \\ [])

@spec download_all(keyword()) ::
  {:ok, %{required(name()) => String.t()}} | {:error, term()}

Ensures every managed model is present on disk.

ensure(name, opts \\ [])

@spec ensure(name(), keyword()) :: {:ok, String.t()} | {:error, term()}

Returns {:ok, path} for name, downloading and verifying it if missing.

Options:

  • :models_dir - override the cache directory
  • :download - override :auto_download_models (default true)
  • :url, :sha256, :request_fun - overrides for tests

fetch!(name)

@spec fetch!(name()) :: %{filename: String.t(), url: String.t(), sha256: String.t()}

Metadata (filename, url, sha256) for a managed model.

models_dir(opts \\ [])

@spec models_dir(keyword()) :: String.t()

Directory where downloaded models are cached.

Checks :models_dir in opts, then OCTOROOM_MODELS_DIR, then :octoroom_agents's :models_dir config, then the OS user cache directory (octoroom_agents/models).

names()

@spec names() :: [name()]

Names of all models managed by this module.

path(name, opts \\ [])

@spec path(name(), keyword()) :: String.t()

Path where name lives or will be cached.

When no custom directory is configured, returns priv/models/<filename> if the file is present locally, otherwise Path.join(models_dir(), filename).