Set up Jupyter AI in Jupyter environment

Jupyter AI provides an AI-powered assistant that helps data scientists generate code, debug errors, summarize content, and interact with notebooks using natural language prompts. It works in both JupyterLab and notebook-based IDEs such as VS Code and Jupyter Notebook.

Jupyter AI supports multiple backends and integrates with models from providers such as OpenAI, Azure, Hugging Face, and SageMaker. Domino Standard Environments (DSEs) come with Jupyter AI pre-installed.

Prerequisites

  • A Domino Workspace running JupyterLab, Jupyter Notebook, or VS Code

  • Access to a Domino Standard Environment (or a custom one with Jupyter AI installed)

  • An API key from an LLM provider, such as OpenAI or Hugging Face, if using magic commands

Ways to use Jupyter AI

You can use Jupyter AI in two modes:

  • Chat-based assistant in JupyterLab (Jupyternaut)

  • Magic commands in notebook-based IDEs

Option 1: Jupyternaut Chatbot (JupyterLab)

To launch the chatbot:

  1. Create a new Workspace using JupyterLab and a Domino Standard Environment.

  2. Click the chat icon in the left sidebar to open the assistant.

  3. Use the interface to ask questions, get explanations, or generate notebook content.

The Jupyter AI documentation has more details about chatbot configuration.

Option 2 Magic commands in Notebook IDEs

In notebook-based IDEs like Jupyter or VS Code, you can access Jupyter AI using magic commands.

To get started:

  1. Launch a Workspace using Jupyter Notebooks or VS Code and a Domino Standard Environment.

  2. Obtain an API key from your LLM provider, such as OpenAI or Hugging Face. Tip: Use Domino environment variables to securely store API keys.

  3. Set the appropriate environment variable in a notebook cell.

  4. For OpenAI: %env OPENAI_API_KEY=<your-api-key>

  5. Load the extension: %load_ext jupyter_ai_magics

  6. Use %ai or %%ai to invoke the assistant.

The Jupyter AI magic command documentation has a complete list of syntax and usage examples.

Custom environment setup

If you’re not using a Domino Standard Environment (DSE), or if you want to preconfigure Jupyter AI for consistent use across projects and teams, you can install and configure it in a custom Compute Environment. This approach makes sure that:

  • Jupyter AI is available by default in all Workspaces using the environment.

  • API keys and assistant tools are pre-installed and ready to use.

  • Users don’t need to reconfigure magic commands or environment variables manually.

Step 1: Install Jupyter AI and rebuild JupyterLab

Add the following to your Dockerfile to install Jupyter AI and rebuild the JupyterLab interface to register the extension:

RUN pip install 'jupyter-ai[jupyterlab]' && \
    jupyter lab build

Step 2: Set your LLM API key as an environment variable

Add your preferred LLM provider’s API key to the Dockerfile:

ENV OPENAI_API_KEY=<your-api-key>

This makes the key available to Jupyter AI for authentication when making requests.

Tip: For sensitive credentials, consider using Domino environment variables instead of hardcoding them.

Step 3: Preload the magic command extension

To make sure that the %ai and %%ai magic commands are available without manual activation, configure IPython to load the extension at startup:

RUN ipython profile create && \
    echo "c.InteractiveShellApp.extensions=['jupyter_ai_magics']" >> /home/ubuntu/.ipython/profile_default/ipython_config.py

Once these steps are complete, any Workspace launched with this Compute Environment will have Jupyter AI ready to use, with no additional configuration required.

Next steps