Skip to content

Commit 2cc9266

Browse files
authored
Update chat component page (#237)
* First pass at updating chat component page for a chatlas world * wip write about newer chat additions * moar * moar * Getting closer * Nearing a 1st draft * Close #212: Add chat component to sidebar
1 parent f4b28ed commit 2cc9266

18 files changed

+980
-163
lines changed

_quarto.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ website:
171171
- components/outputs/verbatim-text/index.qmd
172172
- section: "![](/images/chat-dots-fill.svg){.sidebar-icon .sidebar-subtitle}__Display Messages__"
173173
contents:
174+
- components/display-messages/chat/index.qmd
174175
- components/display-messages/modal/index.qmd
175176
- components/display-messages/notifications/index.qmd
176177
- components/display-messages/progress-bar/index.qmd

components/display-messages/chat/app-core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ def server(input):
1313

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

2020

2121
app = App(app_ui, server)

components/display-messages/chat/app-express.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
fillable_mobile=True,
77
)
88

9-
# Create a chat instance and display it
9+
# Create a chat instance and display it # <<
1010
chat = ui.Chat(id="chat") # <<
1111
chat.ui() # <<
1212

1313

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

components/display-messages/chat/app-preview-code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
# Define a callback to run when the user submits a message
1616
@chat.on_user_submit
17-
async def _():
17+
async def handle_user_input(user_input: str):
1818
# Append a response to the chat
19-
await chat.append_message(f"You said: {chat.user_input()}")
19+
await chat.append_message(f"You said: {user_input}")

components/display-messages/chat/app-preview.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"""
1313
Hi! This is a simple Shiny `Chat` UI. Enter a message below and I will
1414
simply repeat it back to you. For more examples, see this
15-
[folder of examples](https://github.com/posit-dev/py-shiny/tree/main/examples/chat).
15+
[folder of examples](https://github.com/posit-dev/py-shiny/tree/main/shiny/templates/chat).
1616
"""
1717
)
1818

@@ -28,11 +28,6 @@
2828

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

0 commit comments

Comments
 (0)