Skip to content
Closed
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
12 changes: 12 additions & 0 deletions pkg-py/docs/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ quartodoc:
- Chat
- chat_ui
- chat_greeting
- title: Chat Module
options:
signature_name: relative
include_imports: false
include_inherited: false
include_attributes: true
include_classes: true
include_functions: true
contents:
- chat_mod_ui
- chat_mod_server
- ChatServerState
- title: Shiny Express
options:
signature_name: relative
Expand Down
23 changes: 23 additions & 0 deletions pkg-py/docs/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,29 @@ Key points:
- Pass the controller to `stream_async(controller=ctrl)` so chatlas can honour the cancellation signal.
- The cancel input fires as `input.<id>_cancel` (e.g. `input.chat_cancel`). Observe it with `@reactive.event` to call `ctrl.cancel()`. This is needed in both Express and Core apps.
- Partial responses are automatically preserved in chat history by chatlas when a stream is cancelled.
- If you use `chat_mod_server()`, cancellation is handled automatically — no manual wiring needed.

## Chat module

For Shiny Core apps that use [chatlas](https://posit-dev.github.io/chatlas/), `chat_mod_ui()` and `chat_mod_server()` provide a batteries-included chat interface that handles streaming, cancellation, and bookmarking automatically.

```{.python file="app.py"}
from shiny import App, ui
from chatlas import ChatAnthropic
from shinychat import chat_mod_ui, chat_mod_server

app_ui = ui.page_fillable(
chat_mod_ui("chat"),
)

def server(input, output, session):
client = ChatAnthropic(system_prompt="You are a helpful assistant.")
chat = chat_mod_server("chat", client=client)

app = App(app_ui, server)
```

The returned `ChatServerState` object provides reactive accessors like `chat.status()` and `chat.last_turn()`, along with methods like `chat.set_client()` for swapping models mid-session. See the [API reference](api/index.qmd) for the full interface.

## Learn more

Expand Down
4 changes: 4 additions & 0 deletions pkg-py/src/shinychat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from ._chat import Chat, chat_greeting, chat_ui
from ._chat_module import ChatServerState, chat_mod_server, chat_mod_ui
from ._chat_normalize import message_content, message_content_chunk
from ._markdown_stream import MarkdownStream, output_markdown_stream

__all__ = [
"Chat",
"ChatServerState",
"chat_greeting",
"chat_mod_server",
"chat_mod_ui",
"chat_ui",
"MarkdownStream",
"output_markdown_stream",
Expand Down
Loading
Loading