types.ChatClient
types.ChatClient(chat, client)Wraps a chatlas client bound to a :class:~shinychat.Chat instance.
This class is created automatically when you pass a client= argument to :class:~shinychat.Chat. It holds the current client, handles deferred swaps during streaming, and wires up bookmarking.
Attributes
| Name | Description |
|---|---|
| value | The underlying chatlas client. |
Methods
| Name | Description |
|---|---|
| clear | Clear chat messages and optionally reset the client’s turn history. |
| set | Replace the chatlas client. |
clear
types.ChatClient.clear(messages=None, greeting=False, client_history='clear')Clear chat messages and optionally reset the client’s turn history.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| messages | 'list[ChatMessageDict] | None' | A list of messages to set or append on the client. Required when client_history is "set" or "append", and not allowed with "clear" or "keep". |
None |
| greeting | bool | Passed to :meth:~shinychat.Chat.clear_messages. |
False |
| client_history | Literal['clear', 'set', 'append', 'keep'] | How to handle the client’s turn history: * "clear" (default): removes all turns from the client. * "set": sets the client’s turns to messages. Requires messages to be provided. * "append": appends messages to the client’s existing turns. Requires messages to be provided. * "keep": leaves the client’s turns untouched. |
'clear' |
Raises
| Name | Type | Description |
|---|---|---|
| shiny.types.NotifyException | If an assistant response is currently streaming. To avoid this error, guard the call by checking chat.latest_message_stream.status() != "running" before calling :meth:clear. The notification message is shown without sanitization because it is a fixed, user-safe string. |
set
types.ChatClient.set(new_client, *, sync=True)Replace the chatlas client.
If a response stream is currently running the swap is deferred until the stream completes.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| new_client | 'chatlas.Chat[Any, Any]' | The replacement chatlas client. | required |
| sync | bool | When True (the default), copies turns, system_prompt, and tools from the old client to the new one before swapping. |
True |