# `ALLM.TextPart`
[🔗](https://github.com/cykod/ALLM/blob/v0.3.0/lib/allm/text_part.ex#L1)

A text content part used in multimodal `ALLM.Message{:content}` lists. See
spec §35.6.

Layer A — pure serializable data. `:text` is the only required field;
`:metadata` defaults to an empty map. The struct is opaque from the
validator's point of view (`ALLM.Validate.message/1` accepts any
`%TextPart{}` regardless of `:text` content — empty strings included).

Multimodal callers build `%ALLM.Message{content: [...]}` by hand:

    iex> ALLM.Message.new(role: :user, content: [
    ...>   %ALLM.TextPart{text: "What is in this image?"},
    ...>   %ALLM.ImagePart{image: ALLM.Image.from_url("https://example.com/cat.png")}
    ...> ]).role
    :user

## Serializability

ETF round-trip via `:erlang.term_to_binary/1` is total. JSON round-trip via
`ALLM.Serializer` follows the standard `__type__`-tagged wire shape used by
every Layer A struct.

# `t`

```elixir
@type t() :: %ALLM.TextPart{metadata: map(), text: String.t()}
```

# `new`

```elixir
@spec new(
  String.t(),
  keyword()
) :: t()
```

Build a `%TextPart{}` from a string and optional keyword opts.

Accepts an optional `:metadata` keyword (a map). Empty `text` is allowed —
the validator does not reject empty TextParts; that is an upstream concern.

## Examples

    iex> ALLM.TextPart.new("hi")
    %ALLM.TextPart{text: "hi", metadata: %{}}

    iex> ALLM.TextPart.new("hi", metadata: %{source: :test}).metadata
    %{source: :test}

---

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