A JupyterLab extension that integrates Ollama-powered AI assistance directly into notebooks
Project description
JupyterLab AI Assistant
A comprehensive JupyterLab extension that integrates Ollama-powered AI assistance directly into notebooks with cell-specific context awareness and responsive design.
✨ Features
- Chat with Ollama Models: Interact with locally-running Ollama AI models directly within JupyterLab
- Cell-Contextual AI Assistance: Ask questions about specific notebook cells with a simple click
- Smart Responses: Get syntax-highlighted, markdown-formatted responses
- Responsive Design: Clean, modern interface that adapts to your JupyterLab theme
- Theme-Aware UI: Seamless integration with JupyterLab's light/dark themes
- Multi-Model Support: Use any Ollama model installed on your system
- Code Analysis: Explain, optimize, or debug code directly from your notebooks
🔍 How It Works
The extension connects to your local Ollama service and provides two main interaction modes:
- Chat Interface: A standalone chat widget where you can ask general questions
- Cell Context Actions: Toolbar buttons that appear on notebook cells for code-specific questions
Chat Widget
The chat interface features:
- Full markdown support including code blocks
- Syntax highlighting for code
- Model selection dropdown
- Responsive design for all screen sizes
Cell Context Analysis
Cell toolbar buttons provide quick access to:
- 🔍 Explain code in the current cell
- 🔧 Optimize performance
- 🐞 Debug issues
- 📊 Analyze data processing logic
- 💬 Ask custom questions about the cell content
📋 Prerequisites
- JupyterLab 4.x (compatible with 4.0.0 and above)
- Ollama installed and running locally
- Python 3.8+
Detailed Dependencies
This extension has the following specific dependencies:
jupyterlab >= 4.0.0, < 5.0.0
jupyter_server >= 2.0.0
jupyter-client >= 8.0.0
aiohttp
requests >= 2.25.0
Frontend Dependencies
react >= 18.2.0
react-dom >= 18.2.0
react-markdown >= 8.0.0
bootstrap >= 5.3.3
🚀 Installation
Method 1: Install from Source
Use the provided installation script which handles all dependencies and setup:
# Clone the repository
git clone https://github.com/bhumukul-raj/ollama-ai-assistant-project.git
cd ollama-ai-assistant-project/jupyterlab-ai-assistant
# Run the installation script (creates a virtual environment)
bash install-fixed.sh
Method 2: Manual Installation
# Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate
# Install JupyterLab 4.x and dependencies
pip install "jupyterlab>=4.0.0,<5.0.0" "jupyter_server>=2.0.0,<3.0.0" "jupyter-client>=8.0.0"
pip install aiohttp "requests>=2.25.0"
# Install the extension in development mode
pip install -e .
# Build and link the extension
jupyter labextension develop . --overwrite
jupyter lab build
Verify Installation
To verify the extension is properly installed:
jupyter labextension list
You should see jupyterlab-ai-assistant listed in the output.
Ollama Setup
- Install Ollama from ollama.ai
- Start the Ollama service:
ollama serve - Pull at least one model to use with the extension:
ollama pull llama2
📖 Usage Guide
Chat Interface
- Launch JupyterLab
- Click on the "AI Assistant" icon in the sidebar or open it from the menu (AI Assistant > Open AI Assistant)
- Select a model from the dropdown
- Type your question and press Enter
Cell-Specific Questions
- Open a notebook in JupyterLab
- Hover over any code or markdown cell
- Click on one of the AI assistant buttons in the cell toolbar:
- 🔍 Explain - Understand what the code does
- 🔧 Optimize - Get suggestions for performance improvement
- 🐞 Debug - Find and fix issues in your code
- 💬 Chat - Ask a custom question about this cell
- View the AI's response in the popup dialog
Common Use Cases
- Code Explanation: "What does this pandas transformation do?"
- Debugging Help: "Why am I getting this ValueError in my function?"
- Performance Optimization: "How can I make this loop faster?"
- Documentation: "Generate docstrings for this class"
- Learning: "Explain this algorithm step by step"
⚙️ Configuration
You can configure the extension in JupyterLab's Settings menu:
- Go to Settings > Advanced Settings Editor
- Select "AI Assistant" from the dropdown
- Modify the settings as needed
Available settings:
{
"defaultModel": "llama2",
"baseUrl": "http://localhost:11434",
"enabled": true,
"maxTokens": 4096,
"defaultTemperature": 0.7,
"requestTimeout": 60,
"debugMode": false
}
💻 System Requirements
For the best experience, we recommend:
- A system with at least 8GB RAM
- Sufficient disk space for Ollama models (models range from 1GB to 10GB+ each)
- A modern web browser (Chrome, Firefox, Safari, Edge)
- Python 3.8 or newer
🔧 Troubleshooting
Common Issues
-
Extension visible in
jupyter labextension listbut not in JupyterLab UI:- Clear JupyterLab caches with
jupyter lab clean - Remove any conflicting configurations in
~/.jupyter/jupyter_server_config.json - Run
jupyter server extension enable jupyterlab_ai_assistant - Restart JupyterLab completely
- Clear JupyterLab caches with
-
"Module not found" error for jupyterlab_ai_assistant:
- Ensure you're running JupyterLab from the same virtual environment where you installed the extension
- Try reinstalling:
pip install -e .from the extension directory - Check that the module is in your Python path with
python -c "import sys; print(sys.path)"
-
No models available:
- Ensure Ollama is running (
ollama serve) - Verify you've pulled at least one model (
ollama list) - Check connection to the Ollama API:
curl http://localhost:11434/api/tags
- Ensure Ollama is running (
-
Connection errors:
- Verify the Ollama API is accessible at http://localhost:11434
- Check your network configuration if running on a remote system
- Ensure there are no firewall rules blocking the connection
-
TypeScript build errors:
- Make sure you have Node.js installed (version 14 or higher recommended)
- Run a clean build:
npm run clean && npm run build:prod
Testing the Connection
The extension includes a test tool to verify connectivity:
- From the JupyterLab menu, select: AI Assistant > Test Ollama Connection
- A panel will open showing all available models if the connection is successful
Checking Server Logs
If experiencing issues, check the JupyterLab server logs for error messages:
jupyter lab --debug
🛠️ Development
For developers who want to contribute to the project:
# Clone the repository
git clone https://github.com/bhumukul-raj/ollama-ai-assistant-project.git
cd ollama-ai-assistant-project/jupyterlab-ai-assistant
# Install dependencies
pip install -e .
jupyter labextension develop . --overwrite
# Watch for changes during development
npm run watch
In a separate terminal, run JupyterLab in watch mode:
jupyter lab --watch
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
👤 Author
🤝 Contributing
Contributions, issues, and feature requests are welcome! Feel free to check issues page.
📸 Screenshots
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 jupyterlab_ai_assistant-1.1.1.tar.gz.
File metadata
- Download URL: jupyterlab_ai_assistant-1.1.1.tar.gz
- Upload date:
- Size: 5.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb39cedfd1ec3bb498eaa0ef19ec94877e784e0f2ace15fbbf79dc2ee27ea099
|
|
| MD5 |
542761fbd9b39fed00b7a7585654dacf
|
|
| BLAKE2b-256 |
32713012cc4df954e3b1fc00cce7d60ce90d69389d5c5bb0a3fda18f498dc265
|
File details
Details for the file jupyterlab_ai_assistant-1.1.1-py3-none-any.whl.
File metadata
- Download URL: jupyterlab_ai_assistant-1.1.1-py3-none-any.whl
- Upload date:
- Size: 110.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f481bd1ab1083c5266ee1b734409bf219914a3eea9d8678c431475a578ad9b26
|
|
| MD5 |
0b306b44964dddfc1415929afe91cb73
|
|
| BLAKE2b-256 |
65b04e4ddae35d6556aebc9b701836d28b1bb80ae8ad2b6acbfa30cdddbc90b7
|