feat(py): Add client= parameter to Chat for batteries-included chatlas apps#233
Open
cpsievert wants to merge 4 commits into
Open
feat(py): Add client= parameter to Chat for batteries-included chatlas apps#233cpsievert wants to merge 4 commits into
cpsievert wants to merge 4 commits into
Conversation
787b682 to
a882451
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Add chat_auto_ui(), chat_auto_server(), and ChatExpress.ui_auto() — a high-level API that wires streaming, cancellation, and bookmarking to a chatlas client automatically. Also fix enable_bookmarking() to silently no-op when no bookmark store is configured (both Python and R), so it can be called unconditionally.
Instead of a separate ChatAutoServer/chat_auto_server/chat_auto_ui API surface, users now pass client= directly to Chat(). When provided, streaming, cancellation, bookmarking, and greeting handling are wired up automatically. The client-specific surface lives on a ChatClient wrapper at chat.client, with .value (raw chatlas object), .set() for swapping models mid-session, and .clear() for resetting conversation history. Express mode auto-defaults enable_cancel=True when a client is set. - Add _chat_client.py with ChatClient class and helpers - Add client=, greeting=, bookmark_on= params to Chat.__init__ - Add _setup_client() for reactive wiring - Remove _chat_auto.py, ChatAutoServer, chat_auto_server, chat_auto_ui - Remove ChatExpress.ui_auto() method - Remove bookmark-store raise from enable_bookmarking() - Update exports, tests, docs, and changelog
b45d438 to
a9d70b9
Compare
… public API greeting= now works regardless of whether client= is provided. bookmark_on is hardcoded to "response" internally. Removed the thin _setup_greeting wrapper; added docstrings for client and greeting parameters.
Collaborator
Author
|
@gadenbuie there's a bit more review and polish I'd like to do here, but before I do, would be great to have a gut check from you in terms of the overall shape of the proposal here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Building a chatbot with shinychat + chatlas currently requires manually wiring up streaming, cancellation, and bookmarking — roughly 20-30 lines of boilerplate that look the same in every app. This PR adds a
client=parameter toChatthat handles all of it automatically.Express:
Core:
No new API surface to learn — just one parameter on the class you already know. Client-specific methods live on a
ChatClientwrapper atchat.client:.value— the raw chatlas client.set(new_client, sync=True)— swap models mid-session (deferred if streaming).clear(client_history="clear")— reset UI and client turn historyIn Express mode,
enable_canceldefaults toTruewhen a client is set.R package changes
chat_mod_server()now returnsset_client(new_client, sync=TRUE)for swapping clients at runtime, and astatusreactive ("idle"/"streaming").chat_restore()returns a cancel function for clean re-registration during client swaps.Other changes
enable_bookmarking()no longer raises when no bookmark store is configured — it silently no-ops instead.Chat(client=...)as the recommended path.Test plan
uv run pytest— unit tests verify ChatClient behavior (swap, clear, exports, messages_to_turns)uv run pytest pkg-py/tests/playwright— Playwright tests cover Express, Core, cancellation, and bookmark-no-store flowsuv run pyright— type checking passesuv run ruff check pkg-py --config pyproject.toml— linting passescd pkg-r && Rscript -e "devtools::check(document=FALSE)"still passes