Skip to main content

Jupyter/IPython magic commands for chatting with LLMs โ€” OpenAI, Gemini, and Claude.

Project description

๐Ÿค– jupyter-ext-ai

IPython magic commands for chatting with LLMs โ€” OpenAI, Gemini & Claude โ€” right inside Jupyter notebooks.

PyPI version Python License: MIT


โœจ Features

Magic Description
%ai <prompt> One-line prompt โ†’ LLM response
%%ai [flags] Cell magic โ€” cell body is the prompt
%ai_config View / update provider, model, temperature, etc.
%ai_models List models for the active provider
%ai_history Print conversation history
%ai_reset Clear conversation history

Supported providers: OpenAI ยท Google Gemini ยท Anthropic Claude


๐Ÿ“ฆ Installation

pip install jupyter-ext-ai

From source (development):

git clone https://github.com/novatechnolab/jupyter-ext-ai.git
cd jupyter-ext-ai
pip install -e ".[dev]"

๐Ÿ”‘ Configuration

Set your API keys as environment variables:

# Add to your ~/.bashrc, ~/.zshrc, or .env file
export OPENAI_API_KEY="sk-..."
export GOOGLE_API_KEY="AIza..."
export ANTHROPIC_API_KEY="sk-ant-..."

# Optionally set defaults
export JUPYTER_AI_PROVIDER="openai"      # openai | gemini | claude
export JUPYTER_AI_MODEL="gpt-4o-mini"    # any model supported by the provider

๐Ÿš€ Quickstart

# Load the extension
%load_ext jupyter_ext_ai

# Ask a question (uses default provider)
%ai What is the capital of France?

# Switch provider on the fly
%ai --provider gemini Explain recursion in one sentence.

# Use cell magic for longer prompts
%%ai --provider claude --model claude-sonnet-4-20250514
Write a Python function that computes the Fibonacci sequence
using dynamic programming. Include type hints and docstring.

# View / change config
%ai_config
%ai_config --provider gemini --model gemini-2.0-flash --temperature 0.3

# List models
%ai_models openai

# Show conversation history
%ai_history

# Clear history and start fresh
%ai_reset

๐Ÿ—๏ธ Project Structure

jupyter-ext-ai/
โ”œโ”€โ”€ pyproject.toml            # Build config & metadata
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ CONTRIBUTING.md
โ”œโ”€โ”€ MANIFEST.in
โ”œโ”€โ”€ .github/
โ”‚   โ””โ”€โ”€ workflows/
โ”‚       โ””โ”€โ”€ ci.yml            # CI + PyPI publish on tag
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ jupyter_ext_ai/
โ”‚       โ”œโ”€โ”€ __init__.py       # load_ipython_extension() hook
โ”‚       โ”œโ”€โ”€ magic.py          # IPython Magics class
โ”‚       โ”œโ”€โ”€ config.py         # Config dataclass
โ”‚       โ””โ”€โ”€ providers/
โ”‚           โ”œโ”€โ”€ __init__.py   # Provider registry
โ”‚           โ”œโ”€โ”€ base.py       # Abstract base class
โ”‚           โ”œโ”€โ”€ openai_provider.py
โ”‚           โ”œโ”€โ”€ gemini_provider.py
โ”‚           โ””โ”€โ”€ claude_provider.py
โ””โ”€โ”€ tests/
    โ”œโ”€โ”€ conftest.py
    โ”œโ”€โ”€ test_config.py
    โ”œโ”€โ”€ test_providers.py
    โ””โ”€โ”€ test_magic.py

๐Ÿงช Development

# Install in editable mode with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Lint
ruff check src/ tests/

# Build distribution
python -m build

# Check dist before uploading
twine check dist/*

๐Ÿ“ค Publishing to PyPI

First time setup

  1. Create an account at pypi.org (and optionally test.pypi.org)
  2. Generate an API token under Account settings โ†’ API tokens

Publish manually

# Build
python -m build

# Upload to TestPyPI first
twine upload --repository testpypi dist/*

# Upload to PyPI
twine upload dist/*

Automated (GitHub Actions)

Push a version tag to trigger the CI workflow:

git tag v0.1.0
git push origin v0.1.0

The GitHub Action at .github/workflows/ci.yml will lint, test, build, and publish to PyPI automatically (requires a PYPI_API_TOKEN secret in your repo settings).


๐Ÿ“„ License

MIT โ€” use it however you like.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyter_ext_ai-0.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jupyter_ext_ai-0.1.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file jupyter_ext_ai-0.1.0.tar.gz.

File metadata

  • Download URL: jupyter_ext_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for jupyter_ext_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 16ab8b2c2f139dbd2eb01a1000f2c4f775c60ede5608ed5ef4034b94b382f7f9
MD5 c16142a8b41e13b4ed5fa2c24bc874b4
BLAKE2b-256 db89990aaa7c1c50abbdb91a9fc6f385a0da8c329fa38cf52aa03f0c0250b6e5

See more details on using hashes here.

File details

Details for the file jupyter_ext_ai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: jupyter_ext_ai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for jupyter_ext_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a9d9fd9513d0e5c62ca9d48ccc33a597d7bf72f26739fda6b831bcd613be3c53
MD5 ffb5edb4daf814b55302f33d72f6580c
BLAKE2b-256 a8f33d202784fdb67df6d5e19f9b90cc72a8cb5da423194fceedbbd997fe6daf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page