Skip to content

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