Jupyter AI

3.0.0 · active · verified Fri Apr 17

Jupyter AI is a set of extensions that provides agentic AI capabilities directly within JupyterLab. It integrates large language models (LLMs) and agents into notebooks and the JupyterLab interface, offering features like real-time chat, code generation, and AI-powered data analysis. The current version is 3.0.0, with an active development cadence releasing frequently, especially leading up to major versions.

Common errors

Warnings

Install

Imports

Quickstart

To use Jupyter AI, ensure it's installed and your JupyterLab server is running. You primarily interact with Jupyter AI through its dedicated chat interface in the JupyterLab sidebar or directly within notebook cells using magic commands (e.g., `%%ai`). Most LLM providers require an API key, which should be set as an environment variable before launching JupyterLab or configured via JupyterLab's settings. The example demonstrates loading magic commands, listing models, and basic usage for code generation and agent interaction.

import os

# Before starting JupyterLab, set your API key for a model provider.
# Example for OpenAI:
# os.environ['OPENAI_API_KEY'] = os.environ.get('OPENAI_API_KEY', 'YOUR_OPENAI_KEY')
# For other providers like Anthropic:
# os.environ['ANTHROPIC_API_KEY'] = os.environ.get('ANTHROPIC_API_KEY', 'YOUR_ANTHROPIC_KEY')

# --- In a Jupyter notebook cell: ---

# (Optional) Explicitly load the AI magic commands, though often loaded automatically
# %load_ext jupyter_ai_magics

# List available models and providers
# %%ai list

# Use a model for code generation
# %%ai chatgpt -f code
# Create a Python function to calculate the Nth Fibonacci number recursively.

# Use an agent to interact with Jupyter (requires agent-capable model like Claude, Gemini)
# %%ai claude -m anthropic.claude-3-haiku-20240307-v1:0
# Write a simple Python script to list files in the current directory and save it as 'list_files.py'.
# Note: Agent actions that modify files or execute commands will prompt for approval in the UI.

# --- Using the Jupyter AI chat interface: ---
# 1. Open the 'Jupyter AI' panel in the left sidebar of JupyterLab.
# 2. Select a model provider and model from the dropdowns.
# 3. Start a conversation or ask for assistance with your notebook content.

view raw JSON →