Skip to content

feat(bookmarking): Add support for ui.Chat bookmarking #1951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c53934d
Commit before pivoting to using new client state class / chatlas
schloerke Apr 1, 2025
f15e6d0
Add chatlas as a dev github source
schloerke Apr 1, 2025
2cd9886
First pass at `chat.enable_bookmarking()`
schloerke Apr 1, 2025
e8346e7
Init incomplete example apps
schloerke Apr 1, 2025
b1875c4
Merge branch 'main' into bookmark-chat
schloerke Apr 1, 2025
60660a6
Require `chatlas>=0.6.0`
schloerke Apr 2, 2025
22fc7bc
Merge branch 'bookmark-chat' of https://github.com/posit-dev/py-shiny…
schloerke Apr 2, 2025
06c8e09
Add `ClientWithState` docs
schloerke Apr 2, 2025
fdae6e2
Remove unused new attr
schloerke Apr 2, 2025
57c93ae
Try to only import chatlas directly; Move checks to top; Add raises s…
schloerke Apr 2, 2025
4292d18
Use `on` and `store` for param names
schloerke Apr 2, 2025
0761374
Rename cancel callback methods
schloerke Apr 2, 2025
e3f52b0
Remove unnecessary check
schloerke Apr 2, 2025
59fc8bb
Use function to help with consistent behavior for appending init mess…
schloerke Apr 2, 2025
259bd41
Apply suggestions from code review
schloerke Apr 2, 2025
4c6c6b3
Document `on`; Document express version
schloerke Apr 2, 2025
d4bcd3e
Enable bookmarking in templates
schloerke Apr 2, 2025
56bd3c2
Fixes
schloerke Apr 2, 2025
a7ef7be
Remove unused example app
schloerke Apr 2, 2025
45de2ae
Rename variable
schloerke Apr 2, 2025
7d02692
Apply suggestions from code review
schloerke Apr 2, 2025
593425f
Use `state=` not `value=`
schloerke Apr 2, 2025
df344b1
Update template with suggested comment
schloerke Apr 2, 2025
f51c0be
Rename parameters back to `bookmark_store` and `bookmark_on`
schloerke Apr 2, 2025
895a640
Link to Bookmark class in docs; Add Returns
schloerke Apr 2, 2025
e8a3b12
Update CHANGELOG.md
schloerke Apr 2, 2025
3f6f65f
Tests
schloerke Apr 2, 2025
f86abb8
Move most of chatlas logic to `_chat_bookmark.py`
schloerke Apr 2, 2025
d319227
Rearrange sections to co-locate UI together and client together
schloerke Apr 2, 2025
63c2dfb
lint
schloerke Apr 2, 2025
97efb12
Use pydantic json objects, not str for serialization
schloerke Apr 3, 2025
cfef02b
Update CHANGELOG.md
schloerke Apr 3, 2025
51d1847
Use fake key
schloerke Apr 3, 2025
c6f66f0
Use chatlas >= 0.6.1
schloerke Apr 3, 2025
a044f39
check if this helps webkit url assertion
karangattu Apr 3, 2025
126b41e
add some timeout for webkit browser tests
karangattu Apr 3, 2025
1bca258
bump it to 8 secs to see if it is a timing issue
karangattu Apr 3, 2025
35dbc75
bump it to 30 secs
karangattu Apr 3, 2025
ece58f7
bump timeout to 30 secs :(
karangattu Apr 3, 2025
800d03c
default is 30 seconds, duh
karangattu Apr 3, 2025
b80f8b1
explicit 30 sec wait
karangattu Apr 3, 2025
4e17e85
wait up to 30 secs
karangattu Apr 3, 2025
0af0826
add missing import
karangattu Apr 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## New features

* Added support for bookmarking Shiny applications. Bookmarking allows users to save the current state of an application and return to it later. This feature is available in both Shiny Core and Shiny Express. (#1870, #1915, #1919, #1920, #1922, #1934, #1938, #1945)
* To enable bookmarking in Express mode, set `shiny.express.app_opts(bookmark_store=)` during the app's initial construction.
* To enable bookmarking in Core mode, set `shiny.App(bookmark_store=)` when constructing the `app` object.

* Added a new `.enable_bookmarking(client)` method to `ui.Chat()`. This method will attach bookmark hooks to save and restore the chat's messages and client state. (#1951)

* Both `ui.Chat()` and `ui.MarkdownStream()` now support arbirary Shiny UI elements inside of messages. This allows for gathering input from the user (e.g., `ui.input_select()`), displaying of rich output (e.g., `render.DataGrid()`), and more. (#1868)

* Added a new `.message_stream_context()` method to `ui.Chat()`. This context manager is a useful alternative to `.append_message_stream()` when you want to: (1) Nest a stream within another and/or
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ dev = [
"langsmith<0.3",
"openai",
"ollama",
"chatlas>=0.6.0",
"tokenizers",
"aiohttp",
"beautifulsoup4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
chat = ui.Chat(id="chat")
chat.ui()

# Store chat state in the url when an "assistant" response occurs
chat.enable_bookmarking(chat_client, bookmark_store="url")


# Define a callback to run when the user submits a message
@chat.on_user_submit
Expand Down
3 changes: 3 additions & 0 deletions shiny/templates/chat/llm-enterprise/azure-openai/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
)
chat.ui()

# Store chat state in the url when an "assistant" response occurs
chat.enable_bookmarking(chat_client, bookmark_store="url")


# Define a callback to run when the user submits a message
@chat.on_user_submit
Expand Down
3 changes: 3 additions & 0 deletions shiny/templates/chat/llms/anthropic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
)
chat.ui()

# Store chat state in the url when an "assistant" response occurs
chat.enable_bookmarking(chat_client, bookmark_store="url")


# Generate a response when the user submits a message
@chat.on_user_submit
Expand Down
3 changes: 3 additions & 0 deletions shiny/templates/chat/llms/google/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
chat = ui.Chat(id="chat")
chat.ui()

# Store chat state in the url when an "assistant" response occurs
chat.enable_bookmarking(chat_client, bookmark_store="url")


# Generate a response when the user submits a message
@chat.on_user_submit
Expand Down
3 changes: 3 additions & 0 deletions shiny/templates/chat/llms/langchain/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
)
chat.ui()

# Store chat state in the url when an "assistant" response occurs
chat.enable_bookmarking(chat_client, bookmark_store="url")


# Define a callback to run when the user submits a message
@chat.on_user_submit
Expand Down
3 changes: 3 additions & 0 deletions shiny/templates/chat/llms/ollama/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
)
chat.ui()

# Store chat state in the url when an "assistant" response occurs
chat.enable_bookmarking(chat_client, bookmark_store="url")


# Generate a response when the user submits a message
@chat.on_user_submit
Expand Down
3 changes: 3 additions & 0 deletions shiny/templates/chat/llms/openai/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
)
chat.ui()

# Store chat state in the url when an "assistant" response occurs
chat.enable_bookmarking(chat_client, bookmark_store="url")


# Generate a response when the user submits a message
@chat.on_user_submit
Expand Down
Loading
Loading