Skip to content

Commit 65db8e4

Browse files
cpsievertCopilot
andauthored
chore: update Chat API reference example (#2050)
Co-authored-by: Copilot <[email protected]>
1 parent 621fbaf commit 65db8e4

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

shiny/api-examples/Chat/app-core.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@
33
app_ui = ui.page_fillable(
44
ui.panel_title("Hello Shiny Chat"),
55
ui.chat_ui("chat"),
6-
fillable_mobile=True,
7-
)
8-
9-
# Create a welcome message
10-
welcome = """
6+
ui.chat_ui(
7+
"chat",
8+
messages=[
9+
"""
1110
Hi! This is a simple Shiny `Chat` UI. Enter a message below and I will
1211
simply repeat it back to you.
1312
1413
To learn more about chatbots and how to build them with Shiny, check out
1514
[the documentation](https://shiny.posit.co/py/docs/genai-chatbots.html).
1615
"""
16+
],
17+
),
18+
fillable_mobile=True,
19+
)
1720

1821

1922
def server(input, output, session):
20-
chat = ui.Chat(id="chat", messages=[welcome])
23+
chat = ui.Chat(id="chat")
2124

2225
# Define a callback to run when the user submits a message
2326
@chat.on_user_submit

shiny/api-examples/Chat/app-express.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,22 @@
77
fillable_mobile=True,
88
)
99

10-
# Create a welcome message
11-
welcome = """
10+
# Create a chat instance
11+
chat = ui.Chat(id="chat")
12+
13+
# Display it, with a startup message
14+
chat.ui(
15+
messages=[
16+
"""
1217
Hi! This is a simple Shiny `Chat` UI. Enter a message below and I will
1318
simply repeat it back to you.
1419
1520
To learn more about chatbots and how to build them with Shiny, check out
1621
[the documentation](https://shiny.posit.co/py/docs/genai-chatbots.html).
1722
"""
18-
19-
# Create a chat instance
20-
chat = ui.Chat(
21-
id="chat",
22-
messages=[welcome],
23+
],
2324
)
2425

25-
# Display it
26-
chat.ui()
27-
2826

2927
# Define a callback to run when the user submits a message
3028
@chat.on_user_submit

0 commit comments

Comments
 (0)