mito-ai 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mito-ai-0.1.1/LICENSE +3 -0
- mito-ai-0.1.1/PKG-INFO +142 -0
- mito-ai-0.1.1/README.md +115 -0
- mito-ai-0.1.1/jupyter-config/jupyter_server_config.d/mito-ai.json +7 -0
- mito-ai-0.1.1/mito-ai/OpenAICompletionHandler.py +48 -0
- mito-ai-0.1.1/mito-ai/__init__.py +49 -0
- mito-ai-0.1.1/mito-ai/_version.py +25 -0
- mito-ai-0.1.1/mito-ai/labextension/build_log.json +719 -0
- mito-ai-0.1.1/mito-ai/labextension/package.json +206 -0
- mito-ai-0.1.1/mito-ai/labextension/static/lib_index_js.d3d3a588bdd8aeb75ca3.js +2329 -0
- mito-ai-0.1.1/mito-ai/labextension/static/lib_index_js.d3d3a588bdd8aeb75ca3.js.map +1 -0
- mito-ai-0.1.1/mito-ai/labextension/static/remoteEntry.0d4d4f4df37f285d41a9.js +569 -0
- mito-ai-0.1.1/mito-ai/labextension/static/remoteEntry.0d4d4f4df37f285d41a9.js.map +1 -0
- mito-ai-0.1.1/mito-ai/labextension/static/style.js +4 -0
- mito-ai-0.1.1/mito-ai/labextension/static/style_index_js.78a29aa3a61ae44379cf.js +496 -0
- mito-ai-0.1.1/mito-ai/labextension/static/style_index_js.78a29aa3a61ae44379cf.js.map +1 -0
- mito-ai-0.1.1/mito_ai.egg-info/PKG-INFO +142 -0
- mito-ai-0.1.1/mito_ai.egg-info/SOURCES.txt +24 -0
- mito-ai-0.1.1/mito_ai.egg-info/dependency_links.txt +1 -0
- mito-ai-0.1.1/mito_ai.egg-info/entry_points.txt +3 -0
- mito-ai-0.1.1/mito_ai.egg-info/not-zip-safe +1 -0
- mito-ai-0.1.1/mito_ai.egg-info/requires.txt +7 -0
- mito-ai-0.1.1/mito_ai.egg-info/top_level.txt +1 -0
- mito-ai-0.1.1/pyproject.toml +3 -0
- mito-ai-0.1.1/setup.cfg +4 -0
- mito-ai-0.1.1/setup.py +111 -0
mito-ai-0.1.1/LICENSE
ADDED
mito-ai-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mito-ai
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: AI chat for JupyterLab
|
|
5
|
+
Home-page: UNKNOWN
|
|
6
|
+
Author: Aaron Diamond-Reivich
|
|
7
|
+
Author-email: aaron@sagacollab.com
|
|
8
|
+
License: GNU Affero General Public License v3
|
|
9
|
+
Description: # mito_ai
|
|
10
|
+
|
|
11
|
+
[](/actions/workflows/build.yml)
|
|
12
|
+
|
|
13
|
+
AI chat for JupyterLab. This codebase contains two main components:
|
|
14
|
+
1. A Jupyter server extension that handles the backend logic for the chat.
|
|
15
|
+
2. Several JupyterLab extensions that handle the frontend logic for interacting with the AI, including the chat sidebar and the error message rendermime.
|
|
16
|
+
|
|
17
|
+
## Requirements
|
|
18
|
+
|
|
19
|
+
- JupyterLab >= 4.0.0
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
To install the extension, execute:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install mito-ai
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Uninstall
|
|
30
|
+
|
|
31
|
+
To remove the extension, execute:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip uninstall mito-ai
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Contributing
|
|
38
|
+
|
|
39
|
+
### Development install
|
|
40
|
+
|
|
41
|
+
To ensure consistent package management, please use `jlpm` instead of `npm` for this project.
|
|
42
|
+
|
|
43
|
+
Note: You will need NodeJS to build the extension package.
|
|
44
|
+
|
|
45
|
+
The `jlpm` command is JupyterLab's pinned version of
|
|
46
|
+
[yarn](https://yarnpkg.com/) that is installed with JupyterLab.
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Clone the repo to your local environment
|
|
50
|
+
# Change directory to the mito-ai directory
|
|
51
|
+
|
|
52
|
+
# Required to deal with Yarn 3 workspace rules
|
|
53
|
+
touch yarn.lock
|
|
54
|
+
|
|
55
|
+
# Install package in development mode
|
|
56
|
+
pip install -e ".[test, deploy]"
|
|
57
|
+
|
|
58
|
+
# Install the node modules
|
|
59
|
+
jlpm install
|
|
60
|
+
|
|
61
|
+
# Link your development version of the extension with JupyterLab
|
|
62
|
+
jupyter labextension develop . --overwrite
|
|
63
|
+
|
|
64
|
+
# Start the jupyter server extension for development
|
|
65
|
+
jupyter server extension enable --py mito-ai
|
|
66
|
+
|
|
67
|
+
# Rebuild extension Typescript source after making changes
|
|
68
|
+
# In case of Error: If this command fails because the lib directory was not created (the error will say something like
|
|
69
|
+
# unable to find main entry point) then run `jlpm run clean:lib` first to get rid of the old buildcache
|
|
70
|
+
# that might be preventing a new lib directory from getting created.
|
|
71
|
+
jlpm build
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
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.
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Watch the source directory in one terminal, automatically rebuilding when needed
|
|
78
|
+
jlpm watch
|
|
79
|
+
# Run JupyterLab in another terminal
|
|
80
|
+
jupyter lab
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
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).
|
|
84
|
+
|
|
85
|
+
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:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
jupyter lab build --minimize=False
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Development uninstall
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
pip uninstall mito-ai
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
In development mode, you will also need to remove the symlink created by `jupyter labextension develop`
|
|
98
|
+
command. To find its location, you can run `jupyter labextension list` to figure out where the `labextensions`
|
|
99
|
+
folder is located. Then you can remove the symlink named `mito-ai` within that folder.
|
|
100
|
+
|
|
101
|
+
### Testing the extension
|
|
102
|
+
|
|
103
|
+
#### Frontend tests
|
|
104
|
+
|
|
105
|
+
This extension is using [Jest](https://jestjs.io/) for JavaScript code testing.
|
|
106
|
+
|
|
107
|
+
To execute them, execute:
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
jlpm
|
|
111
|
+
jlpm test
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### Integration tests
|
|
115
|
+
|
|
116
|
+
This extension uses [Playwright](https://playwright.dev/docs/intro) for the integration tests (aka user level tests).
|
|
117
|
+
More precisely, the JupyterLab helper [Galata](https://github.com/jupyterlab/jupyterlab/tree/master/galata) is used to handle testing the extension in JupyterLab.
|
|
118
|
+
|
|
119
|
+
More information are provided within the [ui-tests](./ui-tests/README.md) README.
|
|
120
|
+
|
|
121
|
+
### Packaging the extension
|
|
122
|
+
|
|
123
|
+
See [RELEASE](RELEASE.md)
|
|
124
|
+
|
|
125
|
+
Keywords: AI,Jupyter,Mito
|
|
126
|
+
Platform: UNKNOWN
|
|
127
|
+
Classifier: Framework :: Jupyter
|
|
128
|
+
Classifier: Framework :: Jupyter :: JupyterLab
|
|
129
|
+
Classifier: Framework :: Jupyter :: JupyterLab :: 4
|
|
130
|
+
Classifier: Framework :: Jupyter :: JupyterLab :: Extensions
|
|
131
|
+
Classifier: Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt
|
|
132
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
133
|
+
Classifier: Programming Language :: Python
|
|
134
|
+
Classifier: Programming Language :: Python :: 3
|
|
135
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
136
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
137
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
138
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
139
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
140
|
+
Requires-Python: >=3.8
|
|
141
|
+
Description-Content-Type: text/markdown
|
|
142
|
+
Provides-Extra: deploy
|
mito-ai-0.1.1/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# mito_ai
|
|
2
|
+
|
|
3
|
+
[](/actions/workflows/build.yml)
|
|
4
|
+
|
|
5
|
+
AI chat for JupyterLab. This codebase contains two main components:
|
|
6
|
+
1. A Jupyter server extension that handles the backend logic for the chat.
|
|
7
|
+
2. Several JupyterLab extensions that handle the frontend logic for interacting with the AI, including the chat sidebar and the error message rendermime.
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- JupyterLab >= 4.0.0
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
To install the extension, execute:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install mito-ai
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Uninstall
|
|
22
|
+
|
|
23
|
+
To remove the extension, execute:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip uninstall mito-ai
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Contributing
|
|
30
|
+
|
|
31
|
+
### Development install
|
|
32
|
+
|
|
33
|
+
To ensure consistent package management, please use `jlpm` instead of `npm` for this project.
|
|
34
|
+
|
|
35
|
+
Note: You will need NodeJS to build the extension package.
|
|
36
|
+
|
|
37
|
+
The `jlpm` command is JupyterLab's pinned version of
|
|
38
|
+
[yarn](https://yarnpkg.com/) that is installed with JupyterLab.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# Clone the repo to your local environment
|
|
42
|
+
# Change directory to the mito-ai directory
|
|
43
|
+
|
|
44
|
+
# Required to deal with Yarn 3 workspace rules
|
|
45
|
+
touch yarn.lock
|
|
46
|
+
|
|
47
|
+
# Install package in development mode
|
|
48
|
+
pip install -e ".[test, deploy]"
|
|
49
|
+
|
|
50
|
+
# Install the node modules
|
|
51
|
+
jlpm install
|
|
52
|
+
|
|
53
|
+
# Link your development version of the extension with JupyterLab
|
|
54
|
+
jupyter labextension develop . --overwrite
|
|
55
|
+
|
|
56
|
+
# Start the jupyter server extension for development
|
|
57
|
+
jupyter server extension enable --py mito-ai
|
|
58
|
+
|
|
59
|
+
# Rebuild extension Typescript source after making changes
|
|
60
|
+
# In case of Error: If this command fails because the lib directory was not created (the error will say something like
|
|
61
|
+
# unable to find main entry point) then run `jlpm run clean:lib` first to get rid of the old buildcache
|
|
62
|
+
# that might be preventing a new lib directory from getting created.
|
|
63
|
+
jlpm build
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
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.
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# Watch the source directory in one terminal, automatically rebuilding when needed
|
|
70
|
+
jlpm watch
|
|
71
|
+
# Run JupyterLab in another terminal
|
|
72
|
+
jupyter lab
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
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).
|
|
76
|
+
|
|
77
|
+
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:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
jupyter lab build --minimize=False
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Development uninstall
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pip uninstall mito-ai
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
In development mode, you will also need to remove the symlink created by `jupyter labextension develop`
|
|
90
|
+
command. To find its location, you can run `jupyter labextension list` to figure out where the `labextensions`
|
|
91
|
+
folder is located. Then you can remove the symlink named `mito-ai` within that folder.
|
|
92
|
+
|
|
93
|
+
### Testing the extension
|
|
94
|
+
|
|
95
|
+
#### Frontend tests
|
|
96
|
+
|
|
97
|
+
This extension is using [Jest](https://jestjs.io/) for JavaScript code testing.
|
|
98
|
+
|
|
99
|
+
To execute them, execute:
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
jlpm
|
|
103
|
+
jlpm test
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Integration tests
|
|
107
|
+
|
|
108
|
+
This extension uses [Playwright](https://playwright.dev/docs/intro) for the integration tests (aka user level tests).
|
|
109
|
+
More precisely, the JupyterLab helper [Galata](https://github.com/jupyterlab/jupyterlab/tree/master/galata) is used to handle testing the extension in JupyterLab.
|
|
110
|
+
|
|
111
|
+
More information are provided within the [ui-tests](./ui-tests/README.md) README.
|
|
112
|
+
|
|
113
|
+
### Packaging the extension
|
|
114
|
+
|
|
115
|
+
See [RELEASE](RELEASE.md)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import openai
|
|
3
|
+
from jupyter_server.base.handlers import APIHandler
|
|
4
|
+
from tornado import web
|
|
5
|
+
import json
|
|
6
|
+
from openai import OpenAI
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# This handler is responsible for the mito_ai/completion endpoint.
|
|
10
|
+
# It takes a message from the user, sends it to the OpenAI API, and returns the response.
|
|
11
|
+
# Important: Because this is a server extension, print statements are sent to the
|
|
12
|
+
# jupyter server terminal by default (ie: the terminal you ran `jupyter lab`)
|
|
13
|
+
class OpenAICompletionHandler(APIHandler):
|
|
14
|
+
@web.authenticated
|
|
15
|
+
def post(self):
|
|
16
|
+
# Retrieve the message from the request
|
|
17
|
+
data = self.get_json_body()
|
|
18
|
+
messages = data.get('messages', '')
|
|
19
|
+
|
|
20
|
+
# Get the OpenAI API key from environment variables
|
|
21
|
+
openai_api_key = os.getenv('OPENAI_API_KEY')
|
|
22
|
+
if not openai_api_key:
|
|
23
|
+
# If the API key is not set, return a 401 unauthorized error
|
|
24
|
+
self.set_status(401)
|
|
25
|
+
self.finish(json.dumps({"response": "OPENAI_API_KEY not set"}))
|
|
26
|
+
return
|
|
27
|
+
|
|
28
|
+
# Set up the OpenAI client
|
|
29
|
+
openai.api_key = openai_api_key
|
|
30
|
+
client = OpenAI()
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
# Query OpenAI API
|
|
34
|
+
response = client.chat.completions.create(
|
|
35
|
+
model="gpt-4o-mini",
|
|
36
|
+
messages=messages
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
response_dict = response.to_dict()
|
|
40
|
+
|
|
41
|
+
# Send the response back to the frontend
|
|
42
|
+
# TODO: In the future, instead of returning the raw response,
|
|
43
|
+
# return a cleaned up version of the response so we can support
|
|
44
|
+
# multiple models
|
|
45
|
+
self.finish(json.dumps(response_dict))
|
|
46
|
+
except Exception as e:
|
|
47
|
+
self.set_status(500)
|
|
48
|
+
self.finish(json.dumps({"response": f"Error: {str(e)}"}))
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from jupyter_server.utils import url_path_join
|
|
2
|
+
from .OpenAICompletionHandler import OpenAICompletionHandler
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
from _version import __version__
|
|
8
|
+
except ImportError:
|
|
9
|
+
# Fallback when using the package in dev mode without installing
|
|
10
|
+
# in editable mode with pip. It is highly recommended to install
|
|
11
|
+
# the package from a stable release or in editable mode: https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs
|
|
12
|
+
import warnings
|
|
13
|
+
warnings.warn("Importing 'mito-ai' outside a proper installation.")
|
|
14
|
+
__version__ = "dev"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
HERE = Path(__file__).parent.resolve()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
with (HERE / "labextension" / "package.json").open() as fid:
|
|
21
|
+
data = json.load(fid)
|
|
22
|
+
|
|
23
|
+
def _jupyter_labextension_paths():
|
|
24
|
+
return [{
|
|
25
|
+
"src": "labextension",
|
|
26
|
+
"dest": "mito-ai"
|
|
27
|
+
}]
|
|
28
|
+
|
|
29
|
+
def _jupyter_server_extension_points():
|
|
30
|
+
"""
|
|
31
|
+
Returns a list of dictionaries with metadata describing
|
|
32
|
+
where to find the `_load_jupyter_server_extension` function.
|
|
33
|
+
"""
|
|
34
|
+
return [{"module": "mito-ai"}]
|
|
35
|
+
|
|
36
|
+
# Jupyter Server is the backend used by JupyterLab. A sever extension lets
|
|
37
|
+
# us add new API's to the backend, so we can do some processing that we don't
|
|
38
|
+
# want to exist in the users's javascript.
|
|
39
|
+
|
|
40
|
+
# For a further explanation of the Jupyter architecture watch the first 35 minutes
|
|
41
|
+
# of this video: https://www.youtube.com/watch?v=9_-siU-_XoI
|
|
42
|
+
def _load_jupyter_server_extension(server_app):
|
|
43
|
+
host_pattern = ".*$"
|
|
44
|
+
web_app = server_app.web_app
|
|
45
|
+
base_url = web_app.settings["base_url"]
|
|
46
|
+
route_pattern = url_path_join(base_url, "mito_ai", "completion")
|
|
47
|
+
handlers = [(route_pattern, OpenAICompletionHandler)]
|
|
48
|
+
web_app.add_handlers(host_pattern, handlers)
|
|
49
|
+
web_app.log.info("Loaded the mito_ai server extension")
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# coding: utf-8
|
|
3
|
+
|
|
4
|
+
# Copyright (c) Saga Inc.
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
"""
|
|
10
|
+
This code is responsible for getting the package.json that is bundled
|
|
11
|
+
with the javascript code bundle inside this Python package, so we can
|
|
12
|
+
get the version of the package. This means we can easily bump the package
|
|
13
|
+
version in one place (package.json) and have it automatically update here too.
|
|
14
|
+
This is nice for the release process.
|
|
15
|
+
|
|
16
|
+
Since this is a Jupyter Lab 4 extension, themito-ai/labextension folder
|
|
17
|
+
contains the package.json directly. So we can just read it there.
|
|
18
|
+
"""
|
|
19
|
+
lab_extension_folder = os.path.join(Path(__file__).parent, 'labextension')
|
|
20
|
+
|
|
21
|
+
package_json_path = os.path.join(lab_extension_folder, 'package.json')
|
|
22
|
+
package_json = json.loads(open(package_json_path).read())
|
|
23
|
+
|
|
24
|
+
__version__ = package_json['version']
|
|
25
|
+
|