Metadata-Version: 2.4
Name: jupyterlab_browser_ai
Version: 0.6.0
Summary: In-browser AI in JupyterLab and Jupyter Notebook
Project-URL: Homepage, https://github.com/jtpio/jupyterlab-browser-ai
Project-URL: Bug Tracker, https://github.com/jtpio/jupyterlab-browser-ai/issues
Project-URL: Repository, https://github.com/jtpio/jupyterlab-browser-ai.git
Author: Jeremy Tuloup
License: BSD 3-Clause License
        
        Copyright (c) 2025, Jeremy Tuloup
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License-File: LICENSE
Keywords: jupyter,jupyterlab,jupyterlab-extension
Classifier: Framework :: Jupyter
Classifier: Framework :: Jupyter :: JupyterLab
Classifier: Framework :: Jupyter :: JupyterLab :: 4
Classifier: Framework :: Jupyter :: JupyterLab :: Extensions
Classifier: Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.9
Requires-Dist: jupyterlite-ai>=0.9.0a3
Description-Content-Type: text/markdown

# jupyterlab_browser_ai

[![Github Actions Status](https://github.com/jtpio/jupyterlab-browser-ai/workflows/Build/badge.svg)](https://github.com/jtpio/jupyterlab-browser-ai/actions/workflows/build.yml)
[![lite-badge](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://jtpio.github.io/jupyterlab-browser-ai/lab/index.html)

In-browser AI in JupyterLab and Jupyter Notebook

## Requirements

- JupyterLab >= 4.0.0

## Install

To install the extension, execute:

```bash
pip install jupyterlab_browser_ai
```

## Chrome AI

This extension provides several features powered by
[Chrome's built-in AI APIs](https://developer.chrome.com/docs/ai/built-in-apis).
These features require no API key and run fully on-device. They are
automatically enabled when the browser supports the corresponding API and
gracefully disabled otherwise.

### Enabling Chrome AI

See the official [Get started with built-in AI](https://developer.chrome.com/docs/ai/get-started)
guide for full details. In short:

1. Open `chrome://flags/#optimization-guide-on-device-model` and set it to
   **Enabled**.
2. Open `chrome://flags/#prompt-api-for-gemini-nano` and set it to **Enabled**.
3. Restart Chrome.
4. Verify by running `await LanguageModel.availability();` in the DevTools
   console — it should return `"available"`.

**System requirements:**

- Chrome on Windows 10/11, macOS 13+, Linux, or ChromeOS (Chromebook Plus)
- At least 22 GB of free disk space on the volume containing your Chrome profile
- GPU with > 4 GB VRAM, or 16 GB RAM with 4+ CPU cores

### Chat provider

Chrome Built-in AI is registered as a chat provider (provider ID `chrome-ai`).
Select it in the JupyterLab AI provider dropdown to chat with the on-device
model — no API key or model download required.

### Alt text generation

Right-click any image in a notebook markdown cell and select
**Generate Alt Text with ChromeAI**. The extension sends the image to Chrome's
Prompt API, generates a concise alt text description, and updates the markdown
source. The alt text is also copied to the clipboard as a fallback.

### Audio transcription

Right-click an audio file (`.mp3`, `.wav`, `.ogg`, `.m4a`, `.aac`, `.flac`,
`.opus`) in the file browser and select **Generate Transcript with ChromeAI**.
The transcript is saved as `<filename>_transcript.txt` in the same directory.

### Notebook proofreader

Open a notebook and run the **Proofread Notebook** command from the command
palette (or the toolbar button). The extension uses Chrome's Proofreader API to
check grammar and spelling in all markdown cells and applies corrections
in-place.

### File summarizer

When Chrome's Summarizer API is available, files in the file browser
(`.ipynb`, `.md`, `.txt`, `.py`, `.js`, `.ts`) display a sparkle badge. Click
the badge to generate a TL;DR summary shown in a tooltip. Summaries are cached
and automatically invalidated when the file is saved.

## Transformers.js models

Transformers.js model IDs can be discovered on Hugging Face:

- https://huggingface.co/models?library=transformers.js&pipeline_tag=text-generation&sort=downloads

By default, this extension uses:

- `onnx-community/Qwen2.5-Coder-0.5B-Instruct`
- `onnx-community/Qwen2.5-0.5B-Instruct`
- `HuggingFaceTB/SmolLM2-360M-Instruct`

The `transformersJsModels` setting for `jupyterlab-browser-ai` controls the
full dropdown list. If you set it, your list replaces the defaults.

For example:

```json
{
  "transformersJsModels": [
    "onnx-community/Qwen3-0.6B-ONNX",
    "your-org/your-custom-model",
    "HuggingFaceTB/SmolLM2-360M-Instruct"
  ]
}
```

## WebLLM models

WebLLM model IDs can be discovered in the WebLLM prebuilt model config:

- https://github.com/mlc-ai/web-llm/blob/main/src/config.ts (look for `prebuiltAppConfig.model_list[].model_id`)
- https://webllm.mlc.ai/docs/user/basic_usage.html#model-records-in-webllm (official WebLLM docs)

To print the model IDs from the exact `@mlc-ai/web-llm` version installed in this project:

```bash
node -e "import('@mlc-ai/web-llm').then(w => console.log(w.prebuiltAppConfig.model_list.map(m => m.model_id).join('\n')))"
```

By default, this extension uses:

- `Llama-3.2-3B-Instruct-q4f16_1-MLC`
- `Llama-3.2-1B-Instruct-q4f16_1-MLC`
- `Phi-3.5-mini-instruct-q4f16_1-MLC`
- `gemma-2-2b-it-q4f16_1-MLC`
- `Qwen3-0.6B-q4f16_1-MLC`

The `webLLMModels` setting in `jupyterlab-browser-ai` controls the full
WebLLM model dropdown list. If you set it, your list replaces the defaults.

For example:

```json
{
  "webLLMModels": [
    "Qwen3-0.6B-q4f16_1-MLC",
    "Llama-3.2-1B-Instruct-q4f16_1-MLC",
    "gemma-2-2b-it-q4f16_1-MLC"
  ]
}
```

## Uninstall

To remove the extension, execute:

```bash
pip uninstall jupyterlab_browser_ai
```

## Contributing

### Development install

Note: You will need NodeJS to build the extension package.

The `jlpm` command is JupyterLab's pinned version of
[yarn](https://yarnpkg.com/) that is installed with JupyterLab. You may use
`yarn` or `npm` in lieu of `jlpm` below.

```bash
# Clone the repo to your local environment
# Change directory to the jupyterlab_browser_ai directory
# Install package in development mode
pip install -e "."
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Rebuild extension Typescript source after making changes
jlpm build
```

You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.

```bash
# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm watch
# Run JupyterLab in another terminal
jupyter lab
```

With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).

By default, the `jlpm build` command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:

```bash
jupyter lab build --minimize=False
```

### Development uninstall

```bash
pip uninstall jupyterlab_browser_ai
```

In development mode, you will also need to remove the symlink created by `jupyter labextension develop`
command. To find its location, you can run `jupyter labextension list` to figure out where the `labextensions`
folder is located. Then you can remove the symlink named `jupyterlab-browser-ai` within that folder.

### Packaging the extension

See [RELEASE](RELEASE.md)
