Skip to content

Commit 59fc8bb

Browse files
committed
Use function to help with consistent behavior for appending init messages
1 parent e3f52b0 commit 59fc8bb

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

shiny/ui/_chat.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,16 @@ async def _mock_task() -> str:
302302

303303
# TODO: deprecate messages once we start promoting managing LLM message
304304
# state through other means
305-
@reactive.effect
306-
async def _init_chat():
305+
async def _append_init_messages():
307306
for msg in messages:
308307
await self.append_message(msg)
309308

309+
@reactive.effect
310+
async def _init_chat():
311+
await _append_init_messages()
312+
313+
self._append_init_messages = _append_init_messages
310314
self._init_chat = _init_chat
311-
self._init_chat_messages = messages
312315

313316
# When user input is submitted, transform, and store it in the chat state
314317
# (and make sure this runs before other effects since when the user
@@ -1576,8 +1579,7 @@ async def _on_restore_ui(state: RestoreState):
15761579
msgs: list[Any] = state.values[resolved_bookmark_id_msgs_str]
15771580
if not msgs:
15781581
# If no messages, set the default messages
1579-
for default_message in self._init_chat_messages:
1580-
await self.append_message(default_message)
1582+
await self._append_init_messages()
15811583
return
15821584

15831585
print("restored msgs", msgs)

0 commit comments

Comments
 (0)