Skip to content

Commit 05dc9f5

Browse files
authored
Remove .ui() method from Shiny Core's Chat component (#1840)
1 parent 3d1108c commit 05dc9f5

File tree

3 files changed

+55
-46
lines changed

3 files changed

+55
-46
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121

2222
* `ui.Chat()` now correctly handles new `ollama.chat()` return value introduced in `ollama` v0.4. (#1787)
2323

24+
### Changes
25+
26+
* The Shiny Core component `shiny.ui.Chat()` no longer has a `.ui()` method. This method
27+
was never intended to be used in Shiny Core (in that case, use `shiny.ui.chat_ui()`) to create the UI element. Note that the `shiny.express.ui.Chat()`
28+
class still has a `.ui()` method. (#1840)
29+
2430
## [1.2.1] - 2024-11-14
2531

2632
### Bug fixes

shiny/express/ui/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
AccordionPanel,
4242
AnimationOptions,
4343
CardItem,
44-
Chat,
4544
ShowcaseLayout,
4645
Sidebar,
4746
SliderStepArg,
@@ -146,6 +145,8 @@
146145
popover,
147146
)
148147

148+
from ...ui._chat import ChatExpress as Chat
149+
149150
from ...ui._markdown_stream import (
150151
ExpressMarkdownStream as MarkdownStream,
151152
)

shiny/ui/_chat.py

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
__all__ = (
4646
"Chat",
47+
"ChatExpress",
4748
"chat_ui",
4849
"ChatMessage",
4950
)
@@ -246,51 +247,6 @@ async def _on_user_input():
246247
instance.destroy()
247248
CHAT_INSTANCES[instance_id] = self
248249

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-
294250
@overload
295251
def on_user_submit(self, fn: UserSubmitFunction) -> reactive.Effect_: ...
296252

@@ -1048,6 +1004,52 @@ async def _send_custom_message(self, handler: str, obj: ClientMessage | None):
10481004
)
10491005

10501006

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+
10511053
@add_example(ex_dir="../templates/chat/starters/hello")
10521054
def chat_ui(
10531055
id: str,

0 commit comments

Comments
 (0)