logo
0
0
WeChat Login
feat: 添加流式生成功能到 CodeBuddy 聊天模型

Jupyter AI CodeBuddy Provider

将 CodeBuddy AI 集成到 Jupyter AI 的 provider 插件。

环境要求

  • Python 3.10 - 3.12(推荐 3.12,Python 3.14 存在兼容性问题)
  • JupyterLab >= 4.0
  • jupyter-ai >= 2.0.0

全新环境安装

1. 创建虚拟环境(推荐)

# 使用 conda(推荐) conda create -n jupyter-ai python=3.12 conda activate jupyter-ai # 或使用 venv python3.12 -m venv venv source venv/bin/activate # Linux/macOS # venv\Scripts\activate # Windows

2. 安装 JupyterLab 和 jupyter-ai

pip install jupyterlab jupyter-ai

3. 安装 CodeBuddy Provider

cd jupyter-ai-codebuddy pip install -e .

4. 验证安装

# 检查扩展是否正确加载 jupyter server extension list # 应该看到以下输出: # jupyter_ai enabled # - Validating jupyter_ai... # jupyter_ai x.x.x OK

5. 启动 JupyterLab

jupyter lab

常见问题

问题:/api/ai/chats 返回 404

原因jupyter-ai 扩展未安装或安装在不同的 Python 环境中。

解决方法

  1. 确认当前使用的 Python 环境:

    which python which jupyter
  2. 确保 jupyter-ai 安装在运行 jupyter lab 的同一环境中:

    # 查看 jupyter lab 使用的 Python jupyter --path # 在对应环境安装 pip install jupyter-ai

问题:Python 3.14 兼容性警告

如果看到 Pydantic V1 functionality isn't compatible with Python 3.14 警告,建议使用 Python 3.12 环境。

问题:Homebrew 安装的 JupyterLab

如果通过 Homebrew 安装了 JupyterLab,需要在其对应的 Python 环境中安装扩展:

# 查找 Homebrew JupyterLab 的 Python /opt/homebrew/Cellar/jupyterlab/*/libexec/bin/python -m pip install jupyter-ai /opt/homebrew/Cellar/jupyterlab/*/libexec/bin/python -m pip install -e .

使用方式

聊天界面

  1. 启动 JupyterLab:jupyter lab
  2. 打开左侧 Jupyternaut 聊天面板
  3. 在设置中选择 CodeBuddy 作为模型提供商
  4. 选择具体模型(如 glm-4.7)

Magic 命令

%load_ext jupyter_ai_magics %%ai codebuddy:glm-4.7 请解释 Python 的装饰器是什么

支持的模型

模型名称模型 ID
GLM-4.7glm-4.7
GLM-4.6glm-4.6
DeepSeek-V3.2deepseek-v3-2-volc
DeepSeek-V3.1deepseek-v3.1
DeepSeek-V3deepseek-v3-0324

配置

Provider 默认使用 CodeBuddy CLI 的登录认证,无需额外配置 API Key。

如需自定义,可设置环境变量:

export CODEBUDDY_API_KEY="your-api-key" export CODEBUDDY_BASE_URL="custom-base-url"

开发

# 克隆项目 git clone <repo-url> cd jupyter-ai-codebuddy # 安装开发依赖 pip install -e ".[dev]" # 修改代码后需重启 JupyterLab jupyter lab

License

MIT

About

CodeBuddy-JupyterLab-Provider

Language
Python100%