# nbdialog


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

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

``` sh
# 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](https://github.com/slashpablo/nbdialog):

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

or from [conda](https://anaconda.org/slashpablo/nbdialog)

``` sh
$ conda install -c slashpablo nbdialog
```

or from [pypi](https://pypi.org/project/nbdialog/)

``` sh
$ pip install nbdialog
```

### Documentation

Documentation can be found hosted on this GitHub
[repository](https://github.com/slashpablo/nbdialog)’s
[pages](https://slashpablo.github.io/nbdialog/). Additionally you can
find package manager specific guidelines on
[conda](https://anaconda.org/slashpablo/nbdialog) and
[pypi](https://pypi.org/project/nbdialog/) 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:

``` python
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`](https://slashpablo.github.io/nbdialog/providers.openai.html#openaiprovider)
ships with the package. To use a different vendor, implement the
[`Provider`](https://slashpablo.github.io/nbdialog/core.html#provider)
protocol — any object with a `complete(messages: list[dict]) -> str`
method works — and pass it to
[`set_provider`](https://slashpablo.github.io/nbdialog/core.html#set_provider).
