Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .env.azure.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Azure OpenAI Configuration for Jupyter AI Agents
#
# Copy this file to .env and fill in your values:
# cp .env.azure.example .env
#
# Then load it:
# source .env
#
# Or use direnv:
# direnv allow

# Azure OpenAI API Key (required)
export AZURE_OPENAI_API_KEY="your-api-key-here"

# Azure OpenAI Endpoint - Base URL only (required)
# Format: https://your-resource-name.openai.azure.com
# Do NOT include /openai/deployments/... or query parameters
export AZURE_OPENAI_ENDPOINT="https://your-resource-name.openai.azure.com"

# Azure OpenAI API Version (optional, defaults to latest)
# Use the version that matches your deployment
export AZURE_OPENAI_API_VERSION="2024-08-01-preview"

# Example deployment names you might use with --model-name:
# - gpt-4o-mini
# - gpt-4o
# - gpt-35-turbo
# - Your custom deployment names

# Test your configuration:
# python -c "import os; print('API Key:', 'SET' if os.getenv('AZURE_OPENAI_API_KEY') else 'NOT SET'); print('Endpoint:', os.getenv('AZURE_OPENAI_ENDPOINT')); print('Version:', os.getenv('AZURE_OPENAI_API_VERSION', 'default'))"
2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) Datalayer, Inc. https://datalayer.io
# Copyright (c) Datalayer, Inc. https://datalayer.ai
# Distributed under the terms of the Datalayer License.

enableImmutableInstalls: false
Expand Down
33 changes: 23 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,35 @@ example-fastapi: ## example-fastapi server
@exec echo
python -m uvicorn jupyter_ai_agents.examples.fastapi.main:main --reload --port 4400

jupyter-ai-agents-prompt:
jupyter-ai-agents prompt \
repl:
jupyter-ai-agents repl \
--url http://localhost:8888 \
--token MY_TOKEN \
--model-provider azure-openai \
--model-name gpt-4o-mini \
--model azure-openai:gpt-4o-mini

# Note: For Azure OpenAI, ensure these environment variables are set:
# - AZURE_OPENAI_API_KEY
# - AZURE_OPENAI_ENDPOINT (base URL, e.g., https://your-resource.openai.azure.com)
# - AZURE_OPENAI_API_VERSION (optional, defaults to latest)
# Adjust --max-requests based on your Azure tier (CLI default: 4; lower if you hit rate limits)
prompt:
jupyter-ai-agents prompt \
--verbose \
--mcp-servers http://localhost:8888/mcp \
--model anthropic:claude-sonnet-4-20250514 \
--path notebook.ipynb \
--max-requests 20 \
--max-tool-calls 10 \
--input "Create a matplotlib example"

jupyter-ai-agents-explain-error:
explain-error:
jupyter-ai-agents explain-error \
--url http://localhost:8888 \
--token MY_TOKEN \
--model-provider azure-openai \
--model-name gpt-4o-mini \
--path notebook.ipynb
--verbose \
--mcp-servers http://localhost:8888/mcp \
--model anthropic:claude-sonnet-4-20250514 \
--path notebook.ipynb \
--max-requests 20 \
--max-tool-calls 10

publish-pypi: # publish the pypi package
git clean -fdx && \
Expand Down
182 changes: 159 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
~ BSD 3-Clause License
-->

[![Datalayer](https://assets.datalayer.tech/datalayer-25.svg)](https://datalayer.io)
[![Datalayer](https://assets.datalayer.tech/datalayer-25.svg)](https://datalayer.ai)

[![Become a Sponsor](https://img.shields.io/static/v1?label=Become%20a%20Sponsor&message=%E2%9D%A4&logo=GitHub&style=flat&color=1ABC9C)](https://github.com/sponsors/datalayer)

Expand Down Expand Up @@ -75,7 +75,6 @@ You can also use Jupyter AI Agents through the command line interface for automa

![Jupyter AI Agents CLI](https://assets.datalayer.tech/jupyter-ai-agent/ai-agent-prompt-demo-terminal.gif)


### Basic Installation

To install Jupyter AI Agents, run the following command:
Expand Down Expand Up @@ -110,7 +109,7 @@ pip install datalayer_pycrdt==0.12.17
```
### Examples

We put here a quick example for a Out-Kernel Stateless Agent via CLI helping your JupyterLab session.
Jupyter AI Agents provides CLI commands to help your JupyterLab session using **Pydantic AI agents** with **Model Context Protocol (MCP)** for tool integration.

Start JupyterLab, setting a `port` and a `token` to be reused by the agent, and create a notebook `notebook.ipynb`.

Expand All @@ -121,49 +120,186 @@ jupyter lab --port 8888 --IdentityProvider.token MY_TOKEN

Jupyter AI Agents supports multiple AI model providers (more information can be found on [this documentation page](https://jupyter-ai-agents.datalayer.tech/docs/models)).

The following takes you through an example with the Azure OpenAI provider. Read the [Azure Documentation](https://learn.microsoft.com/en-us/azure/ai-services/openai) to get the needed credentials and make sure you define them in the following `.env` file.
### API Keys Configuration

Set the appropriate API key for your chosen provider:

**OpenAI:**
```bash
export OPENAI_API_KEY='your-api-key-here'
```

**Anthropic:**
```bash
export ANTHROPIC_API_KEY='your-api-key-here'
```

**Azure OpenAI:**
```bash
export AZURE_OPENAI_API_KEY='your-api-key-here'
export AZURE_OPENAI_ENDPOINT='https://your-resource.openai.azure.com'
export AZURE_OPENAI_API_VERSION='2024-08-01-preview' # optional
```

**Important for Azure OpenAI:**
- The `AZURE_OPENAI_ENDPOINT` should be just the base URL (e.g., `https://your-resource.openai.azure.com`)
- Do NOT include `/openai/deployments/...` or query parameters in the endpoint
- The deployment name is specified via the `--model-name` parameter
- See `.env.azure.example` for a complete configuration template

**Other providers:**
```bash
cat << EOF >>.env
OPENAI_API_VERSION="..."
AZURE_OPENAI_ENDPOINT="..."
AZURE_OPENAI_API_KEY="..."
EOF
export GOOGLE_API_KEY='your-api-key-here' # For Google/Gemini
export COHERE_API_KEY='your-api-key-here' # For Cohere
export GROQ_API_KEY='your-api-key-here' # For Groq
export MISTRAL_API_KEY='your-api-key-here' # For Mistral
# AWS credentials for Bedrock
export AWS_ACCESS_KEY_ID='your-key'
export AWS_SECRET_ACCESS_KEY='your-secret'
export AWS_REGION='us-east-1'
```

**Prompt Agent**
### Model Specification

You can specify the model in two ways:

1. **Using `--model` with full string** (recommended):
```bash
--model "openai:gpt-4o"
--model "anthropic:claude-sonnet-4-0"
--model "azure-openai:deployment-name"
```

2. **Using `--model-provider` and `--model-name`**:
```bash
--model-provider openai --model-name gpt-4o
--model-provider anthropic --model-name claude-sonnet-4-0
```

Supported providers: `openai`, `anthropic`, `azure-openai`, `github-copilot`, `google`, `bedrock`, `groq`, `mistral`, `cohere`

### Prompt Agent

To use the Jupyter AI Agents, an easy way is to launch a CLI (update the Azure deployment name based on your setup).
Create and execute code based on user instructions:

```bash
# Prompt agent example.
# make jupyter-ai-agents-prompt
# Using full model string (recommended)
jupyter-ai-agents prompt \
--url http://localhost:8888 \
--token MY_TOKEN \
--model-provider azure-openai \
--model-name gpt-4o-mini \
--model "anthropic:claude-sonnet-4-0" \
--path notebook.ipynb \
--input "Create a matplotlib example"

# Using provider and model name
jupyter-ai-agents prompt \
--url http://localhost:8888 \
--token MY_TOKEN \
--model-provider anthropic \
--model-name claude-sonnet-4-0 \
--path notebook.ipynb \
--input "Create a pandas dataframe with sample data and plot it"
```

![Jupyter AI Agents](https://assets.datalayer.tech/jupyter-ai-agent/ai-agent-prompt-demo-terminal.gif)
![Jupyter AI Agents - Prompt](https://assets.datalayer.tech/jupyter-ai-agent/ai-agent-prompt-demo-terminal.gif)

### Explain Error Agent

**Explain Error Agent**
Analyze and fix notebook errors:

```bash
# Explain Error agent example.
# make jupyter-ai-agents-explain-error
jupyter-ai-agents explain-error \
--url http://localhost:8888 \
--token MY_TOKEN \
--model-provider azure-openai \
--model-name gpt-4o-mini \
--path notebook.ipynb
--model "anthropic:claude-sonnet-4-0" \
--path notebook.ipynb \
--current-cell-index 5
```

![Jupyter AI Agents - Explain Error](https://assets.datalayer.tech/jupyter-ai-agent/ai-agent-explainerror-demo-terminal.gif)

### REPL Mode (Interactive)

For an interactive experience with direct access to all Jupyter MCP tools, use the REPL mode:

```bash
jupyter-ai-agents repl \
--url http://localhost:8888 \
--token MY_TOKEN \
--model "anthropic:claude-sonnet-4-0"
```

![Jupyter AI Agents](https://assets.datalayer.tech/jupyter-ai-agent/ai-agent-explainerror-demo-terminal.gif)
In REPL mode, you can directly ask the AI to:
- List notebooks in directories
- Read and analyze notebook contents
- Execute code in cells
- Insert new cells
- Modify existing cells
- Install Python packages

Example REPL interactions:

```
> List all notebooks in the current directory
> Create a new notebook called analysis.ipynb
> In analysis.ipynb, create a cell that imports pandas and loads data.csv
> Execute the cell and show me the first 5 rows
> Add a matplotlib plot showing the distribution of the 'age' column
```

The REPL provides special commands:
- `/exit`: Exit the session
- `/markdown`: Show last response in markdown format
- `/multiline`: Toggle multiline input mode (use Ctrl+D to submit)
- `/cp`: Copy last response to clipboard

You can also use a custom system prompt:

```bash
jupyter-ai-agents repl \
--url http://localhost:8888 \
--token MY_TOKEN \
--model "anthropic:claude-sonnet-4-0" \
--system-prompt "You are a data science expert specializing in pandas and matplotlib."
```

### Prompt Agent

Create and execute code based on user instructions:

```bash
# Using full model string (recommended)
jupyter-ai-agents prompt \
--url http://localhost:8888 \
--token MY_TOKEN \
--model "anthropic:claude-sonnet-4-0" \
--path notebook.ipynb \
--input "Create a matplotlib example"

# Using provider and model name
jupyter-ai-agents prompt \
--url http://localhost:8888 \
--token MY_TOKEN \
--model-provider anthropic \
--model-name claude-sonnet-4-0 \
--path notebook.ipynb \
--input "Create a pandas dataframe with sample data and plot it"
```

### Explain Error Agent

Analyze and fix notebook errors:

```bash
jupyter-ai-agents explain-error \
--url http://localhost:8888 \
--token MY_TOKEN \
--model "anthropic:claude-sonnet-4-0" \
--path notebook.ipynb \
--current-cell-index 5
```

## Uninstall

### About the Technology

Expand Down
2 changes: 1 addition & 1 deletion dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
~ BSD 3-Clause License
-->

[![Datalayer](https://assets.datalayer.tech/datalayer-25.svg)](https://datalayer.io)
[![Datalayer](https://assets.datalayer.tech/datalayer-25.svg)](https://datalayer.ai)

[![Become a Sponsor](https://img.shields.io/static/v1?label=Become%20a%20Sponsor&message=%E2%9D%A4&logo=GitHub&style=flat&color=1ABC9C)](https://github.com/sponsors/datalayer)
2 changes: 1 addition & 1 deletion dev/content/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
~ BSD 3-Clause License
-->

[![Datalayer](https://assets.datalayer.tech/datalayer-25.svg)](https://datalayer.io)
[![Datalayer](https://assets.datalayer.tech/datalayer-25.svg)](https://datalayer.ai)

[![Become a Sponsor](https://img.shields.io/static/v1?label=Become%20a%20Sponsor&message=%E2%9D%A4&logo=GitHub&style=flat&color=1ABC9C)](https://github.com/sponsors/datalayer)
10 changes: 1 addition & 9 deletions dev/content/notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "a582b625-e712-4581-b611-3def5f40bd59",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "84ca6269-06aa-42c3-815c-292980f031c0",
"id": "6e785ae0-34d9-462e-aa9a-22d7b40e15d8",
"metadata": {},
"outputs": [],
"source": []
Expand Down
2 changes: 1 addition & 1 deletion docs/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) Datalayer, Inc. https://datalayer.io
# Copyright (c) Datalayer, Inc. https://datalayer.ai
# Distributed under the terms of the MIT License.

enableImmutableInstalls: false
Expand Down
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) Datalayer, Inc. https://datalayer.io
# Copyright (c) Datalayer, Inc. https://datalayer.ai
# Distributed under the terms of the MIT License.

SHELL=/bin/bash
Expand Down
Loading
Loading