Skip to content

Pare down python Chat features #62

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
606 changes: 31 additions & 575 deletions pkg-py/src/shinychat/_chat.py

Large diffs are not rendered by default.

127 changes: 0 additions & 127 deletions pkg-py/src/shinychat/_chat_provider_types.py

This file was deleted.

67 changes: 0 additions & 67 deletions pkg-py/src/shinychat/_chat_tokenizer.py

This file was deleted.

32 changes: 1 addition & 31 deletions pkg-py/src/shinychat/_chat_types.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Literal, TypedDict

from htmltools import HTML, TagChild
from htmltools import TagChild
from shiny.session import require_active_session

from ._typing_extensions import NotRequired
Expand Down Expand Up @@ -39,35 +38,6 @@ def __init__(
self.html_deps = deps


# A message once transformed have been applied
@dataclass
class TransformedMessage:
content_client: str | HTML
content_server: str
role: Role
transform_key: Literal["content_client", "content_server"]
pre_transform_key: Literal["content_client", "content_server"]
html_deps: list[dict[str, str]] | None = None

@classmethod
def from_chat_message(cls, message: ChatMessage) -> "TransformedMessage":
if message.role == "user":
transform_key = "content_server"
pre_transform_key = "content_client"
else:
transform_key = "content_client"
pre_transform_key = "content_server"

return TransformedMessage(
content_client=message.content,
content_server=message.content,
role=message.role,
transform_key=transform_key,
pre_transform_key=pre_transform_key,
html_deps=message.html_deps,
)


# A message that can be sent to the client
class ClientMessage(TypedDict):
content: str
Expand Down
9 changes: 2 additions & 7 deletions pkg-py/tests/playwright/chat/basic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@
ui.page_opts(title="Hello Chat")

# Create a chat instance, with an initial message
chat = Chat(
id="chat",
messages=[
{"content": "Hello! How can I help you today?", "role": "assistant"},
],
)
chat = Chat(id="chat")

# Display the chat
chat.ui()
chat.ui(messages=["Hello! How can I help you today?"])


# Define a callback to run when the user submits a message
Expand Down
1 change: 0 additions & 1 deletion pkg-py/tests/playwright/chat/basic/test_chat_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def test_validate_chat_basic(page: Page, local_app: ShinyAppProc) -> None:
message_state = controller.OutputCode(page, "message_state")
message_state_expected = tuple(
[
{"content": initial_message, "role": "assistant"},
{"content": f"\n{user_message}", "role": "user"},
{"content": f"You said: \n{user_message}", "role": "assistant"},
{"content": f"{user_message2}", "role": "user"},
Expand Down
15 changes: 5 additions & 10 deletions pkg-py/tests/playwright/chat/icon/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,14 @@

with ui.layout_columns():
# Default Bot ---------------------------------------------------------------------
chat_default = Chat(
id="chat_default",
messages=[
{
"content": "Hello! I'm Default Bot. How can I help you today?",
"role": "assistant",
},
],
)
chat_default = Chat(id="chat_default")

with ui.div():
ui.h2("Default Bot")
chat_default.ui(icon_assistant=None)
chat_default.ui(
messages=["Hello! I'm Default Bot. How can I help you today?"],
icon_assistant=None,
)

@chat_default.on_user_submit
async def handle_user_input_default(user_input: str):
Expand Down
4 changes: 2 additions & 2 deletions pkg-py/tests/playwright/chat/input-suggestion/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
And <span id="fifth" data-suggestion="another suggestion" data-suggestion-submit="true">this suggestion will also auto-submit</span>.</p>
"""

chat = Chat("chat", messages=[suggestion2])
chat = Chat("chat")

chat.ui(messages=[suggestions1])
chat.ui(messages=[suggestions1, suggestion2])


@chat.on_user_submit
Expand Down
6 changes: 3 additions & 3 deletions pkg-py/tests/playwright/chat/shiny_input/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
),
)

chat = Chat(
id="chat",
chat = Chat(id="chat")
chat.ui(
class_="mb-5",
messages=[welcome],
)
chat.ui(class_="mb-5")


@reactive.effect
Expand Down
7 changes: 2 additions & 5 deletions pkg-py/tests/playwright/chat/shiny_output/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ def map():
return ipyl.Map(center=(52, 10), zoom=8)


chat = ui.Chat(
id="chat",
messages=[map_ui],
)
chat = ui.Chat(id="chat")

chat.ui()
chat.ui(messages=[map_ui])

with ui.hold() as df_1:

Expand Down
46 changes: 0 additions & 46 deletions pkg-py/tests/playwright/chat/transform/app.py

This file was deleted.

Loading
Loading