Skip to content

[Feature]: ui.Chat bookmark support #1918

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

Closed
schloerke opened this issue Mar 14, 2025 · 1 comment · Fixed by #1951
Closed

[Feature]: ui.Chat bookmark support #1918

schloerke opened this issue Mar 14, 2025 · 1 comment · Fixed by #1951
Assignees
Labels
enhancement New feature or request

Comments

@schloerke
Copy link
Collaborator

Category

UI Components

Scope

Minor Enhancement

Problem

Chat doesn't restore from bookmarked state. It'd be nice to have this feature!

Solution

It should store information in the bookmark state (values?)

Last chat input value should be ignored.

Related R implementation: posit-dev/shinychat#28

Alternatives (Optional)

No response

Example (Optional)

Impact (Optional)

No response

Contribution? (Optional)

Yes, I can implement (or help).

@schloerke schloerke added enhancement New feature or request needs-triage labels Mar 14, 2025
@schloerke schloerke self-assigned this Mar 17, 2025
@schloerke
Copy link
Collaborator Author

schloerke commented Mar 19, 2025

After talking with @cpsievert ...

chat_client = chatlas.ChatOpenAI(model="gpt-4o-mini")

# Create and display a Shiny chat component
chat = ui.Chat(
    id="chat",
    messages=[
        {"role": "assistant", "content": "Hello! How can I help you today?"}
    ],
)
chat.ui()


chat.enable_bookmarking(
    client=chat_client,
    # ONLY for ChatExpress. For core Chat, use the `App` directly
    bookmark_store="url",
)

chat.enable_bookmarking() TODOs

  • Exclude the chat user input from bookmarking
  • Add a on_bookmark hook
  • Add a on_restore hook
  • Adjust default messages to be ignored if restoration occurs.
  • For express mode only, add parameter bookmark_store: BookmarkStore to reduce code burden in express mode
  • Add a parameter for "on session disconnect, update the query string" as a last-ditch-effort to save the chat state; On restore of this state, reset the query string if there was no query string before the last-ditch-effort.
  • Do NOT: register on_bookmarked to update query string automatically
  • Do NOT: register effect to bookmark when .messages() updates. This should be done through templating to give Authors freedom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant