# `Octoroom.Agent.Models`
[🔗](https://github.com/samrat/octoroom/blob/v0.1.0/agents/lib/octoroom/agent/models.ex#L1)

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`.

# `name`

```elixir
@type name() :: :smart_turn
```

# `download_all`

```elixir
@spec download_all(keyword()) ::
  {:ok, %{required(name()) =&gt; String.t()}} | {:error, term()}
```

Ensures every managed model is present on disk.

# `ensure`

```elixir
@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!`

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

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

# `models_dir`

```elixir
@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`

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

Names of all models managed by this module.

# `path`

```elixir
@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)`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
