# `Planck.AI.Config`
[🔗](https://github.com/alexdesousa/planck/blob/v0.1.0/lib/planck/ai/config.ex#L1)

Converts model configuration into `Planck.AI.Model` structs.

Two entry points are provided:

- `load/1` — reads and parses a JSON file directly.
- `from_list/1` — accepts an already-decoded list of maps, for callers (e.g.
  a CLI tool) that parse a larger config file themselves and extract only the
  models section before passing it here.

Each entry in the list maps to one `%Planck.AI.Model{}`. Only `"id"` and
`"provider"` are required; all other fields have sensible defaults.

## JSON format

    [
      {
        "id": "my-local-llama",
        "provider": "llama_cpp",
        "name": "Local Llama 3.2",
        "base_url": "http://localhost:8080",
        "context_window": 32768,
        "max_tokens": 4096,
        "supports_thinking": false,
        "input_types": ["text"],
        "default_opts": {
          "temperature": 0.8,
          "top_p": 0.95,
          "top_k": 40
        }
      },
      {
        "id": "qwen3-coder:7b",
        "provider": "ollama",
        "context_window": 40960
      }
    ]

## Loading from a file

    {:ok, models} = Planck.AI.Config.load("config/models.json")

## Loading from a pre-decoded list

    # e.g. the CLI decoded a larger config and extracted the models section
    models = Planck.AI.Config.from_list(decoded_config["models"])

# `from_list`

```elixir
@spec from_list([map()]) :: [Planck.AI.Model.t()]
```

Converts a list of maps (as decoded from JSON) into a list of `Model` structs.

Invalid entries are skipped with a warning; the rest are returned.

# `from_map`

```elixir
@spec from_map(map()) :: {:ok, Planck.AI.Model.t()} | {:error, String.t()}
```

Converts a single map into a `Model` struct.

Returns `{:ok, model}` or `{:error, reason}`.

# `load`

```elixir
@spec load(Path.t()) :: {:ok, [Planck.AI.Model.t()]} | {:error, term()}
```

Loads models from a JSON file at `path`.

Returns `{:ok, [Model.t()]}` on success. Invalid entries are skipped with a
warning logged at the `:warning` level. Returns `{:error, reason}` if the
file cannot be read or if the JSON is malformed.

---

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