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

Pare down python Chat features #62

wants to merge 3 commits into from

Conversation

cpsievert
Copy link
Collaborator

This PR removes some features in Chat that predate chatlas and add a lot of complexity to the implementation without much benefit.

For reference, here is the list:

  • Chat(messages=) was removed. Use chat.ui(messages=) instead.
  • Chat(tokenizer=) was removed. This was only relevant for .messages(token_limits=[]) which was also removed.
  • Several parameters were removed from .messages(). This reflects an overall change approach for maintaining the conversation history sent to the LLM -- Chat should no longer be responsible for maintaining this conversation state, and instead, another stateful object (perhaps the one provided by chatlas, Pydantic AI, LangChain, etc.) should be used to maintain this state. That said, .messages() can still be useful if you want a reflection of the message state on the client.
  • The transform_user_input and transform_assistant_response decorators were removed. This change also reflects the new recommendation of using another stateful object to submit input and retain conversation history.
  • .user_input()'s transform parameter was removed (as a consequence of the previous point).
  • The already deprecated .set_user_message() method was officially removed (in favor of .update_user_input())

NOTE: Although these features are removed here, we should do a py-shiny release that deprecates these features first, then removes them full-stop when we move to re-export shinychat in shiny.

Follow up

  • Create shiny PR to deprecate these features
  • Possibly externalize the _chat_normalize.py logic into a more explicit API for transforming provider-specific completion objects into a ChatMessage/ChatMessageDict. That way .append_message() et al. can have a stronger message type.
  • When we eventually go to re-export shinychat in shiny, remove the "3rd party" LLM dependencies from shiny's pyproject.toml

@cpsievert cpsievert mentioned this pull request May 30, 2025
3 tasks
@cpsievert cpsievert requested a review from Copilot May 30, 2025 16:42
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR pares down the Chat module by removing legacy features and simplifying the API. Key changes include the removal of deprecated decorators, test files for transform functionality, and legacy tokenizer/provider type support.

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg-py/tests/playwright/chat/transform_assistant_stream/* Removal of tests related to the transform_assistant_response decorator.
pkg-py/tests/playwright/chat/transform_assistant/, pkg-py/tests/playwright/chat/transform/ Entirely removed tests and app code for legacy transform features.
pkg-py/tests/playwright/chat/shiny_output/, pkg-py/tests/playwright/chat/shiny_input/, pkg-py/tests/playwright/chat/input-suggestion/, pkg-py/tests/playwright/chat/icon/, pkg-py/tests/playwright/chat/basic/* Updated Chat instantiation to use ui() parameters for messages.
pkg-py/src/shinychat/_chat_types.py Removed the TransformedMessage data class.
pkg-py/src/shinychat/_chat_tokenizer.py Removed legacy tokenizer-related support.
pkg-py/src/shinychat/_chat_provider_types.py Removed provider types and conversion functions.
Comments suppressed due to low confidence (4)

pkg-py/tests/playwright/chat/basic/test_chat_basic.py:44

  • Confirm that removing the default assistant message expectation aligns with the new Chat API behavior; update documentation if necessary.
-            {"content": initial_message, "role": "assistant"},

pkg-py/src/shinychat/_chat_provider_types.py:1

  • The removal of provider types represents a breaking change; ensure downstream consumers are informed and documentation is updated.
import sys

pkg-py/src/shinychat/_chat_tokenizer.py:1

  • Verify that no remaining parts of the codebase rely on the legacy tokenizer functionality now that this file has been removed.
from __future__ import annotations

pkg-py/tests/playwright/chat/icon/app.py:18

  • [nitpick] Ensure that moving the messages parameter from the Chat initializer to the ui() method is clearly communicated in API documentation to avoid user confusion.
chat_default.ui(icon_assistant=None)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant