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.
โจ 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
- Create an account at pypi.org (and optionally test.pypi.org)
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16ab8b2c2f139dbd2eb01a1000f2c4f775c60ede5608ed5ef4034b94b382f7f9
|
|
| MD5 |
c16142a8b41e13b4ed5fa2c24bc874b4
|
|
| BLAKE2b-256 |
db89990aaa7c1c50abbdb91a9fc6f385a0da8c329fa38cf52aa03f0c0250b6e5
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9d9fd9513d0e5c62ca9d48ccc33a597d7bf72f26739fda6b831bcd613be3c53
|
|
| MD5 |
ffb5edb4daf814b55302f33d72f6580c
|
|
| BLAKE2b-256 |
a8f33d202784fdb67df6d5e19f9b90cc72a8cb5da423194fceedbbd997fe6daf
|