Skip to main content

A simple chat UI widget for Jupyter notebooks

Project description

jupyter-chat-widget

A simple chat UI widget for Jupyter notebooks with streaming response support, designed to integrate easily with LLM APIs.

Note: this widget uses ipywidgets<8.0.0 for compatibility with Colab.

CI Docs PyPI version Python versions

Installation

pip install jupyter-chat-widget

Quick Start

from jupyter_chat_widget import ChatUI

# Create the chat widget
chat = ChatUI()

# Define a handler for user messages
def handle_message(message: str) -> None:
    # Stream a response token by token
    for word in message.split():
        chat.append(word + " ")

# Connect the handler
chat.connect(handle_message)

Documentation

See the live documentation or the example notebook in examples/.

API Reference

ChatUI

The main chat widget class.

Methods

Method Description
connect(callback) Connect a callback function to handle user messages
append(token) Append text to the current assistant response (streaming)
rewrite(text) Replace the entire assistant response
clear() Clear all chat history and current response

Example: Streaming Responses

from jupyter_chat_widget import ChatUI
from time import sleep

chat = ChatUI()

def slow_echo(message: str) -> None:
    """Echo back the message word by word."""
    for word in message.split():
        sleep(0.5)  # Simulate processing time
        chat.append(word + " ")
    chat.rewrite(f"You said: {message}")

chat.connect(slow_echo)

Example: Integration with LLM

from jupyter_chat_widget import ChatUI

chat = ChatUI()

def llm_handler(message: str) -> None:
    """Stream responses from an LLM API."""
    # Replace with your LLM API call
    for token in your_llm_api.stream(message):
        chat.append(token)

chat.connect(llm_handler)

Development

# Clone the repository
git clone https://github.com/zansara/jupyter-chat-widget.git
cd jupyter-chat-widget

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run linting
ruff check src tests
ruff format src tests

# Build the package
python -m build

Pre-commit Hooks

# Install pre-commit hooks
pre-commit install

# Run hooks on all files
pre-commit run --all-files

License

MIT License - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyter_chat_widget-0.4.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jupyter_chat_widget-0.4.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file jupyter_chat_widget-0.4.0.tar.gz.

File metadata

  • Download URL: jupyter_chat_widget-0.4.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jupyter_chat_widget-0.4.0.tar.gz
Algorithm Hash digest
SHA256 4878fe8e5f8ee99af6eb1fe23338ac46f04ab6afdd6e08f05404fa8afc4975e2
MD5 5985a744feb8b1546a8712f52dded744
BLAKE2b-256 cb9aa8de6503fa239b2d6e7221dddf79436a2b6e6f21f773723e1b586b6c7c52

See more details on using hashes here.

Provenance

The following attestation bundles were made for jupyter_chat_widget-0.4.0.tar.gz:

Publisher: publish.yml on ZanSara/jupyter-chat-widget

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jupyter_chat_widget-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jupyter_chat_widget-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3250fe25e93ecaaa53e5956f7ed57b55f91e9dbbaa4274a1fd914094fd9554f
MD5 65be7c14da7c6368d0912024d2cb015a
BLAKE2b-256 d95bf602a6836b30367a781274de607699b6091784e01fbce1170f9cddc7a1cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for jupyter_chat_widget-0.4.0-py3-none-any.whl:

Publisher: publish.yml on ZanSara/jupyter-chat-widget

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page