JupyterLab的生成式AI扩展
项目描述
jupyter_ai
此扩展由名为 jupyter_ai
的服务器扩展Python包和名为 jupyter_ai
的前端扩展NPM包组成。
需求
- JupyterLab >= 4.0.0
- Jupyter Server >= 2.0.0
安装
您可以使用 conda
或 pip
安装Jupyter AI。如果您在使用基于Apple Silicon的Mac(M1、M1 Pro、M2等)上的macOS,我们强烈建议使用 conda
。
在您可以使用Jupyter AI之前,您需要安装任何包并设置使用API密钥的模型提供者的环境变量。有关所需内容的详细信息,请参阅 我们的文档。
使用pip
$ pip install jupyter_ai
使用conda
首先,安装conda并创建一个使用Python 3.12的环境
$ conda create -n jupyter-ai python=3.12
$ conda activate jupyter-ai
$ pip install jupyter_ai
卸载
要删除扩展,执行
$ pip uninstall jupyter_ai
故障排除
如果您可以看到扩展用户界面,但它不工作,请检查服务器扩展是否已启用
jupyter server extension list
如果服务器扩展已安装并启用,但您看不到扩展用户界面,请验证前端扩展是否已安装
jupyter labextension list
贡献
开发安装
注意:您需要NodeJS来构建扩展包。
jlpm
命令是JupyterLab安装的yarn的固定版本。您可以使用下面的yarn
或npm
代替jlpm
。
# Clone the repo to your local environment
# Change directory to the jupyter_ai directory
# Install package in development mode
pip install -e .
# 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 jupyter_ai
# Rebuild extension Typescript source after making changes
jlpm build
您可以在不同的终端中同时监视源目录并运行JupyterLab,以监视扩展源中的更改并自动重新构建扩展。
# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm watch
# Run JupyterLab in another terminal
jupyter lab
在监视命令运行时,每次保存的更改都将立即在本地构建并可在您运行的JupyterLab中使用。刷新JupyterLab以在浏览器中加载更改(您可能需要等待几秒钟,以便重新构建扩展)。
默认情况下,jlpm build
命令为此扩展生成源映射,以便使用浏览器开发工具进行调试。要同时为JupyterLab核心扩展生成源映射,您可以运行以下命令
jupyter lab build --minimize=False
开发卸载
# Server extension must be manually disabled in develop mode
jupyter server extension disable jupyter_ai
pip uninstall jupyter_ai
在开发模式下,您还需要删除由jupyter labextension develop
命令创建的符号链接。要找到其位置,您可以运行jupyter labextension list
以确定labextensions
文件夹的位置。然后您可以删除该文件夹中名为jupyter_ai
的符号链接。
测试扩展
服务器测试
此扩展使用Pytest进行Python代码测试。
安装测试依赖项(仅需安装一次)
pip install -e ".[test]"
要执行它们,请运行
pytest -vv -r ap --cov jupyter_ai
集成测试
此扩展使用Playwright进行集成测试(也称为用户级测试)。更确切地说,JupyterLab辅助工具Galata用于处理在JupyterLab中测试扩展。
更多详细信息请参阅ui-tests的README。
打包扩展
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。