Skip to content

Commit 017c17a

Browse files
committed
Update docstrings
1 parent 1a06708 commit 017c17a

File tree

1 file changed

+63
-24
lines changed

1 file changed

+63
-24
lines changed

shiny/ui/_chat.py

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,21 @@ async def handle_user_input(user_input: str):
133133
A unique identifier for the chat session. In Shiny Core, make sure this id
134134
matches a corresponding :func:`~shiny.ui.chat_ui` call in the UI.
135135
messages
136-
A sequence of messages to display in the chat. Each message can be either a
137-
string or a dictionary with `content` and `role` keys. The `content` key
138-
should contain a string, and the `role` key can be "assistant" or "user".
139-
Content strings are interpreted as markdown and rendered to HTML on the client.
140-
Content may also include specially formatted **input suggestion** links (see
141-
`.append_message_stream()` for more information).
136+
A sequence of messages to display in the chat. A given message can be one of the
137+
following:
138+
139+
* A string, which is interpreted as markdown and rendered to HTML on the client.
140+
* To prevent interpreting as markdown, mark the string as
141+
:class:`~shiny.ui.HTML`.
142+
* A UI element (specifically, a :class:`~shiny.ui.TagChild`).
143+
* This includes :class:`~shiny.ui.TagList`, which take UI elements
144+
(including strings) as children. In this case, strings are still
145+
interpreted as markdown as long as they're not inside HTML.
146+
* A dictionary with `content` and `role` keys. The `content` key can contain a
147+
content as described above, and the `role` key can be "assistant" or "user".
148+
149+
**NOTE:** content may include specially formatted **input suggestion** links
150+
(see `.append_message()` for more information).
142151
on_error
143152
How to handle errors that occur in response to user input. When `"unhandled"`,
144153
the app will stop running when an error occurs. Otherwise, a notification
@@ -505,12 +514,22 @@ async def append_message(
505514
Parameters
506515
----------
507516
message
508-
The message to append. A variety of message formats are supported including
509-
a string, a dictionary with `content` and `role` keys, or a relevant chat
510-
completion object from platforms like OpenAI, Anthropic, Ollama, and others.
511-
Content strings are interpreted as markdown and rendered to HTML on the
512-
client. Content may also include specially formatted **input suggestion**
513-
links (see note below).
517+
A given message can be one of the following:
518+
519+
* A string, which is interpreted as markdown and rendered to HTML on the
520+
client.
521+
* To prevent interpreting as markdown, mark the string as
522+
:class:`~shiny.ui.HTML`.
523+
* A UI element (specifically, a :class:`~shiny.ui.TagChild`).
524+
* This includes :class:`~shiny.ui.TagList`, which take UI elements
525+
(including strings) as children. In this case, strings are still
526+
interpreted as markdown as long as they're not inside HTML.
527+
* A dictionary with `content` and `role` keys. The `content` key can contain
528+
content as described above, and the `role` key can be "assistant" or
529+
"user".
530+
531+
**NOTE:** content may include specially formatted **input suggestion** links
532+
(see note below).
514533
icon
515534
An optional icon to display next to the message, currently only used for
516535
assistant messages. The icon can be any HTML element (e.g., an
@@ -600,12 +619,23 @@ async def append_message_stream(
600619
Parameters
601620
----------
602621
message
603-
An (async) iterable of message chunks to append. A variety of message chunk
604-
formats are supported, including a string, a dictionary with `content` and
605-
`role` keys, or a relevant chat completion object from platforms like
606-
OpenAI, Anthropic, Ollama, and others. Content strings are interpreted as
607-
markdown and rendered to HTML on the client. Content may also include
608-
specially formatted **input suggestion** links (see note below).
622+
An (async) iterable of message chunks. Each chunk can be one of the
623+
following:
624+
625+
* A string, which is interpreted as markdown and rendered to HTML on the
626+
client.
627+
* To prevent interpreting as markdown, mark the string as
628+
:class:`~shiny.ui.HTML`.
629+
* A UI element (specifically, a :class:`~shiny.ui.TagChild`).
630+
* This includes :class:`~shiny.ui.TagList`, which take UI elements
631+
(including strings) as children. In this case, strings are still
632+
interpreted as markdown as long as they're not inside HTML.
633+
* A dictionary with `content` and `role` keys. The `content` key can contain
634+
content as described above, and the `role` key can be "assistant" or
635+
"user".
636+
637+
**NOTE:** content may include specially formatted **input suggestion** links
638+
(see note below).
609639
icon
610640
An optional icon to display next to the message, currently only used for
611641
assistant messages. The icon can be any HTML element (e.g., an
@@ -1231,12 +1261,21 @@ def chat_ui(
12311261
id
12321262
A unique identifier for the chat UI.
12331263
messages
1234-
A sequence of messages to display in the chat. Each message can be either a
1235-
string or a dictionary with `content` and `role` keys. The `content` key
1236-
should contain a string, and the `role` key can be "assistant" or "user".
1237-
Content strings are interpreted as markdown and rendered to HTML on the client.
1238-
Content may also include specially formatted **input suggestion** links (see
1239-
:method:`~shiny.ui.Chat.append_message_stream` for more information).
1264+
A sequence of messages to display in the chat. A given message can be one of the
1265+
following:
1266+
1267+
* A string, which is interpreted as markdown and rendered to HTML on the client.
1268+
* To prevent interpreting as markdown, mark the string as
1269+
:class:`~shiny.ui.HTML`.
1270+
* A UI element (specifically, a :class:`~shiny.ui.TagChild`).
1271+
* This includes :class:`~shiny.ui.TagList`, which take UI elements
1272+
(including strings) as children. In this case, strings are still
1273+
interpreted as markdown as long as they're not inside HTML.
1274+
* A dictionary with `content` and `role` keys. The `content` key can contain a
1275+
content as described above, and the `role` key can be "assistant" or "user".
1276+
1277+
**NOTE:** content may include specially formatted **input suggestion** links
1278+
(see :method:`~shiny.ui.Chat.append_message` for more info).
12401279
placeholder
12411280
Placeholder text for the chat input.
12421281
width

0 commit comments

Comments
 (0)