Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move magics to jupyter-ai-magics package #48

Merged
merged 6 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .jupyter-releaser.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ before-build-python = [
[options]
version-cmd = "../../scripts/bump-version.sh"
python_packages = [
"packages/jupyter-ai-magics:jupyter-ai-magics",
"packages/jupyter-ai:jupyter-ai",
"packages/jupyter-ai-dalle:jupyter-ai-dalle",
"packages/jupyter-ai-chatgpt:jupyter-ai-chatgpt"
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ hatch shell
Set up your development environment and start the server:

```
jlpm setup:dev # only needs to be run once
jlpm dev
dlqqq marked this conversation as resolved.
Show resolved Hide resolved
```

Expand Down
24 changes: 22 additions & 2 deletions docs/source/contributors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ hatch shell
Set up your development environment and start the server:

```
jlpm setup:dev # only needs to be run once
jlpm dev
```

Expand All @@ -64,6 +63,27 @@ To exit the hatch environment, on a blank command prompt, run `exit` or press `C

If installation fails for any reason, you will have to first uninstall the hatch environment and then test your fix by reinstalling.

To change what Jupyter AI packages are installed in your Hatch environment, use the `dev-uninstall` script:

```
# uninstalls all Jupyter AI packages
jlpm dev-uninstall
```

To reinstall Jupyter AI packages back into your Hatch environment, use the `dev-install` script:

```
# installs all Jupyter AI packages
jlpm dev-install
```

To only install/uninstall a subset of Jupyter AI packages, use the `--scope` argument that gets forwarded to Lerna:

```
# installs jupyter_ai_magics and its dependencies
jlpm dev-install --scope "@jupyter-ai/magics"
```

## Creating a new AI module

You can use the **Jupyter AI Module Cookiecutter** to create a new AI module easily. The AI module constructed from the template serves as a very simple example that can be extended however you wish.
Expand Down Expand Up @@ -101,7 +121,7 @@ or restart the server.
If you change the **server implementation** of an AI module, after rebuilding, restart the server.

If you make changes to the **user interface** or **lab extension**, run `jlpm build` and then
refresh your browser tab. Make sure to run `jlpm setup:dev` after starting a new Hatch shell.
refresh your browser tab.

## Development uninstall

Expand Down
3 changes: 2 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useWorkspaces": true,
"version": "0.4.0",
"npmClient": "yarn"
"npmClient": "yarn",
"useNx": true
}
9 changes: 6 additions & 3 deletions nx.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"targetDefaults": {
"setup:dev": {
"dependsOn": ["build"]
},
"build": {
"dependsOn": ["^build"]
},
"build:prod": {
"dependsOn": ["^build:prod"]
},
"dev-install": {
"dependsOn": ["^dev-install"]
},
"dev-uninstall": {
"dependsOn": ["clean:labextension"]
}
},
"tasksRunnerOptions": {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,22 @@
"packages/*"
],
"scripts": {
"setup:dev": "lerna run setup:dev --stream",
"build": "lerna run build --stream",
"build:core": "lerna run build --stream --scope \"@jupyter-ai/core\"",
"build:prod": "lerna run build:prod --stream",
"clean": "lerna run clean",
"clean:all": "lerna run clean:all",
"dev": "jupyter lab --config playground/config.py",
"dev-install": "lerna run dev-install --stream",
"dev-uninstall": "lerna run dev-uninstall --stream",
"lint": "jlpm && lerna run prettier && lerna run eslint",
"lint:check": "lerna run prettier:check && lerna run eslint:check",
"watch": "lerna run watch --parallel --stream"
},
"devDependencies": {
"@jupyterlab/builder": "^3.1.0",
"lerna": "^6.4.1"
"lerna": "^6.4.1",
"nx": "^15.9.2"
},
"nx": {
"includedScripts": []
Expand Down
5 changes: 3 additions & 2 deletions packages/jupyter-ai-chatgpt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@
"prettier": "jlpm prettier:base --write --list-different",
"prettier:base": "prettier \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
"prettier:check": "jlpm prettier:base --check",
"setup:dev": "jupyter labextension develop . --overwrite && jupyter server extension enable jupyter_ai_chatgpt",
"stylelint": "jlpm stylelint:check --fix",
"stylelint:check": "stylelint --cache \"style/**/*.css\"",
"test": "jest --coverage",
"watch": "run-p watch:src watch:labextension",
"watch:src": "tsc -w",
"watch:labextension": "jupyter labextension watch ."
"watch:labextension": "jupyter labextension watch .",
"dev-install": "pip install -e . && jupyter labextension develop . --overwrite && jupyter server extension enable jupyter_ai_chatgpt",
"dev-uninstall": "pip uninstall jupyter_ai_chatgpt -y"
},
"dependencies": {
"@jupyterlab/application": "^3.1.0"
Expand Down
5 changes: 3 additions & 2 deletions packages/jupyter-ai-dalle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@
"prettier": "jlpm prettier:base --write --list-different",
"prettier:base": "prettier \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
"prettier:check": "jlpm prettier:base --check",
"setup:dev": "jupyter labextension develop . --overwrite && jupyter server extension enable jupyter_ai_dalle",
"stylelint": "jlpm stylelint:check --fix",
"stylelint:check": "stylelint --cache \"style/**/*.css\"",
"test": "jest --coverage",
"watch": "run-p watch:src watch:labextension",
"watch:src": "tsc -w",
"watch:labextension": "jupyter labextension watch ."
"watch:labextension": "jupyter labextension watch .",
"dev-install": "pip install -e . && jupyter labextension develop . --overwrite && jupyter server extension enable jupyter_ai",
"dev-uninstall": "pip uninstall jupyter_ai_dalle -y"
},
"dependencies": {
"@jupyterlab/application": "^3.1.0"
Expand Down
122 changes: 122 additions & 0 deletions packages/jupyter-ai-magics/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
*.bundle.*
lib/
node_modules/
*.log
.eslintcache
.stylelintcache
*.egg-info/
.ipynb_checkpoints
*.tsbuildinfo
jupyter_ai_magics/labextension
# Version file is handled by hatchling
jupyter_ai_magics/_version.py

# Integration tests
ui-tests/test-results/
ui-tests/playwright-report/

# Created by https://www.gitignore.io/api/python
# Edit at https://www.gitignore.io/?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage/
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# End of https://www.gitignore.io/api/python

# OSX files
.DS_Store
29 changes: 29 additions & 0 deletions packages/jupyter-ai-magics/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2023, Project Jupyter
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.
4 changes: 4 additions & 0 deletions packages/jupyter-ai-magics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# @jupyter-ai/magics

This is a Python library `jupyter_ai_magics` that exposes the model providers
and defines the IPython magics.
18 changes: 18 additions & 0 deletions packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from ._version import __version__

from .magics import AiMagics

# expose model providers on the package root
from .providers import (
AI21Provider,
AnthropicProvider,
CohereProvider,
HfHubProvider,
OpenAIProvider,
ChatOpenAIProvider,
SmEndpointProvider
)
from .providers import BaseProvider

def load_ipython_extension(ipython):
ipython.register_magics(AiMagics)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from IPython.core.magic_arguments import magic_arguments, argument, parse_argstring
from IPython.display import HTML, Markdown, Math, JSON

from jupyter_ai.providers import BaseProvider
from .providers import BaseProvider


MODEL_ID_ALIASES = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Python unit tests for jupyter_ai_magics."""
24 changes: 24 additions & 0 deletions packages/jupyter-ai-magics/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@jupyter-ai/magics",
"version": "0.4.0",
"description": "Jupyter AI magics Python package. Not published on NPM.",
"private": true,
"homepage": "https://github.com/jupyterlab/jupyter-ai",
"bugs": {
"url": "https://github.com/jupyterlab/jupyter-ai/issues",
"email": "jupyter@googlegroups.com"
},
"license": "BSD-3-Clause",
"author": {
"name": "Project Jupyter",
"email": "jupyter@googlegroups.com"
},
"repository": {
"type": "git",
"url": "https://github.com/jupyterlab/jupyter-ai.git"
},
"scripts": {
"dev-install": "pip install -e \".[all]\"",
"dev-uninstall": "pip uninstall jupyter_ai_magics -y"
}
}
Loading