Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
First version of a chat UI package, based on jupyter-ai chat UI
Browse files Browse the repository at this point in the history
  • Loading branch information
brichet committed Feb 20, 2024
1 parent 7807932 commit 15d6e52
Show file tree
Hide file tree
Showing 38 changed files with 2,560 additions and 433 deletions.
19 changes: 0 additions & 19 deletions .copier-answers.yml

This file was deleted.

59 changes: 8 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,30 @@
[![Github Actions Status](https://github.com/QuantStack/jupyterlab-chat/workflows/Build/badge.svg)](https://github.com/QuantStack/jupyterlab-chat/actions/workflows/build.yml)[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/QuantStack/jupyterlab-chat/main?urlpath=lab)
A chat extension for Jupyterlab

This extension is composed of a Python package named `jupyterlab_chat`
for the server extension and a NPM package named `@jupyterlab/chat`
for the frontend extension.
This package is composed of a Python package named `jupyterlab_chat`
for the server side and a NPM package named `@jupyterlab/chat`
for the frontend side.

## Requirements

- JupyterLab >= 4.0.0

## Install

To install the extension, execute:
To install the package, execute:

```bash
pip install jupyterlab_chat
```

## Uninstall

To remove the extension, execute:
To remove the package, execute:

```bash
pip uninstall jupyterlab_chat
```

## Troubleshoot

If you are seeing the frontend extension, but it is not working, check
that the server extension is enabled:

```bash
jupyter server extension list
```

If the server extension is installed and enabled, but you are not seeing
the frontend extension, check the frontend extension is installed:

```bash
jupyter labextension list
```

## Contributing

### Development install
Expand All @@ -58,44 +42,19 @@ The `jlpm` command is JupyterLab's pinned version of
# Change directory to the jupyterlab_chat directory
# Install package in development mode
pip install -e ".[test]"
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Server extension must be manually installed in develop mode
jupyter server extension enable jupyterlab_chat
# Rebuild extension Typescript source after making changes
# Rebuild 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
```
By default, the `jlpm build` command generates the source maps for this package to make it easier to debug using the browser dev tools.

### Development uninstall

```bash
# Server extension must be manually disabled in develop mode
jupyter server extension disable jupyterlab_chat
pip uninstall jupyterlab_chat
```

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/chat` within that folder.

### Testing the extension
### Testing the package

#### Server tests

Expand All @@ -105,8 +64,6 @@ Install test dependencies (needed only once):

```sh
pip install -e ".[test]"
# Each time you install the Python package, you need to restore the front-end extension link
jupyter labextension develop . --overwrite
```

To execute them, run:
Expand Down
5 changes: 0 additions & 5 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import pytest

pytest_plugins = ("pytest_jupyter.jupyter_server", )


@pytest.fixture
def jp_server_config(jp_server_config):
return {"ServerApp": {"jpserver_extensions": {"jupyterlab_chat": True}}}
7 changes: 0 additions & 7 deletions jupyter-config/server-config/jupyterlab_chat.json

This file was deleted.

27 changes: 1 addition & 26 deletions jupyterlab_chat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,5 @@
import warnings
warnings.warn("Importing 'jupyterlab_chat' outside a proper installation.")
__version__ = "dev"
from .handlers import setup_handlers


def _jupyter_labextension_paths():
return [{
"src": "labextension",
"dest": "@jupyterlab/chat"
}]


def _jupyter_server_extension_points():
return [{
"module": "jupyterlab_chat"
}]


def _load_jupyter_server_extension(server_app):
"""Registers the API handler to receive HTTP requests from the frontend extension.
Parameters
----------
server_app: jupyterlab.labapp.LabApp
JupyterLab application instance
"""
setup_handlers(server_app.web_app)
name = "jupyterlab_chat"
server_app.log.info(f"Registered {name} server extension")
from .extension import ChatExtension
14 changes: 1 addition & 13 deletions jupyterlab_chat/tests/test_handlers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
import json


async def test_get_example(jp_fetch):
# When
response = await jp_fetch("jupyterlab-chat", "get-example")

# Then
assert response.code == 200
payload = json.loads(response.body)
assert payload == {
"data": "This is /jupyterlab-chat/get-example endpoint!"
}
### TODO ####
Loading

0 comments on commit 15d6e52

Please sign in to comment.