Skip to content

Commit

Permalink
import AI module cookiecutter (jupyterlab#13)
Browse files Browse the repository at this point in the history
* import Jupyter AI module cookiecutter

* rename all remaining occurrences of GAI => AI

* declare email in all packages and cookiecutter

* fix VSCode ESLint extension

* export InsertionContext type, add devDep on @jupyter-ai/core

* update cookiecutter readme to delete extra files manually

* configure skipLibCheck: true

* update cookiecutter readme
  • Loading branch information
dlqqq authored Mar 7, 2023
1 parent d11ae10 commit 174d202
Show file tree
Hide file tree
Showing 52 changed files with 1,555 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
/packages/jupyter-ai-dalle/LICENSE filter=lfs diff=lfs merge=lfs -text
/LICENSE filter=lfs diff=lfs merge=lfs -text
*.sh filter=lfs diff=lfs merge=lfs -text
/packages/jupyter-ai-module-cookiecutter/LICENSE filter=lfs diff=lfs merge=lfs -text
/packages/jupyter-ai-module-cookiecutter/{{cookiecutter.labextension_name}}/LICENSE filter=lfs diff=lfs merge=lfs -text
/packages/jupyter-ai-module-cookiecutter/{{cookiecutter.labextension_name}}/binder/postBuild filter=lfs diff=lfs merge=lfs -text
* !text !filter !merge !diff
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
{
"name": "@jupyter-ai/monorepo",
"version": "0.1.1",
"description": "A generative AI extension for JupyterLab",
"private": true,
"keywords": [
"jupyter",
"jupyterlab",
"jupyterlab-extension"
],
"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"
},
"workspaces": [
".",
"packages/*"
Expand Down
8 changes: 5 additions & 3 deletions packages/jupyter-ai-dalle/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ module.exports = {
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module'
project: './tsconfig.json'
},
plugins: ['@typescript-eslint'],
rules: {
Expand All @@ -24,7 +23,7 @@ module.exports = {
}
],
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/quotes': [
Expand All @@ -35,5 +34,8 @@ module.exports = {
curly: ['error', 'all'],
eqeqeq: 'error',
'prefer-arrow-callback': 'error'
},
overrides: {
files: ['./src/**/*']
}
};
4 changes: 2 additions & 2 deletions packages/jupyter-ai-dalle/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# jupyter_ai_dalle

This extension is composed of a Python package named `jupyter_ai_dalle`
that exposes the model engines to the Jupyter GAI server extension,
that exposes the model engines to the Jupyter AI server extension,
and an NPM package named `jupyter_ai_dalle`
that provides a frontend labextension registering inserters.

Expand Down Expand Up @@ -84,7 +84,7 @@ folder is located. Then you can remove the symlink named `jupyter_ai_dalle` with

#### Backend tests

This GAI module is using [Pytest](https://docs.pytest.org/) for Python code testing.
This AI module is using [Pytest](https://docs.pytest.org/) for Python code testing.

Install test dependencies (needed only once):

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 @@ -9,12 +9,13 @@
],
"homepage": "https://github.com/jupyterlab/jupyter-ai",
"bugs": {
"url": "https://github.com/jupyterlab/jupyter-ai/issues"
"url": "https://github.com/jupyterlab/jupyter-ai/issues",
"email": "jupyter@googlegroups.com"
},
"license": "BSD-3-Clause",
"author": {
"name": "Project Jupyter",
"email": "me@test.com"
"email": "jupyter@googlegroups.com"
},
"files": [
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
Expand Down
10 changes: 4 additions & 6 deletions packages/jupyter-ai-dalle/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { Notebook, NotebookActions } from '@jupyterlab/notebook';
import { Widget } from '@lumino/widgets';
import type { InsertionContext } from '@jupyter-ai/core';

/**
* Initialization data for the jupyter_ai_dalle extension.
Expand All @@ -16,10 +16,8 @@ const plugin: JupyterFrontEndPlugin<void> = {

// handle below-in-image insertion mode for notebooks
app.commands.addCommand('ai:insert-below-in-image', {
// context has type InsertionContext, but cannot be typed as the frontend
// package is not yet published to NPM
execute: (context: any) => {
const notebook = context.widget as Widget;
execute: ((context: InsertionContext) => {
const notebook = context.widget;
if (!(notebook instanceof Notebook)) {
console.error('Editor widget is not of type "Notebook".');
return false;
Expand All @@ -31,7 +29,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
.get(notebook.activeCellIndex)
?.sharedModel.setSource(`![](${context.response.output})`);
NotebookActions.run(notebook);
}
}) as any
});
}
};
Expand Down
120 changes: 120 additions & 0 deletions packages/jupyter-ai-module-cookiecutter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
*.bundle.*
lib/
node_modules/
*.egg-info/
.ipynb_checkpoints
*.tsbuildinfo
.eslintcache
.stylelintcache
{{cookiecutter.python_name}}/static

# 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.xml
*.cover
.hypothesis/
.pytest_cache/
coverage/lcov-report/
coverage/lcov.info

# 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

# Default extension dir
myextension
.vscode/
29 changes: 29 additions & 0 deletions packages/jupyter-ai-module-cookiecutter/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2017-2021, Project Jupyter Contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* 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.

* 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.
38 changes: 38 additions & 0 deletions packages/jupyter-ai-module-cookiecutter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Jupyter AI Module Cookiecutter

A [cookiecutter](https://github.com/audreyr/cookiecutter) template for creating
a AI module. The AI module constructed from the template serves as a very simple
example that can be extended however you wish.

## Usage

Install cookiecutter.

```
pip install cookiecutter
```

Then from the project root, run these commands:

```
cd packages/
cookiecutter jupyter-ai-module-cookiecutter
```

Follow the prompts to create a new AI module under `packages/`. Your
labextension name should use hyphens, whereas your Python name should use
underscores.

# Usage (monorepo integration)

To integrate the new AI module into this monorepo, execute this command
manually from the AI module root:

```
rm -r .github/ binder/ CHANGELOG.md RELEASE.md
```

Rename the JS package to be scoped under `@jupyter-ai/`.

Finally, add the Python package to the `options.python_packages` field in
`.jupyter-releaser.toml`.
12 changes: 12 additions & 0 deletions packages/jupyter-ai-module-cookiecutter/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"author_name": "Project Jupyter",
"author_email": "jupyter@googlegroups.com",
"version": "0.1.0",
"labextension_name": "myextension",
"python_name": "{{ cookiecutter.labextension_name | replace('-', '_') }}",
"project_short_description": "A JupyterLab extension.",
"has_settings": "n",
"has_binder": "n",
"test": "y",
"repository": "https://github.com/jupyterlab/jupyter-ai"
}
39 changes: 39 additions & 0 deletions packages/jupyter-ai-module-cookiecutter/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python
from pathlib import Path

PROJECT_DIRECTORY = Path.cwd()


def remove_path(path: Path) -> None:
"""Remove the provided path.
If the target path is a directory, remove it recursively.
"""
if not path.exists():
return

if path.is_file():
path.unlink()
elif path.is_dir():
for f in path.iterdir():
remove_path(f)
path.rmdir()


if __name__ == "__main__":

if not "{{ cookiecutter.has_settings }}".lower().startswith("y"):
remove_path(PROJECT_DIRECTORY / "schema")

if not "{{ cookiecutter.has_binder }}".lower().startswith("y"):
remove_path(PROJECT_DIRECTORY / "binder")
remove_path(PROJECT_DIRECTORY / ".github/workflows/binder-on-pr.yml")

if not "{{ cookiecutter.test }}".lower().startswith("y"):
remove_path(PROJECT_DIRECTORY / ".github" / "workflows" / "update-integration-tests.yml")
remove_path(PROJECT_DIRECTORY / "src" / "__tests__")
remove_path(PROJECT_DIRECTORY / "ui-tests")
remove_path(PROJECT_DIRECTORY / "{{ cookiecutter.python_name }}" / "tests")
remove_path(PROJECT_DIRECTORY / "babel.config.js")
remove_path(PROJECT_DIRECTORY / "conftest.py")
remove_path(PROJECT_DIRECTORY / "jest.config.js")
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
dist
coverage
**/*.d.ts
tests

**/__tests__
ui-tests
Loading

0 comments on commit 174d202

Please sign in to comment.