Skip to content

Commit 785b900

Browse files
authored
Use pre-commit (jupyterlab#237)
* add precommit config * add pre-commit to Python dev dependency groups * precommit initial pass * fix precommit
1 parent 1bc264e commit 785b900

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1140
-863
lines changed

.pre-commit-config.yaml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: end-of-file-fixer
6+
- id: check-case-conflict
7+
- id: check-executables-have-shebangs
8+
- id: requirements-txt-fixer
9+
- id: check-added-large-files
10+
- id: check-case-conflict
11+
- id: check-toml
12+
exclude: ^packages/jupyter-ai-module-cookiecutter
13+
- id: check-yaml
14+
exclude: ^packages/jupyter-ai-module-cookiecutter
15+
- id: debug-statements
16+
- id: forbid-new-submodules
17+
- id: check-builtin-literals
18+
- id: trailing-whitespace
19+
20+
- repo: https://github.com/psf/black
21+
rev: 23.3.0
22+
hooks:
23+
- id: black
24+
25+
- repo: https://github.com/PyCQA/isort
26+
rev: 5.12.0
27+
hooks:
28+
- id: isort
29+
args: ["--profile", "black"]
30+
files: \.py$
31+
32+
- repo: https://github.com/asottile/pyupgrade
33+
rev: v3.4.0
34+
hooks:
35+
- id: pyupgrade
36+
args: [--py37-plus]
37+
38+
- repo: https://github.com/pycqa/flake8
39+
rev: 6.0.0
40+
hooks:
41+
- id: flake8
42+
additional_dependencies:
43+
[
44+
"flake8-bugbear==20.1.4",
45+
"flake8-logging-format==0.6.0",
46+
"flake8-implicit-str-concat==0.2.0",
47+
]
48+
stages: [manual]
49+
50+
- repo: https://github.com/sirosen/check-jsonschema
51+
rev: 0.23.1
52+
hooks:
53+
- id: check-jsonschema
54+
name: "Check GitHub Workflows"
55+
files: ^\.github/workflows/
56+
types: [yaml]
57+
args: ["--schemafile", "https://json.schemastore.org/github-workflow"]
58+
stages: [manual]

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Jupyter AI
22

3-
Welcome to Jupyter AI, which brings generative AI to Jupyter. Jupyter AI provides a user-friendly
3+
Welcome to Jupyter AI, which brings generative AI to Jupyter. Jupyter AI provides a user-friendly
44
and powerful way to explore generative AI models in notebooks and improve your productivity
55
in JupyterLab and the Jupyter Notebook. More specifically, Jupyter AI offers:
66

@@ -41,7 +41,7 @@ First, install [conda](https://conda.io/projects/conda/en/latest/user-guide/inst
4141

4242
If you are using an Apple Silicon-based Mac (M1, M1 Pro, M2, etc.), you need to uninstall the `pip` provided version of `grpcio` and install the version provided by `conda` instead.
4343

44-
$ pip uninstall grpcio; conda install grpcio
44+
$ pip uninstall grpcio; conda install grpcio
4545

4646
If you are not using JupyterLab and you only want to install the Jupyter AI `%%ai` magic, skip the `pip install jupyter_ai` step above, and instead, run:
4747

@@ -59,7 +59,7 @@ Once you have installed the `%%ai` magic, you can enable it in any notebook or t
5959
or:
6060

6161
%load_ext jupyter_ai
62-
62+
6363
The screenshots below are from notebooks in the `examples/` directory of this package.
6464

6565
Then, you can use the `%%ai` magic command to specify a model and natural language prompt:

docs/source/_static/css/custom.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ img.screenshot {
22
/* Copied from div.admonition */
33
box-shadow: 0 .2rem .5rem var(--pst-color-shadow),0 0 .0625rem var(--pst-color-shadow);
44
border-color: var(--pst-color-info);
5-
}
5+
}

docs/source/conf.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@
66
# -- Project information -----------------------------------------------------
77
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
88

9-
project = 'Jupyter AI'
10-
copyright = '2023, Project Jupyter'
11-
author = 'Project Jupyter'
9+
project = "Jupyter AI"
10+
copyright = "2023, Project Jupyter"
11+
author = "Project Jupyter"
1212

1313
# -- General configuration ---------------------------------------------------
1414
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
1515

1616
extensions = ["myst_parser"]
1717
myst_enable_extensions = ["colon_fence"]
1818

19-
templates_path = ['_templates']
19+
templates_path = ["_templates"]
2020
exclude_patterns = []
2121

2222
# -- Options for HTML output -------------------------------------------------
2323
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
2424

2525
html_theme = "pydata_sphinx_theme"
26-
html_static_path = ['_static']
26+
html_static_path = ["_static"]
2727

2828
html_css_files = [
29-
'css/custom.css',
29+
"css/custom.css",
3030
]
3131

3232
# -- Jupyter theming -------------------------------------------------

docs/source/contributors/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Due to a compatibility issue with Webpack, Node.js 18.15.0 does not work with Ju
2121
:::
2222

2323
## Development install
24-
After you have installed the prerequisites, create a new conda environment and activate it.
24+
After you have installed the prerequisites, create a new conda environment and activate it.
2525

2626
```
2727
conda create -n jupyter-ai python=3.10

docs/source/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Jupyter AI
22

3-
Welcome to Jupyter AI, which brings generative AI to Jupyter. Jupyter AI provides a user-friendly
3+
Welcome to Jupyter AI, which brings generative AI to Jupyter. Jupyter AI provides a user-friendly
44
and powerful way to explore generative AI models in notebooks and improve your productivity
55
in JupyterLab and the Jupyter Notebook. More specifically, Jupyter AI offers:
66

@@ -19,4 +19,4 @@ maxdepth: 2
1919
2020
users/index
2121
contributors/index
22-
```
22+
```

docs/source/users/index.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Welcome to the user documentation for Jupyter AI.
44

5-
If you are interested in contributing to Jupyter AI,
5+
If you are interested in contributing to Jupyter AI,
66
please see our {doc}`contributor's guide </contributors/index>`.
77

88
## Prerequisites
@@ -101,7 +101,7 @@ First, install [conda](https://conda.io/projects/conda/en/latest/user-guide/inst
101101

102102
If you are using an Apple Silicon-based Mac (M1, M1 Pro, M2, etc.), you need to uninstall the `pip` provided version of `grpcio` and install the version provided by `conda` instead.
103103

104-
$ pip uninstall grpcio; conda install grpcio
104+
$ pip uninstall grpcio; conda install grpcio
105105

106106
If you are not using JupyterLab and you only want to install the Jupyter AI `%%ai` magic, you can run:
107107

@@ -127,7 +127,7 @@ or
127127

128128
## The chat interface
129129

130-
The easiest way to get started with Jupyter AI is to use the chat interface.
130+
The easiest way to get started with Jupyter AI is to use the chat interface.
131131

132132
:::{attention}
133133
:name: open-ai-privacy-cost
@@ -449,7 +449,7 @@ will look like properly typeset equations.
449449
Generate the 2D heat equation in LaTeX surrounded by `$$`. Do not include an explanation.
450450
```
451451

452-
This prompt will produce output as a code cell below the input cell.
452+
This prompt will produce output as a code cell below the input cell.
453453

454454
:::{warning}
455455
:name: run-code
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
from ._version import __version__
2+
3+
# expose embedding model providers on the package root
4+
from .embedding_providers import (
5+
CohereEmbeddingsProvider,
6+
HfHubEmbeddingsProvider,
7+
OpenAIEmbeddingsProvider,
8+
)
29
from .exception import store_exception
310
from .magics import AiMagics
411

512
# expose model providers on the package root
613
from .providers import (
714
AI21Provider,
815
AnthropicProvider,
16+
BaseProvider,
17+
ChatOpenAINewProvider,
18+
ChatOpenAIProvider,
919
CohereProvider,
1020
HfHubProvider,
1121
OpenAIProvider,
12-
ChatOpenAIProvider,
13-
ChatOpenAINewProvider,
14-
SmEndpointProvider
15-
)
16-
# expose embedding model providers on the package root
17-
from .embedding_providers import (
18-
OpenAIEmbeddingsProvider,
19-
CohereEmbeddingsProvider,
20-
HfHubEmbeddingsProvider
22+
SmEndpointProvider,
2123
)
22-
from .providers import BaseProvider
24+
2325

2426
def load_ipython_extension(ipython):
2527
ipython.register_magics(AiMagics)
2628
ipython.set_custom_exc((BaseException,), store_exception)
2729

30+
2831
def unload_ipython_extension(ipython):
2932
ipython.set_custom_exc((BaseException,), ipython.CustomTB)

packages/jupyter-ai-magics/jupyter_ai_magics/aliases.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"gpt3": "openai:text-davinci-003",
44
"chatgpt": "openai-chat:gpt-3.5-turbo",
55
"gpt4": "openai-chat:gpt-4",
6-
}
6+
}

packages/jupyter-ai-magics/jupyter_ai_magics/embedding_providers.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
from typing import ClassVar, List, Type
2+
23
from jupyter_ai_magics.providers import AuthStrategy, EnvAuthStrategy, Field
3-
from pydantic import BaseModel, Extra
4-
from langchain.embeddings import OpenAIEmbeddings, CohereEmbeddings, HuggingFaceHubEmbeddings
4+
from langchain.embeddings import (
5+
CohereEmbeddings,
6+
HuggingFaceHubEmbeddings,
7+
OpenAIEmbeddings,
8+
)
59
from langchain.embeddings.base import Embeddings
10+
from pydantic import BaseModel, Extra
611

712

813
class BaseEmbeddingsProvider(BaseModel):
@@ -33,22 +38,20 @@ class Config:
3338

3439
model_id: str
3540

36-
provider_klass: ClassVar[Type[Embeddings]]
41+
provider_klass: ClassVar[Type[Embeddings]]
3742

3843
registry: ClassVar[bool] = False
3944
"""Whether this provider is a registry provider."""
4045

4146
fields: ClassVar[List[Field]] = []
4247
"""Fields expected by this provider in its constructor. Each `Field` `f`
4348
should be passed as a keyword argument, keyed by `f.key`."""
44-
49+
4550

4651
class OpenAIEmbeddingsProvider(BaseEmbeddingsProvider):
4752
id = "openai"
4853
name = "OpenAI"
49-
models = [
50-
"text-embedding-ada-002"
51-
]
54+
models = ["text-embedding-ada-002"]
5255
model_id_key = "model"
5356
pypi_package_deps = ["openai"]
5457
auth_strategy = EnvAuthStrategy(name="OPENAI_API_KEY")
@@ -58,11 +61,7 @@ class OpenAIEmbeddingsProvider(BaseEmbeddingsProvider):
5861
class CohereEmbeddingsProvider(BaseEmbeddingsProvider):
5962
id = "cohere"
6063
name = "Cohere"
61-
models = [
62-
'large',
63-
'multilingual-22-12',
64-
'small'
65-
]
64+
models = ["large", "multilingual-22-12", "small"]
6665
model_id_key = "model"
6766
pypi_package_deps = ["cohere"]
6867
auth_strategy = EnvAuthStrategy(name="COHERE_API_KEY")

packages/jupyter-ai-magics/jupyter_ai_magics/exception.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
from IPython.core.magic import register_line_magic
1+
import traceback
2+
23
from IPython.core.getipython import get_ipython
4+
from IPython.core.magic import register_line_magic
35
from IPython.core.ultratb import ListTB
46

5-
import traceback
67

78
def store_exception(shell, etype, evalue, tb, tb_offset=None):
89
# A structured traceback (a list of strings) or None
9-
10+
1011
if issubclass(etype, SyntaxError):
1112
# Disable ANSI color strings
1213
shell.SyntaxTB.color_toggle()
@@ -18,7 +19,9 @@ def store_exception(shell, etype, evalue, tb, tb_offset=None):
1819
else:
1920
# Disable ANSI color strings
2021
shell.InteractiveTB.color_toggle()
21-
stb = shell.InteractiveTB.structured_traceback(etype, evalue, tb, tb_offset=tb_offset)
22+
stb = shell.InteractiveTB.structured_traceback(
23+
etype, evalue, tb, tb_offset=tb_offset
24+
)
2225
stb_text = shell.InteractiveTB.stb2text(stb)
2326
# Re-enable ANSI color strings
2427
shell.InteractiveTB.color_toggle()
@@ -31,6 +34,6 @@ def store_exception(shell, etype, evalue, tb, tb_offset=None):
3134
err = shell.user_ns.get("Err", {})
3235
err[prompt_number] = styled_exception
3336
shell.user_ns["Err"] = err
34-
35-
# Return
37+
38+
# Return
3639
return etraceback

0 commit comments

Comments
 (0)