Skip to main content

调用LLM实现Jupyter代码的自动生成、执行、调试等功能

Project description

jupyter-agent

调用LLM实现Jupyter代码的自动生成、执行、调试等功能

特性

  • 提供%%bot指令,在juyter环境中,通过调用LLM实现代码生成、执行、调试等能力
  • 支持调用OpenAI兼容API,实现LLM相关的功能

安装

# 激活目标环境(视情况选择)
source /path/to/target_env/bin/activate

pip install jupyter-agent

源码打包安全(Build)

# 下载代码
git clone https://github.com/yourusername/jupyter-agent.git
cd jupyter-agent

# 安装打包环境
virtualenv .venv
source .venv/bin/activate
pip install build

# 编译打包
python -m build

# 退出打包环境
deactivate

# 激活目标环境
source /path/to/target_env/bin/activate

# 安装编译好的wheel包
pip install /path/to/upyter-agent/dist/jupyter_agent-xxxx-py3-none-any.whl

使用方法

安装完成后,启动Jupyter环境(兼容Vscode的Notebook编译器)

全局配置

# 加载扩展的Magic命令
%load_ext jupyter_agent.bot_magics
# 设备模型调用的API地址,不同的Agent可以调用不同的模型,这里以调用lmstudio本地部署的模型为例
%config BotMagics.default_api_url = 'http://127.0.0.1:1234/v1'
%config BotMagics.default_api_key = 'API_KEY'
%config BotMagics.default_model_name = 'qwen3-30b-a3b' 
%config BotMagics.coding_model_name = 'devstral-small-2505-mlx'
# 设置当前Notebook的路径,由于vscode中运行里无法自动获取到该路径,需要手工指定
%config BotMagics.notebook_path = globals()["__vsc_ipynb_file__"]

全局任务规划

%%bot -P

# 全局目标
...

全局任务规划会解析用户输入的prompt,生成具体的执行计划,后续的%%bot指令会以该计划为蓝本自动生成每个步骤(子任务)的代码。

alt text alt text

生成并执行子任务代码

%% bot [-s stage]

# generated code ...

在完成全局任务规划后,开始执行子任务时,只需要新建一个cell,输入并执行%%bot命令,如下图:

alt text

注:由于cell magic命令无法直接定位当前cell,需要通过cell的内容进行匹配,因此首次执行%%bot命令时,需要在cell中额外添加一些随机字符

接下来工具会调用相应的agent自动生成并执行相应步骤的代码,如下图:

alt text

一个cell中只会执行全局计划中的一个步骤,当前步骤执行完成后,需要手工新建一个cell并重复上述过程,直到完成全局目标完成(此时工具不会再生成新代码)

在子任务执行的过程中,默认情况下每一个环节工具都会给出如下图的确认提示,可跟据实际情况输入相应的选项,或直接回车确认继续执行下一环节。

alt text

更详细用法可参考示例Notebook

贡献

欢迎提交 issue 或 pull request 参与贡献。

许可证

本项目基于 MIT License 开源。

Copyright (c) 2025 viewstar000

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyter_agent-2025.6.101.tar.gz (37.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jupyter_agent-2025.6.101-py3-none-any.whl (51.5 kB view details)

Uploaded Python 3

File details

Details for the file jupyter_agent-2025.6.101.tar.gz.

File metadata

  • Download URL: jupyter_agent-2025.6.101.tar.gz
  • Upload date:
  • Size: 37.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for jupyter_agent-2025.6.101.tar.gz
Algorithm Hash digest
SHA256 c3ce7fb92d2ae4d6920473419a7b7981fb7978043ac4dbfa7768ce07fdbe3784
MD5 5c56dbb6e56dc1fe536b9914530f2d3d
BLAKE2b-256 6d546fa7ac4e51edb04d96f67645d8f0f7907a4276e6ca13e7f5bb40d9eedd4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for jupyter_agent-2025.6.101.tar.gz:

Publisher: python-publish.yml on viewstar000/jupyter-agent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jupyter_agent-2025.6.101-py3-none-any.whl.

File metadata

File hashes

Hashes for jupyter_agent-2025.6.101-py3-none-any.whl
Algorithm Hash digest
SHA256 8c692dfc40d46122ed157136383e39938faa51d122a8b8335dd891f86514fe91
MD5 9a37afd23010b92adefe71215f0fdbc8
BLAKE2b-256 2be54dceaa4a51a464881f19e12793ee47e53d9f867f3ffd2aa267c22f2e1970

See more details on using hashes here.

Provenance

The following attestation bundles were made for jupyter_agent-2025.6.101-py3-none-any.whl:

Publisher: python-publish.yml on viewstar000/jupyter-agent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page