|  | 
| 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 | 
 | 
| @@ -1051,6 +1007,52 @@ async def _send_custom_message(self, handler: str, obj: ClientMessage | None): | 
| 1051 | 1007 |         ) | 
| 1052 | 1008 | 
 | 
| 1053 | 1009 | 
 | 
|  | 1010 | +@add_example(ex_dir="../templates/chat/starters/hello") | 
|  | 1011 | +class ChatExpress(Chat): | 
|  | 1012 | + | 
|  | 1013 | +    def ui( | 
|  | 1014 | +        self, | 
|  | 1015 | +        *, | 
|  | 1016 | +        messages: Optional[Sequence[str | ChatMessage]] = None, | 
|  | 1017 | +        placeholder: str = "Enter a message...", | 
|  | 1018 | +        width: CssUnit = "min(680px, 100%)", | 
|  | 1019 | +        height: CssUnit = "auto", | 
|  | 1020 | +        fill: bool = True, | 
|  | 1021 | +        **kwargs: TagAttrValue, | 
|  | 1022 | +    ) -> Tag: | 
|  | 1023 | +        """ | 
|  | 1024 | +        Create a UI element for this `Chat`. | 
|  | 1025 | +
 | 
|  | 1026 | +        Parameters | 
|  | 1027 | +        ---------- | 
|  | 1028 | +        messages | 
|  | 1029 | +            A sequence of messages to display in the chat. Each message can be either a | 
|  | 1030 | +            string or a dictionary with `content` and `role` keys. The `content` key | 
|  | 1031 | +            should contain the message text, and the `role` key can be "assistant" or | 
|  | 1032 | +            "user". | 
|  | 1033 | +        placeholder | 
|  | 1034 | +            Placeholder text for the chat input. | 
|  | 1035 | +        width | 
|  | 1036 | +            The width of the UI element. | 
|  | 1037 | +        height | 
|  | 1038 | +            The height of the UI element. | 
|  | 1039 | +        fill | 
|  | 1040 | +            Whether the chat should vertically take available space inside a fillable | 
|  | 1041 | +            container. | 
|  | 1042 | +        kwargs | 
|  | 1043 | +            Additional attributes for the chat container element. | 
|  | 1044 | +        """ | 
|  | 1045 | +        return chat_ui( | 
|  | 1046 | +            id=self.id, | 
|  | 1047 | +            messages=messages, | 
|  | 1048 | +            placeholder=placeholder, | 
|  | 1049 | +            width=width, | 
|  | 1050 | +            height=height, | 
|  | 1051 | +            fill=fill, | 
|  | 1052 | +            **kwargs, | 
|  | 1053 | +        ) | 
|  | 1054 | + | 
|  | 1055 | + | 
| 1054 | 1056 | @add_example(ex_dir="../templates/chat/starters/hello") | 
| 1055 | 1057 | def chat_ui( | 
| 1056 | 1058 |     id: str, | 
|  | 
0 commit comments