|
44 | 44 |
|
45 | 45 | __all__ = ( |
46 | 46 | "Chat", |
| 47 | + "ChatExpress", |
47 | 48 | "chat_ui", |
48 | 49 | "ChatMessage", |
49 | 50 | ) |
@@ -246,51 +247,6 @@ async def _on_user_input(): |
246 | 247 | instance.destroy() |
247 | 248 | CHAT_INSTANCES[instance_id] = self |
248 | 249 |
|
249 | | - def ui( |
250 | | - self, |
251 | | - *, |
252 | | - messages: Optional[Sequence[str | ChatMessage]] = None, |
253 | | - placeholder: str = "Enter a message...", |
254 | | - width: CssUnit = "min(680px, 100%)", |
255 | | - height: CssUnit = "auto", |
256 | | - fill: bool = True, |
257 | | - **kwargs: TagAttrValue, |
258 | | - ) -> Tag: |
259 | | - """ |
260 | | - Place a chat component in the UI. |
261 | | -
|
262 | | - This method is only relevant fpr Shiny Express. In Shiny Core, use |
263 | | - :func:`~shiny.ui.chat_ui` instead to insert the chat UI. |
264 | | -
|
265 | | - Parameters |
266 | | - ---------- |
267 | | - messages |
268 | | - A sequence of messages to display in the chat. Each message can be either a |
269 | | - string or a dictionary with `content` and `role` keys. The `content` key |
270 | | - should contain the message text, and the `role` key can be "assistant" or |
271 | | - "user". |
272 | | - placeholder |
273 | | - Placeholder text for the chat input. |
274 | | - width |
275 | | - The width of the chat container. |
276 | | - height |
277 | | - The height of the chat container. |
278 | | - fill |
279 | | - Whether the chat should vertically take available space inside a fillable |
280 | | - container. |
281 | | - kwargs |
282 | | - Additional attributes for the chat container element. |
283 | | - """ |
284 | | - return chat_ui( |
285 | | - id=self.id, |
286 | | - messages=messages, |
287 | | - placeholder=placeholder, |
288 | | - width=width, |
289 | | - height=height, |
290 | | - fill=fill, |
291 | | - **kwargs, |
292 | | - ) |
293 | | - |
294 | 250 | @overload |
295 | 251 | def on_user_submit(self, fn: UserSubmitFunction) -> reactive.Effect_: ... |
296 | 252 |
|
@@ -1048,6 +1004,52 @@ async def _send_custom_message(self, handler: str, obj: ClientMessage | None): |
1048 | 1004 | ) |
1049 | 1005 |
|
1050 | 1006 |
|
| 1007 | +@add_example(ex_dir="../templates/chat/starters/hello") |
| 1008 | +class ChatExpress(Chat): |
| 1009 | + |
| 1010 | + def ui( |
| 1011 | + self, |
| 1012 | + *, |
| 1013 | + messages: Optional[Sequence[str | ChatMessage]] = None, |
| 1014 | + placeholder: str = "Enter a message...", |
| 1015 | + width: CssUnit = "min(680px, 100%)", |
| 1016 | + height: CssUnit = "auto", |
| 1017 | + fill: bool = True, |
| 1018 | + **kwargs: TagAttrValue, |
| 1019 | + ) -> Tag: |
| 1020 | + """ |
| 1021 | + Create a UI element for this `Chat`. |
| 1022 | +
|
| 1023 | + Parameters |
| 1024 | + ---------- |
| 1025 | + messages |
| 1026 | + A sequence of messages to display in the chat. Each message can be either a |
| 1027 | + string or a dictionary with `content` and `role` keys. The `content` key |
| 1028 | + should contain the message text, and the `role` key can be "assistant" or |
| 1029 | + "user". |
| 1030 | + placeholder |
| 1031 | + Placeholder text for the chat input. |
| 1032 | + width |
| 1033 | + The width of the UI element. |
| 1034 | + height |
| 1035 | + The height of the UI element. |
| 1036 | + fill |
| 1037 | + Whether the chat should vertically take available space inside a fillable |
| 1038 | + container. |
| 1039 | + kwargs |
| 1040 | + Additional attributes for the chat container element. |
| 1041 | + """ |
| 1042 | + return chat_ui( |
| 1043 | + id=self.id, |
| 1044 | + messages=messages, |
| 1045 | + placeholder=placeholder, |
| 1046 | + width=width, |
| 1047 | + height=height, |
| 1048 | + fill=fill, |
| 1049 | + **kwargs, |
| 1050 | + ) |
| 1051 | + |
| 1052 | + |
1051 | 1053 | @add_example(ex_dir="../templates/chat/starters/hello") |
1052 | 1054 | def chat_ui( |
1053 | 1055 | id: str, |
|
0 commit comments