Skip to content

Commit 4c6c6b3

Browse files
committed
Document on; Document express version
1 parent 259bd41 commit 4c6c6b3

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

shiny/ui/_chat.py

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,6 @@ def enable_bookmarking(
14111411
client: ClientWithState | chatlas.Chat[Any, Any],
14121412
/,
14131413
*,
1414-
# TODO: Barret - `on` docs
14151414
on: Optional[Literal["response"]] = "response",
14161415
) -> CancelCallback:
14171416
"""
@@ -1420,12 +1419,21 @@ def enable_bookmarking(
14201419
This method registers `on_bookmark` and `on_restore` hooks on `session.bookmark`
14211420
to save/restore chat state on both the `Chat` and `client` instances.
14221421
In order for this method to actually work correctly, a `bookmark_store`
1423-
must be specified on the `App` object.
1422+
must be specified within `shiny.App()` or `shiny.express.app_opts()`.
14241423
14251424
Parameters
14261425
----------
14271426
client
1428-
The chat client instance to use for bookmarking. This can be a Chat model provider from [chatlas](https://posit-dev.github.io/chatlas/), or more generally, an instance following the `ClientWithState` protocol.
1427+
The chat client instance to use for bookmarking. This can be a Chat model
1428+
provider from [chatlas](https://posit-dev.github.io/chatlas/), or more
1429+
generally, an instance following the `ClientWithState` protocol.
1430+
on
1431+
The event to trigger the bookmarking on.
1432+
1433+
When `on` is not `None`, the query string with the latest bookmark URL.
1434+
1435+
When `on` is `"response"`, the session will attempt to bookmark when the
1436+
assistant is done responding.
14291437
14301438
Raises
14311439
------
@@ -1579,7 +1587,7 @@ async def _on_restore_ui(state: RestoreState):
15791587

15801588
msgs: list[Any] = state.values[resolved_bookmark_id_msgs_str]
15811589
if not msgs:
1582-
# If no messages, set the default messages
1590+
# If no messages to restore, display the `__init__(messages=)` messages
15831591
await self._append_init_messages()
15841592
return
15851593

@@ -1659,6 +1667,37 @@ def enable_bookmarking(
16591667
store: Optional[BookmarkStore] = None,
16601668
on: Optional[Literal["response"]] = "response",
16611669
) -> CancelCallback:
1670+
"""
1671+
Enable bookmarking for the chat instance.
1672+
1673+
This method registers `on_bookmark` and `on_restore` hooks on `session.bookmark`
1674+
to save/restore chat state on both the `Chat` and `client` instances.
1675+
In order for this method to actually work correctly, a `bookmark_store`
1676+
must be specified within `shiny.App()` or `shiny.express.app_opts()`.
1677+
1678+
Parameters
1679+
----------
1680+
client
1681+
The chat client instance to use for bookmarking. This can be a Chat model
1682+
provider from [chatlas](https://posit-dev.github.io/chatlas/), or more
1683+
generally, an instance following the `ClientWithState` protocol.
1684+
store
1685+
A convenience parameter to set the `shiny.express.app_opts(bookmark_store=)`
1686+
which is required for bookmarking (and `.enable_bookmarking()`). If `None`,
1687+
no value will be set.
1688+
on
1689+
The event to trigger the bookmarking on.
1690+
1691+
When `on` is not `None`, the query string with the latest bookmark URL.
1692+
1693+
When `on` is `"response"`, the session will attempt to bookmark when the
1694+
assistant is done responding.
1695+
1696+
Raises
1697+
------
1698+
ValueError
1699+
If the Shiny App does have bookmarking enabled.
1700+
"""
16621701

16631702
if store is not None:
16641703
from ..express import app_opts

0 commit comments

Comments
 (0)