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.3.0.tar.gz (5.2 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.3.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jupyter_chat_widget-0.3.0.tar.gz
  • Upload date:
  • Size: 5.2 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.3.0.tar.gz
Algorithm Hash digest
SHA256 61a877e6c03da5dcf2c192798ece7d525552cbc488244dab731b7139778dd42e
MD5 ba6fc905c2dcb12a817d5b598d477fef
BLAKE2b-256 8113dd5d2aed658cd69679ce4be35322f3697c1745389668940e4010ac51f805

See more details on using hashes here.

Provenance

The following attestation bundles were made for jupyter_chat_widget-0.3.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.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jupyter_chat_widget-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aaa39a5cc1e81b2b021b7ba5e752ba5d2a4f871b47f80da01d0e4cb2c86700db
MD5 ed3146632de9fae55fd7d4de68978585
BLAKE2b-256 6e930b108a250752a493991e7cedf0eaec505b6093167f1660c2bf68e0fca7b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for jupyter_chat_widget-0.3.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