Skip to content

Commit d8b8c3c

Browse files
authored
Remove LangChain (#60)
* agents: cli * repl * redme: lint * azure * repl * remove langchain * example: simple * rename * datalayer.ai * model * fix: timeout * fix: timeout * agents: prompt and explain-error * readme
1 parent 7be72af commit d8b8c3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2605
-1820
lines changed

.env.azure.example

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Azure OpenAI Configuration for Jupyter AI Agents
2+
#
3+
# Copy this file to .env and fill in your values:
4+
# cp .env.azure.example .env
5+
#
6+
# Then load it:
7+
# source .env
8+
#
9+
# Or use direnv:
10+
# direnv allow
11+
12+
# Azure OpenAI API Key (required)
13+
export AZURE_OPENAI_API_KEY="your-api-key-here"
14+
15+
# Azure OpenAI Endpoint - Base URL only (required)
16+
# Format: https://your-resource-name.openai.azure.com
17+
# Do NOT include /openai/deployments/... or query parameters
18+
export AZURE_OPENAI_ENDPOINT="https://your-resource-name.openai.azure.com"
19+
20+
# Azure OpenAI API Version (optional, defaults to latest)
21+
# Use the version that matches your deployment
22+
export AZURE_OPENAI_API_VERSION="2024-08-01-preview"
23+
24+
# Example deployment names you might use with --model-name:
25+
# - gpt-4o-mini
26+
# - gpt-4o
27+
# - gpt-35-turbo
28+
# - Your custom deployment names
29+
30+
# Test your configuration:
31+
# 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'))"

.yarnrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) Datalayer, Inc. https://datalayer.io
1+
# Copyright (c) Datalayer, Inc. https://datalayer.ai
22
# Distributed under the terms of the Datalayer License.
33

44
enableImmutableInstalls: false

Makefile

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,35 @@ example-fastapi: ## example-fastapi server
4242
@exec echo
4343
python -m uvicorn jupyter_ai_agents.examples.fastapi.main:main --reload --port 4400
4444

45-
jupyter-ai-agents-prompt:
46-
jupyter-ai-agents prompt \
45+
repl:
46+
jupyter-ai-agents repl \
4747
--url http://localhost:8888 \
4848
--token MY_TOKEN \
49-
--model-provider azure-openai \
50-
--model-name gpt-4o-mini \
49+
--model azure-openai:gpt-4o-mini
50+
51+
# Note: For Azure OpenAI, ensure these environment variables are set:
52+
# - AZURE_OPENAI_API_KEY
53+
# - AZURE_OPENAI_ENDPOINT (base URL, e.g., https://your-resource.openai.azure.com)
54+
# - AZURE_OPENAI_API_VERSION (optional, defaults to latest)
55+
# Adjust --max-requests based on your Azure tier (CLI default: 4; lower if you hit rate limits)
56+
prompt:
57+
jupyter-ai-agents prompt \
58+
--verbose \
59+
--mcp-servers http://localhost:8888/mcp \
60+
--model anthropic:claude-sonnet-4-20250514 \
5161
--path notebook.ipynb \
62+
--max-requests 20 \
63+
--max-tool-calls 10 \
5264
--input "Create a matplotlib example"
5365

54-
jupyter-ai-agents-explain-error:
66+
explain-error:
5567
jupyter-ai-agents explain-error \
56-
--url http://localhost:8888 \
57-
--token MY_TOKEN \
58-
--model-provider azure-openai \
59-
--model-name gpt-4o-mini \
60-
--path notebook.ipynb
68+
--verbose \
69+
--mcp-servers http://localhost:8888/mcp \
70+
--model anthropic:claude-sonnet-4-20250514 \
71+
--path notebook.ipynb \
72+
--max-requests 20 \
73+
--max-tool-calls 10
6174

6275
publish-pypi: # publish the pypi package
6376
git clean -fdx && \

README.md

Lines changed: 159 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
~ BSD 3-Clause License
55
-->
66

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

99
[![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)
1010

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

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

78-
7978
### Basic Installation
8079

8180
To install Jupyter AI Agents, run the following command:
@@ -110,7 +109,7 @@ pip install datalayer_pycrdt==0.12.17
110109
```
111110
### Examples
112111

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

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

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

122121
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)).
123122

124-
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.
123+
### API Keys Configuration
124+
125+
Set the appropriate API key for your chosen provider:
126+
127+
**OpenAI:**
128+
```bash
129+
export OPENAI_API_KEY='your-api-key-here'
130+
```
131+
132+
**Anthropic:**
133+
```bash
134+
export ANTHROPIC_API_KEY='your-api-key-here'
135+
```
136+
137+
**Azure OpenAI:**
138+
```bash
139+
export AZURE_OPENAI_API_KEY='your-api-key-here'
140+
export AZURE_OPENAI_ENDPOINT='https://your-resource.openai.azure.com'
141+
export AZURE_OPENAI_API_VERSION='2024-08-01-preview' # optional
142+
```
143+
144+
**Important for Azure OpenAI:**
145+
- The `AZURE_OPENAI_ENDPOINT` should be just the base URL (e.g., `https://your-resource.openai.azure.com`)
146+
- Do NOT include `/openai/deployments/...` or query parameters in the endpoint
147+
- The deployment name is specified via the `--model-name` parameter
148+
- See `.env.azure.example` for a complete configuration template
125149

150+
**Other providers:**
126151
```bash
127-
cat << EOF >>.env
128-
OPENAI_API_VERSION="..."
129-
AZURE_OPENAI_ENDPOINT="..."
130-
AZURE_OPENAI_API_KEY="..."
131-
EOF
152+
export GOOGLE_API_KEY='your-api-key-here' # For Google/Gemini
153+
export COHERE_API_KEY='your-api-key-here' # For Cohere
154+
export GROQ_API_KEY='your-api-key-here' # For Groq
155+
export MISTRAL_API_KEY='your-api-key-here' # For Mistral
156+
# AWS credentials for Bedrock
157+
export AWS_ACCESS_KEY_ID='your-key'
158+
export AWS_SECRET_ACCESS_KEY='your-secret'
159+
export AWS_REGION='us-east-1'
132160
```
133161

134-
**Prompt Agent**
162+
### Model Specification
163+
164+
You can specify the model in two ways:
165+
166+
1. **Using `--model` with full string** (recommended):
167+
```bash
168+
--model "openai:gpt-4o"
169+
--model "anthropic:claude-sonnet-4-0"
170+
--model "azure-openai:deployment-name"
171+
```
172+
173+
2. **Using `--model-provider` and `--model-name`**:
174+
```bash
175+
--model-provider openai --model-name gpt-4o
176+
--model-provider anthropic --model-name claude-sonnet-4-0
177+
```
178+
179+
Supported providers: `openai`, `anthropic`, `azure-openai`, `github-copilot`, `google`, `bedrock`, `groq`, `mistral`, `cohere`
180+
181+
### Prompt Agent
135182

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

138185
```bash
139-
# Prompt agent example.
140-
# make jupyter-ai-agents-prompt
186+
# Using full model string (recommended)
141187
jupyter-ai-agents prompt \
142188
--url http://localhost:8888 \
143189
--token MY_TOKEN \
144-
--model-provider azure-openai \
145-
--model-name gpt-4o-mini \
190+
--model "anthropic:claude-sonnet-4-0" \
146191
--path notebook.ipynb \
147192
--input "Create a matplotlib example"
193+
194+
# Using provider and model name
195+
jupyter-ai-agents prompt \
196+
--url http://localhost:8888 \
197+
--token MY_TOKEN \
198+
--model-provider anthropic \
199+
--model-name claude-sonnet-4-0 \
200+
--path notebook.ipynb \
201+
--input "Create a pandas dataframe with sample data and plot it"
148202
```
149203

150-
![Jupyter AI Agents](https://assets.datalayer.tech/jupyter-ai-agent/ai-agent-prompt-demo-terminal.gif)
204+
![Jupyter AI Agents - Prompt](https://assets.datalayer.tech/jupyter-ai-agent/ai-agent-prompt-demo-terminal.gif)
205+
206+
### Explain Error Agent
151207

152-
**Explain Error Agent**
208+
Analyze and fix notebook errors:
153209

154210
```bash
155-
# Explain Error agent example.
156-
# make jupyter-ai-agents-explain-error
157211
jupyter-ai-agents explain-error \
158212
--url http://localhost:8888 \
159213
--token MY_TOKEN \
160-
--model-provider azure-openai \
161-
--model-name gpt-4o-mini \
162-
--path notebook.ipynb
214+
--model "anthropic:claude-sonnet-4-0" \
215+
--path notebook.ipynb \
216+
--current-cell-index 5
217+
```
218+
219+
![Jupyter AI Agents - Explain Error](https://assets.datalayer.tech/jupyter-ai-agent/ai-agent-explainerror-demo-terminal.gif)
220+
221+
### REPL Mode (Interactive)
222+
223+
For an interactive experience with direct access to all Jupyter MCP tools, use the REPL mode:
224+
225+
```bash
226+
jupyter-ai-agents repl \
227+
--url http://localhost:8888 \
228+
--token MY_TOKEN \
229+
--model "anthropic:claude-sonnet-4-0"
163230
```
164231

165-
![Jupyter AI Agents](https://assets.datalayer.tech/jupyter-ai-agent/ai-agent-explainerror-demo-terminal.gif)
232+
In REPL mode, you can directly ask the AI to:
233+
- List notebooks in directories
234+
- Read and analyze notebook contents
235+
- Execute code in cells
236+
- Insert new cells
237+
- Modify existing cells
238+
- Install Python packages
239+
240+
Example REPL interactions:
241+
242+
```
243+
> List all notebooks in the current directory
244+
> Create a new notebook called analysis.ipynb
245+
> In analysis.ipynb, create a cell that imports pandas and loads data.csv
246+
> Execute the cell and show me the first 5 rows
247+
> Add a matplotlib plot showing the distribution of the 'age' column
248+
```
249+
250+
The REPL provides special commands:
251+
- `/exit`: Exit the session
252+
- `/markdown`: Show last response in markdown format
253+
- `/multiline`: Toggle multiline input mode (use Ctrl+D to submit)
254+
- `/cp`: Copy last response to clipboard
255+
256+
You can also use a custom system prompt:
257+
258+
```bash
259+
jupyter-ai-agents repl \
260+
--url http://localhost:8888 \
261+
--token MY_TOKEN \
262+
--model "anthropic:claude-sonnet-4-0" \
263+
--system-prompt "You are a data science expert specializing in pandas and matplotlib."
264+
```
265+
266+
### Prompt Agent
267+
268+
Create and execute code based on user instructions:
269+
270+
```bash
271+
# Using full model string (recommended)
272+
jupyter-ai-agents prompt \
273+
--url http://localhost:8888 \
274+
--token MY_TOKEN \
275+
--model "anthropic:claude-sonnet-4-0" \
276+
--path notebook.ipynb \
277+
--input "Create a matplotlib example"
278+
279+
# Using provider and model name
280+
jupyter-ai-agents prompt \
281+
--url http://localhost:8888 \
282+
--token MY_TOKEN \
283+
--model-provider anthropic \
284+
--model-name claude-sonnet-4-0 \
285+
--path notebook.ipynb \
286+
--input "Create a pandas dataframe with sample data and plot it"
287+
```
288+
289+
### Explain Error Agent
290+
291+
Analyze and fix notebook errors:
292+
293+
```bash
294+
jupyter-ai-agents explain-error \
295+
--url http://localhost:8888 \
296+
--token MY_TOKEN \
297+
--model "anthropic:claude-sonnet-4-0" \
298+
--path notebook.ipynb \
299+
--current-cell-index 5
300+
```
166301

302+
## Uninstall
167303

168304
### About the Technology
169305

dev/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
~ BSD 3-Clause License
55
-->
66

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

99
[![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)

dev/content/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
~ BSD 3-Clause License
55
-->
66

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

99
[![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)

dev/content/notebook.ipynb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6-
"id": "a582b625-e712-4581-b611-3def5f40bd59",
7-
"metadata": {},
8-
"outputs": [],
9-
"source": []
10-
},
11-
{
12-
"cell_type": "code",
13-
"execution_count": null,
14-
"id": "84ca6269-06aa-42c3-815c-292980f031c0",
6+
"id": "6e785ae0-34d9-462e-aa9a-22d7b40e15d8",
157
"metadata": {},
168
"outputs": [],
179
"source": []

docs/.yarnrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) Datalayer, Inc. https://datalayer.io
1+
# Copyright (c) Datalayer, Inc. https://datalayer.ai
22
# Distributed under the terms of the MIT License.
33

44
enableImmutableInstalls: false

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) Datalayer, Inc. https://datalayer.io
1+
# Copyright (c) Datalayer, Inc. https://datalayer.ai
22
# Distributed under the terms of the MIT License.
33

44
SHELL=/bin/bash

0 commit comments

Comments
 (0)