AI.Message.User (fnord v0.9.40)

View Source

User input message.

Internal shape (matches the chat-completions raw map shape that existing pattern matches expect):

%AI.Message.User{role: "user", content: "<binary>"}

Wire shape (built on demand by to_map/1):

%{type: "message", role: "user",
  content: [%{type: "input_text", text: "..."}]}

Storing content as a binary keeps the struct drop-in compatible with the ~150 pattern-match sites that do msg.content or %{role: "user", content: c} = msg.

We already accept typed content parts on hydrate and collapse them back to a single binary. Supporting rich multi-part user messages end-to-end would still require revisiting the internal struct shape.

Summary

Functions

Hydrate from a Responses-shaped or legacy chat-completions-shaped map (atom or string keys). The Responses shape carries content as a list of typed parts; we collapse those parts to a single binary.

Build a user message from a binary.

Types

t()

@type t() :: %AI.Message.User{content: binary(), role: binary()}

Functions

from_map(raw)

@spec from_map(map()) :: t()

Hydrate from a Responses-shaped or legacy chat-completions-shaped map (atom or string keys). The Responses shape carries content as a list of typed parts; we collapse those parts to a single binary.

new(text)

@spec new(binary()) :: t()

Build a user message from a binary.