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.

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.1.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.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jupyter_chat_widget-0.1.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.1.0.tar.gz
Algorithm Hash digest
SHA256 9b44cc4e81f8b397bcd748ae89818682e3c970af376bfc821175bfdfe3430b57
MD5 0817818bfd14d78946641ac36756d726
BLAKE2b-256 431e3d89206a85bea8d4bbd63f7e7bec2747ede0300c3e76b952b6429860532d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for jupyter_chat_widget-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a8c5497974b93c5f5a222fa5ee78c24df34cc91aadb5335ef268a8fca7b8114
MD5 8bd3b2eed5130030164438779a6ea417
BLAKE2b-256 5c11ca55649a57c5be396cc04c0b21ce7a43c1723125cbd57124c768e2dac04b

See more details on using hashes here.

Provenance

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