Development

This project is a Python package (anywidget) with a bundled React front-end.

Setup

Using venv

python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
jupyter lab example.ipynb

Front-end development

After setting up Python, install the JavaScript dependencies:

npm install

In a separate terminal, start the dev build watcher:

npm run dev

Open example.ipynb in JupyterLab, VS Code, or your favorite editor. Changes in js/ should be reflected in the notebook.

Tests

pytest

Offline / no API key

For unit tests and demos you can use the built-in scripted model (no network, no API keys):

from langchain_core.messages import AIMessage
from langchain_widget import TestChatModel, tool_call

chat_model = TestChatModel(
    [
        AIMessage(
            content="Calling add...",
            tool_calls=[tool_call(id="c1", name="add", args={"a": 2, "b": 3})],
        ),
        AIMessage(content="2 + 3 = 5."),
    ]
)

To inject context from other widgets/apps:

w.add_context(title="Weas selection", content="Selected atoms: [0, 3, 7]")