express.ui.Chat
self, id, *, messages=(), on_error='auto', tokenizer=None) express.ui.Chat(
Methods
Name | Description |
---|---|
enable_bookmarking | Enable bookmarking for the chat instance. |
ui | Create a UI element for this Chat . |
enable_bookmarking
express.ui.Chat.enable_bookmarking(
client,/,
*,
=None,
bookmark_store='response',
bookmark_on )
Enable bookmarking for the chat instance.
This method registers on_bookmark
and on_restore
hooks on session.bookmark
(shiny.bookmark.Bookmark
) to save/restore chat state on both the Chat
and client=
instances. In order for this method to actually work correctly, a bookmark_store=
must be specified in shiny.express.app_opts()
.
Parameters
client :
ClientWithState
|chatlas
.Chat
[Any, Any]-
The chat client instance to use for bookmarking. This can be a Chat model provider from chatlas, or more generally, an instance following the
ClientWithState
protocol. bookmark_store : Optional[
BookmarkStore
] = None-
A convenience parameter to set the
shiny.express.app_opts(bookmark_store=)
which is required for bookmarking (and.enable_bookmarking()
). IfNone
, no value will be set. bookmark_on : Optional[Literal[‘response’]] = 'response'
-
The event to trigger the bookmarking on. Supported values include: -
"response"
(the default): a bookmark is triggered when the assistant is done responding. -None
: no bookmark is triggered When this method triggers a bookmark, it also updates the URL query string to reflect the bookmarked state.
Raises
: ValueError
-
If the Shiny App does have bookmarking enabled.
Returns
:
CancelCallback
-
A callback to cancel the bookmarking hooks.
ui
express.ui.Chat.ui(=None,
messages='Enter a message...',
placeholder='min(680px, 100%)',
width='auto',
height=True,
fill=None,
icon_assistant**kwargs,
)
Create a UI element for this Chat
.
Parameters
messages : Optional[Sequence[str |
ChatMessageDict
]] = None-
A sequence of messages to display in the chat. Each message can be either a string or a dictionary with
content
androle
keys. Thecontent
key should contain the message text, and therole
key can be “assistant” or “user”. placeholder : str = 'Enter a message…'
-
Placeholder text for the chat input.
width :
CssUnit
= 'min(680px, 100%)'-
The width of the UI element.
height :
CssUnit
= 'auto'-
The height of the UI element.
fill : bool = True
-
Whether the chat should vertically take available space inside a fillable container.
icon_assistant :
HTML
| Tag | TagList | None = None-
The icon to use for the assistant chat messages. Can be a HTML or a tag in the form of
HTML
orTag
. IfNone
, a default robot icon is used. kwargs : TagAttrValue = {}
-
Additional attributes for the chat container element.