Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove .ui() method from Shiny Core's Chat component #1840

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

### Changes

* The `shiny.ui.Chat()` class no longer has a `.ui()` method. This method
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()`
class still has a `.ui()` method. (#1840)
cpsievert marked this conversation as resolved.
Show resolved Hide resolved
cpsievert marked this conversation as resolved.
Show resolved Hide resolved

## [1.2.1] - 2024-11-14

### Bug fixes
Expand Down
3 changes: 2 additions & 1 deletion shiny/express/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
AccordionPanel,
AnimationOptions,
CardItem,
Chat,
ShowcaseLayout,
Sidebar,
SliderStepArg,
Expand Down Expand Up @@ -146,6 +145,8 @@
popover,
)

from ...ui._chat import ChatExpress as Chat

from ...ui._markdown_stream import (
ExpressMarkdownStream as MarkdownStream,
)
Expand Down
92 changes: 47 additions & 45 deletions shiny/ui/_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

__all__ = (
"Chat",
"ChatExpress",
"chat_ui",
"ChatMessage",
)
Expand Down Expand Up @@ -246,51 +247,6 @@ async def _on_user_input():
instance.destroy()
CHAT_INSTANCES[instance_id] = self

def ui(
self,
*,
messages: Optional[Sequence[str | ChatMessage]] = None,
placeholder: str = "Enter a message...",
width: CssUnit = "min(680px, 100%)",
height: CssUnit = "auto",
fill: bool = True,
**kwargs: TagAttrValue,
) -> Tag:
"""
Place a chat component in the UI.

This method is only relevant fpr Shiny Express. In Shiny Core, use
:func:`~shiny.ui.chat_ui` instead to insert the chat UI.

Parameters
----------
messages
A sequence of messages to display in the chat. Each message can be either a
string or a dictionary with `content` and `role` keys. The `content` key
should contain the message text, and the `role` key can be "assistant" or
"user".
placeholder
Placeholder text for the chat input.
width
The width of the chat container.
height
The height of the chat container.
fill
Whether the chat should vertically take available space inside a fillable
container.
kwargs
Additional attributes for the chat container element.
"""
return chat_ui(
id=self.id,
messages=messages,
placeholder=placeholder,
width=width,
height=height,
fill=fill,
**kwargs,
)

@overload
def on_user_submit(self, fn: UserSubmitFunction) -> reactive.Effect_: ...

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


@add_example(ex_dir="../templates/chat/starters/hello")
class ChatExpress(Chat):

def ui(
self,
*,
messages: Optional[Sequence[str | ChatMessage]] = None,
placeholder: str = "Enter a message...",
width: CssUnit = "min(680px, 100%)",
height: CssUnit = "auto",
fill: bool = True,
**kwargs: TagAttrValue,
) -> Tag:
"""
Create a UI element for this `Chat`.

Parameters
----------
messages
A sequence of messages to display in the chat. Each message can be either a
string or a dictionary with `content` and `role` keys. The `content` key
should contain the message text, and the `role` key can be "assistant" or
"user".
placeholder
Placeholder text for the chat input.
width
The width of the UI element.
height
The height of the UI element.
fill
Whether the chat should vertically take available space inside a fillable
container.
kwargs
Additional attributes for the chat container element.
"""
return chat_ui(
id=self.id,
messages=messages,
placeholder=placeholder,
width=width,
height=height,
fill=fill,
**kwargs,
)


@add_example(ex_dir="../templates/chat/starters/hello")
def chat_ui(
id: str,
Expand Down
Loading