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

Conversation

schloerke
Copy link
Collaborator

@schloerke schloerke commented Apr 1, 2025

Fixes #1918

# File: app-express.py

# ------------------------------------------------------------------------------------
# A basic Shiny Chat example powered by Ollama.
# ------------------------------------------------------------------------------------

from chatlas import ChatOllama

from shiny.express import ui

# ChatOllama() requires an Ollama model server to be running locally.
# See the docs for more information on how to set up a local Ollama server.
# https://posit-dev.github.io/chatlas/reference/ChatOllama.html
chat_client = ChatOllama(model="llama3.2")

# Set some Shiny page options
ui.page_opts(
    title="Hello Ollama Chat",
    fillable=True,
    fillable_mobile=True,
)

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

### 
# New code
##
chat.enable_bookmarking(chat_client, store="url")
## / new code

# Generate a response when the user submits a message
@chat.on_user_submit
async def handle_user_input(user_input: str):
    response = await chat_client.stream_async(user_input)
    await chat.append_message_stream(response)

@schloerke schloerke enabled auto-merge (squash) April 3, 2025 16:18
@schloerke schloerke merged commit 6c5ae7e into main Apr 3, 2025
53 of 54 checks passed
@schloerke schloerke deleted the bookmark-chat branch April 3, 2025 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: ui.Chat bookmark support
3 participants