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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4878fe8e5f8ee99af6eb1fe23338ac46f04ab6afdd6e08f05404fa8afc4975e2
|
|
| MD5 |
5985a744feb8b1546a8712f52dded744
|
|
| BLAKE2b-256 |
cb9aa8de6503fa239b2d6e7221dddf79436a2b6e6f21f773723e1b586b6c7c52
|
Provenance
The following attestation bundles were made for jupyter_chat_widget-0.4.0.tar.gz:
Publisher:
publish.yml on ZanSara/jupyter-chat-widget
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jupyter_chat_widget-0.4.0.tar.gz -
Subject digest:
4878fe8e5f8ee99af6eb1fe23338ac46f04ab6afdd6e08f05404fa8afc4975e2 - Sigstore transparency entry: 832896893
- Sigstore integration time:
-
Permalink:
ZanSara/jupyter-chat-widget@791357f2e6649a2439d97ca1220f88745f214d50 -
Branch / Tag:
refs/tags/0.4.0 - Owner: https://github.com/ZanSara
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@791357f2e6649a2439d97ca1220f88745f214d50 -
Trigger Event:
release
-
Statement type:
File details
Details for the file jupyter_chat_widget-0.4.0-py3-none-any.whl.
File metadata
- Download URL: jupyter_chat_widget-0.4.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3250fe25e93ecaaa53e5956f7ed57b55f91e9dbbaa4274a1fd914094fd9554f
|
|
| MD5 |
65be7c14da7c6368d0912024d2cb015a
|
|
| BLAKE2b-256 |
d95bf602a6836b30367a781274de607699b6091784e01fbce1170f9cddc7a1cc
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jupyter_chat_widget-0.4.0-py3-none-any.whl -
Subject digest:
a3250fe25e93ecaaa53e5956f7ed57b55f91e9dbbaa4274a1fd914094fd9554f - Sigstore transparency entry: 832896895
- Sigstore integration time:
-
Permalink:
ZanSara/jupyter-chat-widget@791357f2e6649a2439d97ca1220f88745f214d50 -
Branch / Tag:
refs/tags/0.4.0 - Owner: https://github.com/ZanSara
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@791357f2e6649a2439d97ca1220f88745f214d50 -
Trigger Event:
release
-
Statement type: