posit-dev / py-shiny

Shiny for Python
https://shiny.posit.co/py/
MIT License
1.32k stars 81 forks source link

Add `messages` parameter to `chat_ui()` and `Chat.ui()`; revert #1593 #1736

Closed cpsievert closed 1 month ago

cpsievert commented 1 month ago

With this PR, the messages parameter of Chat.ui()/chat_ui() becomes the suggested way to provide starting messages. For example:

Express ````python from shiny import reactive from shiny.express import ui chat = ui.Chat(id="chat") chat.ui(messages=["Hello, how can I help?"]) ````
Core ```python from shiny import App, ui app_ui = ui.page_fixed( ui.chat_ui("chat", messages=["Hello, how are you?"]), ) def server(input, output, session): pass app = App(app_ui, server) ```

This PR also reverts #1593 since waiting until flush to send is not an ideal way to support dynamic UI. As a result, this PR also closes #1735.

In the next release, we should deprecate Chat(messages=...) in favor of these new parameters. Deprecating now feels premature since it's still convenient for things like system messages. But, when we move towards recommending chatlas/LangChain for managing chat state in a future release, we'll deprecate as a part of that move.