Skip to content

Commit

Permalink
Upgrade to JupyterLab 4 (jupyterlab#296)
Browse files Browse the repository at this point in the history
* initial upgrade to JL4

* fix RTC

* update workflows and scripts to JL4

* update documentation to JL4

* pre-commit

* update documentation

* documentation updates per @JasonWeill
  • Loading branch information
dlqqq authored Jul 27, 2023
1 parent ff350ab commit 4ad7fa6
Show file tree
Hide file tree
Showing 21 changed files with 18,377 additions and 12,735 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
with:
python_version: "3.11.x"
- name: Install JupyterLab
run: pip install jupyterlab~=3.6
run: pip install jupyterlab~=4.0
- name: Install JS dependencies
run: jlpm
- name: Run JS Lint
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ dev.sh
.vscode

.jupyter_ystore.db

.yarn
2 changes: 1 addition & 1 deletion .jupyter-releaser.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[hooks]
before-build-npm = [
"python -m pip install jupyterlab~=3.6",
"python -m pip install jupyterlab~=4.0",
"jlpm",
"jlpm build:prod"
]
Expand Down
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nodeLinker: "node-modules"
enableImmutableInstalls: false
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ in JupyterLab and the Jupyter Notebook. More specifically, Jupyter AI offers:

Documentation is available on [ReadTheDocs](https://jupyter-ai.readthedocs.io/en/latest/).

## Installation
## Requirements

You can use `conda` or `pip` to install Jupyter AI. If you're using macOS on an Apple Silicon-based Mac (M1, M1 Pro, M2, etc.), we strongly recommend using `conda`.
- Python 3.8 - 3.11
- JupyterLab 4

Python 3.8 or newer is required; older versions of Python do not support the `typing` module we use, and as of June 30, 2023, have reached end of life.
## Installation

Before you can use Jupyter AI, you will need to install any packages and set environment variables with API keys for the model providers that you will use. See [our documentation](https://jupyter-ai.readthedocs.io/en/latest/users/index.html) for details about what you'll need.
Below is a simplified overview of the installation and usage process.
See [our official documentation](https://jupyter-ai.readthedocs.io/en/latest/users/index.html)
for details on installing and using Jupyter AI.

### With pip

Expand Down
137 changes: 81 additions & 56 deletions docs/source/users/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,102 @@ please see our {doc}`contributor's guide </contributors/index>`.

## Prerequisites

You can run Jupyter AI on any system that can run a supported Python version from 3.8 to 3.11, including recent Windows, macOS, and Linux versions.
You can run Jupyter AI on any system that can run a supported Python version
from 3.8 to 3.11, including recent Windows, macOS, and Linux versions.

If you use `conda`, you can install Python 3.11 in your environment by running:

```
conda install python=3.11
```

To use the `jupyter_ai` package, you will also need to have a currently-maintained version of JupyterLab 3 installed. We do not yet support JupyterLab 4. If you use `conda`, you can install JupyterLab in your environment by running:
The `jupyter_ai` package, which provides the lab extension and user interface in
JupyterLab, depends on JupyterLab 4. If upgrading to JupyterLab 4 is not
possible in your environment, you should install `jupyter_ai` v1.x instead.
See "Installation" for more details.

You can install JupyterLab using `pip` or `conda`.

1. via `pip`:

```
# change 4.0 to 3.0 if you need JupyterLab 3
pip install jupyterlab~=4.0
```

2. via `conda`:

```
conda install jupyterlab
# change 4.0 to 3.0 if you need JupyterLab 3
conda config --add channels conda-forge
conda config --set channel_priority strict
conda install jupyterlab~=4.0
```

You should have Jupyter Server 2.x (not 1.x) installed. A fresh install of JupyterLab 3.6.x should come with Server 2.x. You can find your current Server version by running `jupyter --version` and checking for a line beginning with `jupyter_server`. To upgrade your version of Jupyter Server, run:
The `jupyter_ai_magics` package, which provides exclusively the IPython magics,
does not depend on JupyterLab or `jupyter_ai`. You can install
`jupyter_ai_magics` without installing `jupyterlab` or `jupyter_ai`.

## Installation

### Installation via `pip`

To install the JupyterLab extension, you can run:

```
pip install jupyter_server --upgrade
pip install jupyter_ai
```

You can use the `jupyter_ai_magics` package without JupyterLab, but you will need a compatible interface, such as [IPython](https://ipython.org/).
The latest major version of `jupyter_ai`, v2, only supports JupyterLab 4. If you
need support for JupyterLab 3, you should install `jupyter_ai` v1 instead:

```
pip install jupyter_ai~=1.0
```

If you are not using JupyterLab and you only want to install the Jupyter AI `%%ai` magic, you can run:

```
$ pip install jupyter_ai_magics
```

`jupyter_ai` depends on `jupyter_ai_magics`, so installing `jupyter_ai`
automatically installs `jupyter_ai_magics`.

### Installation via `pip` within Conda environment (recommended)

We highly recommend installing both JupyterLab and Jupyter AI within an isolated
Conda environment to avoid clobbering Python packages in your existing Python
environment.

First, install
[conda](https://conda.io/projects/conda/en/latest/user-guide/install/index.html)
and create an environment that uses Python 3.11:

$ conda create -n jupyter-ai python=3.11
$ conda activate jupyter-ai
$ pip install jupyter_ai

Then, follow the steps from "Requirements" and "Installation via `pip`" to
install JupyterLab and Jupyter AI in this Conda environment.

When starting JupyterLab with Jupyter AI, make sure to activate the Conda
environment first:

```
conda activate jupyter-ai
jupyter lab
```

## Uninstallation

To remove the extension, run:

$ pip uninstall jupyter_ai

or

$ pip uninstall jupyter_ai_magics

## Model providers

Expand Down Expand Up @@ -80,56 +155,6 @@ responsible for all charges they incur when they make API requests. Review your
provider's pricing information before submitting requests via Jupyter AI.
:::

## Installing

You can use `conda` or `pip` to install Jupyter AI. If you're using macOS on an Apple Silicon-based Mac (M1, M1 Pro, M2, etc.), we strongly recommend using `conda`.

Python 3.8 or newer is required; older versions of Python do not support the
`typing` module we use, and as of June 30, 2023, have reached end of life.

Before you can use Jupyter AI, you will need to install any packages and set environment variables with API keys for the model providers that you will use. See [our documentation](https://jupyter-ai.readthedocs.io/en/latest/users/index.html) for details about what you'll need.

### With pip

If you want to install both the `%%ai` magic and the JupyterLab extension, you can run:

$ pip install jupyter_ai

If you are not using JupyterLab and you only want to install the Jupyter AI `%%ai` magic, you can run:

$ pip install jupyter_ai_magics


### With conda

First, install [conda](https://conda.io/projects/conda/en/latest/user-guide/install/index.html) and create an environment that uses Python 3.11:

$ conda create -n jupyter-ai python=3.11
$ conda activate jupyter-ai
$ pip install jupyter_ai

If you are not using JupyterLab and you only want to install the Jupyter AI `%%ai` magic, you can run:

$ pip install jupyter_ai_magics

The `%%ai` magic will work anywhere the IPython kernel runs (JupyterLab, Jupyter Notebook, Google Colab, VSCode, etc.).

You can check that the Jupyter AI server extension is enabled by running:

$ jupyter server extension list

To verify that the frontend extension is installed, run:

$ jupyter labextension list

To remove the extension, run:

$ pip uninstall jupyter_ai

or

$ pip uninstall jupyter_ai_magics

## The chat interface

The easiest way to get started with Jupyter AI is to use the chat interface.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"watch": "lerna run watch --parallel --stream"
},
"devDependencies": {
"@jupyterlab/builder": "^3.1.0",
"@jupyterlab/builder": "^4",
"lerna": "^6.4.1",
"nx": "^15.9.2"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

- name: Install dependencies
run: python -m pip install -U jupyterlab~=3.1
run: python -m pip install -U jupyterlab~=4.0

- name: Lint the extension
run: |
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
sudo rm -rf $(which node)
sudo rm -rf $(which node)
pip install "jupyterlab~=3.1" {{ cookiecutter.python_name }}*.whl
pip install "jupyterlab~=4.0" {{ cookiecutter.python_name }}*.whl
jupyter labextension list
jupyter labextension list 2>&1 | grep -ie "{{ cookiecutter.labextension_name }}.*OK"
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
- name: Install the extension
run: |
set -eux
python -m pip install "jupyterlab~=3.1" {{ cookiecutter.python_name }}*.whl
python -m pip install "jupyterlab~=4.0" {{ cookiecutter.python_name }}*.whl
- name: Install dependencies
working-directory: ui-tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

- name: Install dependencies
run: python -m pip install -U jupyterlab~=3.1
run: python -m pip install -U jupyterlab~=4.0

- name: Install extension
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ that provides a frontend labextension registering inserters.

## Requirements

- JupyterLab >= 3.0
- Python 3.8 - 3.11
- JupyterLab 4

## Install

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ channels:
dependencies:
# runtime dependencies
- python >=3.8,<3.9.0a0
- jupyterlab >=3,<4.0.0a0
- jupyterlab >=4,<5
# labextension build dependencies
- nodejs >=18,<19
- pip
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["hatchling>=1.4.0", "jupyterlab>=3.4.7,<4.0.0", "hatch-nodejs-version"]
requires = ["hatchling>=1.4.0", "jupyterlab~=4.0", "hatch-nodejs-version"]
build-backend = "hatchling.build"

[project]
Expand All @@ -10,7 +10,7 @@ requires-python = ">=3.8"
classifiers = [
"Framework :: Jupyter",
"Framework :: Jupyter :: JupyterLab",
"Framework :: Jupyter :: JupyterLab :: 3",
"Framework :: Jupyter :: JupyterLab :: 4",
"Framework :: Jupyter :: JupyterLab :: Extensions",
"Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt",
"License :: OSI Approved :: BSD License",
Expand Down Expand Up @@ -82,7 +82,7 @@ build_dir = "{{cookiecutter.python_name}}/labextension"
version_cmd = "hatch version"

[tool.jupyter-releaser.hooks]
before-build-npm = ["python -m pip install jupyterlab~=3.1", "jlpm", "jlpm build:prod"]
before-build-npm = ["python -m pip install jupyterlab~=4.0", "jlpm", "jlpm build:prod"]
before-build-python = ["jlpm clean:all"]

[tool.check-wheel-contents]
Expand Down
9 changes: 6 additions & 3 deletions packages/jupyter-ai/jupyter_ai/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ async def get(self, *args, **kwargs):
await res

def get_chat_user(self) -> ChatUser:
"""Retrieves the current user. If collaborative mode is disabled, one
is synthesized from the login."""
collaborative = self.config.get("LabApp", {}).get("collaborative", False)
"""Retrieves the current user. If `jupyter_collaboration` is not
installed, one is synthesized from the server's current shell
environment."""
collaborative = self.config.ServerApp.jpserver_extensions.get_value({}).get(
"jupyter_collaboration", False
)

if collaborative:
return ChatUser(**asdict(self.current_user))
Expand Down
27 changes: 15 additions & 12 deletions packages/jupyter-ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,21 @@
"dependencies": {
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@jupyterlab/application": "^3.6.3",
"@jupyterlab/cells": "^3.6.3",
"@jupyterlab/collaboration": "^3.6.3",
"@jupyterlab/coreutils": "^5.6.3",
"@jupyterlab/fileeditor": "^3.6.3",
"@jupyterlab/notebook": "^3.6.3",
"@jupyterlab/services": "^6.6.3",
"@jupyterlab/ui-components": "^3.6.3",
"@jupyter/collaboration": "^1",
"@jupyterlab/application": "^4",
"@jupyterlab/cells": "^4",
"@jupyterlab/codeeditor": "^4",
"@jupyterlab/codemirror": "^4",
"@jupyterlab/collaboration": "^3",
"@jupyterlab/coreutils": "^6",
"@jupyterlab/fileeditor": "^4",
"@jupyterlab/notebook": "^4",
"@jupyterlab/services": "^7",
"@jupyterlab/ui-components": "^4",
"@mui/icons-material": "^5.11.0",
"@mui/material": "^5.11.0",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-markdown": "^8.0.6",
"react-syntax-highlighter": "^15.5.0",
"rehype-katex": "^6.0.2",
Expand All @@ -80,8 +83,8 @@
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@jupyterlab/builder": "^3.5.1",
"@jupyterlab/testutils": "^3.0.0",
"@jupyterlab/builder": "^4",
"@jupyterlab/testutils": "^4",
"@types/jest": "^26.0.0",
"@types/react-syntax-highlighter": "^15.5.6",
"@typescript-eslint/eslint-plugin": "^4.8.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/jupyter-ai/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["hatchling>=1.4.0", "jupyterlab>=3.4.7,<4.0.0", "hatch-nodejs-version"]
requires = ["hatchling>=1.4.0", "jupyterlab~=4.0", "hatch-nodejs-version"]
build-backend = "hatchling.build"

[project]
Expand All @@ -10,7 +10,7 @@ requires-python = ">=3.8"
classifiers = [
"Framework :: Jupyter",
"Framework :: Jupyter :: JupyterLab",
"Framework :: Jupyter :: JupyterLab :: 3",
"Framework :: Jupyter :: JupyterLab :: 4",
"Framework :: Jupyter :: JupyterLab :: Extensions",
"Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt",
"License :: OSI Approved :: BSD License",
Expand All @@ -23,7 +23,7 @@ classifiers = [
]
dependencies = [
"jupyter_server>=1.6,<3",
"jupyterlab>=3.5,<4",
"jupyterlab~=4.0",
"pydantic",
"openai~=0.26",
"aiosqlite~=0.18",
Expand Down
Loading

0 comments on commit 4ad7fa6

Please sign in to comment.