Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ website:
- components/outputs/verbatim-text/index.qmd
- section: "![](/images/chat-dots-fill.svg){.sidebar-icon .sidebar-subtitle}__Display Messages__"
contents:
- components/display-messages/chat/index.qmd
- components/display-messages/modal/index.qmd
- components/display-messages/notifications/index.qmd
- components/display-messages/progress-bar/index.qmd
Expand Down
4 changes: 2 additions & 2 deletions components/display-messages/chat/app-core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def server(input):

# Define a callback to run when the user submits a message
@chat.on_user_submit # <<
async def _(): # <<
async def handle_user_input(user_input: str): # <<
# Simply echo the user's input back to them
await chat.append_message(f"You said: {chat.user_input()}") # <<
await chat.append_message(f"You said: {user_input}") # <<


app = App(app_ui, server)
10 changes: 5 additions & 5 deletions components/display-messages/chat/app-express.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
fillable_mobile=True,
)

# Create a chat instance and display it
# Create a chat instance and display it # <<
chat = ui.Chat(id="chat") # <<
chat.ui() # <<


# Define a callback to run when the user submits a message
# Define a callback to run when the user submits a message # <<
@chat.on_user_submit # <<
async def _(): # <<
# Simply echo the user's input back to them
await chat.append_message(f"You said: {chat.user_input()}") # <<
async def handle_user_input(user_input: str): # <<
# Simply echo the user's input back to them # <<
await chat.append_message(f"You said: {user_input}") # <<
4 changes: 2 additions & 2 deletions components/display-messages/chat/app-preview-code.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@

# Define a callback to run when the user submits a message
@chat.on_user_submit
async def _():
async def handle_user_input(user_input: str):
# Append a response to the chat
await chat.append_message(f"You said: {chat.user_input()}")
await chat.append_message(f"You said: {user_input}")
11 changes: 3 additions & 8 deletions components/display-messages/chat/app-preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""
Hi! This is a simple Shiny `Chat` UI. Enter a message below and I will
simply repeat it back to you. For more examples, see this
[folder of examples](https://github.com/posit-dev/py-shiny/tree/main/examples/chat).
[folder of examples](https://github.com/posit-dev/py-shiny/tree/main/shiny/templates/chat).
"""
)

Expand All @@ -28,11 +28,6 @@

# Define a callback to run when the user submits a message
@chat.on_user_submit
async def _():
# Get the chat messages.
messages = chat.messages()
# Typically you'd pass messages to an LLM for response generation,
# but for this example, we'll just echo the user's input
user = messages[-1]["content"]
async def handle_user_input(user_input: str):
# Append a response to the chat
await chat.append_message(f"You said: {user}")
await chat.append_message(f"You said: {user_input}")
Loading
Loading