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

Uploaded Python 3

File details

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

File metadata

  • Download URL: jupyter_chat_widget-0.2.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.2.0.tar.gz
Algorithm Hash digest
SHA256 379bca86bbb729d432d6fd7247fc0688904fff1aa594c8ae4290befb38ef46f4
MD5 06306a3cb982d4f67ce42ef6db4139bc
BLAKE2b-256 4d2119383fa7169e2f6501bc44e5f2b6a26e66e0afdf12940d0697b6e5238e53

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for jupyter_chat_widget-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62b91db60acc34101d2618f0cd9ccf15bf517d4544e828d89055e8e8ba1c293c
MD5 4045cde39f82d753ce2d45826c6c2400
BLAKE2b-256 872b34717fa77c60d550538d7700dbc6c1d31e3d27cb0c300bf3f78430b6f29b

See more details on using hashes here.

Provenance

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