Skip to content

Commit bd323ff

Browse files
committed
First pass at updating chat component page for a chatlas world
1 parent 642b7f1 commit bd323ff

File tree

5 files changed

+205
-148
lines changed

5 files changed

+205
-148
lines changed

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
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}") # <<

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)