nbdialog

This file will become your README and also the index of your documentation.

Developer Guide

If you are new to using nbdev here are some useful pointers to get you started.

Install nbdialog in Development mode

# make sure nbdialog package is installed in development mode
$ pip install -e .

# make changes under nbs/ directory
# ...

# compile to have changes apply to nbdialog
$ nbdev_prepare

Usage

Installation

Install latest from the GitHub repository:

$ pip install git+https://github.com/slashpablo/nbdialog.git

or from conda

$ conda install -c slashpablo nbdialog

or from pypi

$ pip install nbdialog

Documentation

Documentation can be found hosted on this GitHub repository’s pages. Additionally you can find package manager specific guidelines on conda and pypi respectively.

How to use

nbdialog adds a %%prompt cell magic that turns a Jupyter notebook into an LLM dialog. When you run a prompt cell, every cell above it — code, markdown, and captured outputs — is sent to the model as conversation history; previous prompt cells appear as prior assistant turns. The reply renders as markdown and is cached in the cell’s outputs, so re-running the notebook doesn’t re-call the model.

Register a provider once per kernel:

from nbdialog.core import *
from nbdialog.providers.openai import OpenAIProvider

set_provider(OpenAIProvider())

Then write a prompt in any cell — the rest of the notebook above it becomes the context:

%%prompt
write me hello world in python, like a pirate!

Run the cell to see the model’s response rendered as markdown. Subsequent runs reuse the cached output; pass -f to force a fresh call:

%%prompt -f
which is better?

OpenAIProvider ships with the package. To use a different vendor, implement the Provider protocol — any object with a complete(messages: list[dict]) -> str method works — and pass it to set_provider.