types.ChatMessage
types.ChatMessage(
content,
role='assistant',
content_type=None,
attachments=None,
blocks=None,
parts=None,
)A chat message with ordered content segments.
The message stores its content as segments: string segments interleaved with structured blocks. This is the same shape the wire format and :class:StoredMessage use. The content, blocks, and parts properties are read-only views over those segments.
Pass content for a simple string or HTML tag, parts to interleave strings and blocks in one message, or blocks to attach structured blocks after a string. These three inputs are mutually exclusive: parts raises when combined with blocks or non-empty content.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| content | TagChild | The message content. A plain string is markdown. An htmltools tag, :class:~htmltools.TagList, or :class:~htmltools.HTML is trusted HTML. Tag content is an HTML container: bare strings inside it are escaped text, not markdown. To mix markdown and HTML in one message, use parts instead. |
required |
| role | Role | The message role. One of "assistant", "user", or "system". Defaults to "assistant". |
'assistant' |
| content_type | 'ContentType | None' | The content type for string segments. One of "markdown", "html", "text", or "thinking". When content is a string, defaults to "markdown". When content is a tag or TagList, defaults to "html". When parts is passed, applies to every string part in the list. |
None |
| attachments | 'list[Attachment] | None' | Files attached to the message. Each item is an :class:~shinychat.Attachment or a dict that validates as one. |
None |
| blocks | 'list[StructuredBlock] | None' | Structured blocks to append after the content. Cannot be combined with parts. |
None |
| parts | 'list[str | StructuredBlock] | None' | An ordered list of bare strings and structured blocks. Strings become segments stamped with content_type. Blocks pass through in order. Cannot be combined with blocks or non-empty content. |
None |
Attributes
| Name | Description |
|---|---|
| blocks | The structured blocks in the message, in content order. |
| content | The string content of the message, joined from its string segments. |
| parts | The segment list as bare strings interleaved with blocks. |