7171
7272# TODO: UserInput might need to be a list of dicts if we want to support multiple
7373# user input content types
74- TransformUserInput = Callable [[str ], Union [str , None ]]
75- TransformUserInputAsync = Callable [[str ], Awaitable [Union [str , None ]]]
76- TransformAssistantResponse = Callable [[str ], Union [str , HTML , None ]]
77- TransformAssistantResponseAsync = Callable [
78- [str ], Awaitable [Union [str , HTML , None ]]
79- ]
80- TransformAssistantResponseChunk = Callable [
81- [str , str , bool ], Union [str , HTML , None ]
82- ]
83- TransformAssistantResponseChunkAsync = Callable [
84- [str , str , bool ], Awaitable [Union [str , HTML , None ]]
85- ]
86- TransformAssistantResponseFunction = Union [
87- TransformAssistantResponse ,
88- TransformAssistantResponseAsync ,
89- TransformAssistantResponseChunk ,
90- TransformAssistantResponseChunkAsync ,
91- ]
9274UserSubmitFunction0 = Union [
9375 Callable [[], None ],
9476 Callable [[], Awaitable [None ]],
@@ -160,22 +142,6 @@ async def handle_user_input(user_input: str):
160142 id
161143 A unique identifier for the chat session. In Shiny Core, make sure this id
162144 matches a corresponding :func:`~shiny.ui.chat_ui` call in the UI.
163- messages
164- A sequence of messages to display in the chat. A given message can be one of the
165- following:
166-
167- * A string, which is interpreted as markdown and rendered to HTML on the client.
168- * To prevent interpreting as markdown, mark the string as
169- :class:`~shiny.ui.HTML`.
170- * A UI element (specifically, a :class:`~shiny.ui.TagChild`).
171- * This includes :class:`~shiny.ui.TagList`, which take UI elements
172- (including strings) as children. In this case, strings are still
173- interpreted as markdown as long as they're not inside HTML.
174- * A dictionary with `content` and `role` keys. The `content` key can contain a
175- content as described above, and the `role` key can be "assistant" or "user".
176-
177- **NOTE:** content may include specially formatted **input suggestion** links
178- (see `.append_message()` for more information).
179145 on_error
180146 How to handle errors that occur in response to user input. When `"unhandled"`,
181147 the app will stop running when an error occurs. Otherwise, a notification
@@ -186,12 +152,6 @@ async def handle_user_input(user_input: str):
186152 * `"actual"`: Display the actual error message to the user.
187153 * `"sanitize"`: Sanitize the error message before displaying it to the user.
188154 * `"unhandled"`: Do not display any error message to the user.
189- tokenizer
190- The tokenizer to use for calculating token counts, which is required to impose
191- `token_limits` in `.messages()`. If not provided, a default generic tokenizer
192- is attempted to be loaded from the tokenizers library. A specific tokenizer
193- may also be provided by following the `TokenEncoding` (tiktoken or tozenizers)
194- protocol (e.g., `tiktoken.encoding_for_model("gpt-4o")`).
195155 """
196156
197157 def __init__ (
@@ -353,11 +313,12 @@ def messages(self) -> tuple[ChatMessageDict, ...]:
353313 """
354314 Reactively read chat messages
355315
316+ Obtain chat messages that have been appended after initial load.
317+
356318 Note
357319 ----
358- Messages are listed in the order they were added. As a result, when this method
359- is called in a `.on_user_submit()` callback (as it most often is), the last
360- message will be the most recent one submitted by the user.
320+ Startup messages (i.e., those passed to the `.ui()` method) are not included in the
321+ return value. Also, this method must be called in a reactive context, and will invl
361322
362323 Returns
363324 -------
0 commit comments