ShinyChat

0.2.9 · active · verified Thu Apr 16

ShinyChat is a Python library that provides a Shiny toolkit for building generative AI applications like chatbots and streaming content directly within Shiny applications. It offers easy-to-use chat UI components that integrate seamlessly with various LLM frameworks. The library is actively maintained with frequent updates, currently at version 0.2.9.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart creates a simple ShinyChat application where the AI assistant acts as an echo bot, repeating whatever the user types. It demonstrates the basic setup of a `Chat` instance, displaying its UI, and handling user input with an asynchronous callback.

import os
from shiny.express import ui
from shinychat.express import Chat

# Set some Shiny page options
ui.page_opts(
    title="Hello ShinyChat Echo Bot",
    fillable=True,
    fillable_mobile=True,
)

# Create a chat instance and display its UI
chat = Chat(id="chat")
chat.ui(
    messages=["Hello! I'm an echo bot. Type something and I'll repeat it!"]
)

# Define a callback to run when the user submits a message
@chat.on_user_submit
async def handle_user_input(user_input: str):
    # Simply echo the user's input back to them
    await chat.append_message(f"You said: {user_input}")

# To run this app, save it as `app.py` and execute:
# `uv shiny run --reload app.py` (if using uv)
# or `python -m shiny run --reload app.py` (if using pip/python)

view raw JSON →