From f0c0954fb4ad68c6116d1d03af03db5c80dda5e8 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Tue, 7 Jan 2025 15:29:52 -0500 Subject: [PATCH 1/3] Use `.stream_async()` when streaming. Await the value --- chatlas/_chat.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/chatlas/_chat.py b/chatlas/_chat.py index 8dfd109a..c20b76c0 100644 --- a/chatlas/_chat.py +++ b/chatlas/_chat.py @@ -388,6 +388,7 @@ def app( port: int = 0, launch_browser: bool = True, bg_thread: Optional[bool] = None, + echo: Optional[Literal["text", "all", "none"]] = None, kwargs: Optional[SubmitInputArgsT] = None, ): """ @@ -438,7 +439,10 @@ async def _(): return if stream: await chat.append_message_stream( - self.stream(user_input, kwargs=kwargs) + await self.stream_async( + user_input, + kwargs=kwargs, + ) ) else: await chat.append_message(str(self.chat(user_input, kwargs=kwargs))) From ff5a8fa8381562a035a853aedd571ad89149724a Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Tue, 7 Jan 2025 15:30:27 -0500 Subject: [PATCH 2/3] Add `echo=` to `.app` so that tool calls can be exposed. --- chatlas/_chat.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/chatlas/_chat.py b/chatlas/_chat.py index c20b76c0..29021ebd 100644 --- a/chatlas/_chat.py +++ b/chatlas/_chat.py @@ -405,6 +405,8 @@ def app( bg_thread Whether to run the app in a background thread. If `None`, the app will run in a background thread if the current environment is a notebook. + echo + Whether to echo text content, all content (i.e., tool calls), or no content. Defaults to `"none"` when `stream=True` and `"text"` when `stream=False`. kwargs Additional keyword arguments to pass to the method used for requesting the response. @@ -442,10 +444,19 @@ async def _(): await self.stream_async( user_input, kwargs=kwargs, + echo=echo or "none", ) ) else: - await chat.append_message(str(self.chat(user_input, kwargs=kwargs))) + await chat.append_message( + str( + self.chat( + user_input, + kwargs=kwargs, + echo=echo or "text", + ) + ) + ) app = App(app_ui, server) From 18a8137a093210ba9d5c33a06926a8d67d636434 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Thu, 9 Jan 2025 15:40:40 -0500 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec6d0cc1..fad9aa61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,8 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### New features +* Added `.app(*, echo=)` support. This allows for chatlas to change the echo behavior when running the Shiny app. (#31) + ### Bug fixes +* Fix broken `Chat`'s Shiny app when `.app(*, stream=True)` by using async chat tools. (#31) * Update formatting of exported markdown to use `repr()` instead of `str()` when exporting tool call results. (#30) ## [0.3.0] - 2024-12-20