jupyter-agent 2025.6.101__py3-none-any.whl → 2025.6.103__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,10 +61,33 @@ class BotMagics(Magics, Configurable):
61
61
 
62
62
  return options
63
63
 
64
+ def ensure_notebook_path(self):
65
+ if self.notebook_path:
66
+ return self.notebook_path
67
+ result = self.shell and self.shell.run_cell("globals().get('__vsc_ipynb_file__')")
68
+ if result and result.success and result.result:
69
+ self.notebook_path = result.result
70
+ return self.notebook_path
71
+ try:
72
+ self.notebook_path = str(ipynbname.path())
73
+ return self.notebook_path
74
+ except Exception as e:
75
+ _F(f"Failed to get notebook path: {e}")
76
+ return None
77
+
64
78
  @cell_magic
65
79
  def bot(self, line, cell):
66
80
  """Jupyter cell magic: %%bot"""
67
81
  try:
82
+ if not self.ensure_notebook_path():
83
+ _O(
84
+ Markdown(
85
+ "The notebook path is **empty**, we can't do anything.\n\n"
86
+ "Please set the notebook path in the configuration, and **RERUN** the cell again.\n\n"
87
+ 'For example: `%config BotMagics.notebook_path = globals()["__vsc_ipynb_file__"]`'
88
+ )
89
+ )
90
+ return
68
91
  AgentCellContext.SUPPORT_SAVE_META = self.support_save_meta
69
92
  reset_output(stage="Logging", logging_level=self.logging_level)
70
93
  _I("Cell magic %%bot executing ...")
@@ -85,8 +108,6 @@ class BotMagics(Magics, Configurable):
85
108
  options = self.parse_args(line)
86
109
  _D(f"Cell magic called with options: {options}")
87
110
  set_logging_level(options.logging_level)
88
- self.notebook_path = self.notebook_path or ipynbname.path()
89
- _D(f"Cell magic called with notebook path: {self.notebook_path}")
90
111
  nb_context = NotebookContext(line, cell, notebook_path=self.notebook_path)
91
112
  agent_factory = AgentFactory(
92
113
  nb_context,
@@ -0,0 +1,300 @@
1
+ Metadata-Version: 2.4
2
+ Name: jupyter-agent
3
+ Version: 2025.6.103
4
+ Summary: 调用LLM实现Jupyter代码的自动生成、执行、调试等功能
5
+ Author: viewstar000
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/viewstar000/jupyter-agent
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.12
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: ipython
14
+ Requires-Dist: nbformat
15
+ Requires-Dist: ipynbname
16
+ Requires-Dist: openai
17
+ Requires-Dist: traitlets
18
+ Requires-Dist: pyyaml
19
+ Requires-Dist: jinja2
20
+ Requires-Dist: pydantic
21
+ Dynamic: license-file
22
+
23
+ # jupyter-agent
24
+
25
+ [EN](#en)
26
+
27
+ 调用LLM实现Jupyter代码的自动生成、执行、调试等功能
28
+
29
+ ## 特性
30
+
31
+ - 提供`%%bot`指令,在juyter环境中,通过调用LLM实现代码生成、执行、调试等能力
32
+ - 支持调用OpenAI兼容API,实现LLM相关的功能
33
+
34
+ ## 安装
35
+
36
+ ```bash
37
+ # 激活目标环境(视情况选择)
38
+ source /path/to/target_env/bin/activate
39
+
40
+ pip install jupyter-agent
41
+ ```
42
+
43
+ ## 源码打包安全(Build)
44
+
45
+ ```bash
46
+ # 下载代码
47
+ git clone https://github.com/yourusername/jupyter-agent.git
48
+ cd jupyter-agent
49
+
50
+ # 安装打包环境
51
+ virtualenv .venv
52
+ source .venv/bin/activate
53
+ pip install build
54
+
55
+ # 编译打包
56
+ python -m build
57
+
58
+ # 退出打包环境
59
+ deactivate
60
+
61
+ # 激活目标环境
62
+ source /path/to/target_env/bin/activate
63
+
64
+ # 安装编译好的wheel包
65
+ pip install /path/to/jupyter-agent/dist/jupyter_agent-xxxx-py3-none-any.whl
66
+ ```
67
+
68
+ ## 安装Vscode插件(可选)
69
+
70
+ 下载地址:[jupyter-agent-extension](https://marketplace.visualstudio.com/items?itemName=viewstar000.jupyter-agent-extension)
71
+
72
+ ## 使用方法
73
+
74
+ 安装完成后,启动Jupyter环境(兼容Vscode的Notebook编译器)
75
+
76
+ ### 全局配置
77
+
78
+ 基础配置
79
+
80
+ ```python
81
+ # 加载扩展的Magic命令
82
+ %load_ext jupyter_agent.bot_magics
83
+
84
+ # 设置模型调用的API地址,不同的Agent可以调用不同的模型,这里以调用lmstudio本地部署的模型为例
85
+ %config BotMagics.default_api_url = 'http://127.0.0.1:1234/v1'
86
+ %config BotMagics.default_api_key = 'API_KEY'
87
+ %config BotMagics.default_model_name = 'qwen3-30b-a3b'
88
+ %config BotMagics.coding_model_name = 'devstral-small-2505-mlx'
89
+ ```
90
+
91
+ 扩展配置
92
+
93
+ ```python
94
+ # 设置当前Notebook的路径,当无法自动获取时需要手工指定,以Vscode中的Notebook为例
95
+ %config BotMagics.notebook_path = globals()["__vsc_ipynb_file__"]
96
+
97
+ # 设置是否保存任务数据到Metadata,只有Vscode中安装了jupyter-agent-extension后才支持
98
+ %config BotMagics.support_save_meta = True
99
+
100
+ # 设置日志级别,可选值为DEBUG、INFO、WARN、ERROR、FATAL,默认为INFO
101
+ %config BotMagics.logging_level = 'DEBUG'
102
+
103
+ # 设置是否显示思考过程,默认为True
104
+ %config BotMagics.display_think = True
105
+
106
+ # 设置是否显示发送给出LLM的消息和LLM的回答,默认为False
107
+ %config BotMagics.display_message = True
108
+ %config BotMagics.display_response = True
109
+ ```
110
+
111
+ ### 全局任务规划
112
+
113
+ ```python
114
+ %%bot -P
115
+
116
+ # 全局目标
117
+ ...
118
+ ```
119
+
120
+ 全局任务规划会解析用户输入的prompt,生成具体的执行计划,后续的%%bot指令会以该计划为蓝本自动生成每个步骤(子任务)的代码。
121
+
122
+ ![docs/image-global-prompt.png](https://raw.githubusercontent.com/viewstar000/jupyter-agent/refs/heads/main/docs/image-global-prompt.png)
123
+ ![docs/image-global-plan.png](https://raw.githubusercontent.com/viewstar000/jupyter-agent/refs/heads/main/docs/image-global-plan.png)
124
+
125
+ ### 生成并执行子任务代码
126
+
127
+ ```python
128
+ %% bot [-s stage]
129
+
130
+ # generated code ...
131
+ ```
132
+
133
+ 在完成全局任务规划后,开始执行子任务时,只需要新建一个cell,输入并执行`%%bot`命令,如下图:
134
+
135
+ ![docs/image-task-empty.png](https://raw.githubusercontent.com/viewstar000/jupyter-agent/refs/heads/main/docs/image-task-empty.png)
136
+
137
+ > **注:**由于cell magic命令无法直接定位当前cell,需要通过cell的内容进行匹配,因此首次执行%%bot命令时,需要在cell中额外添加一些随机字符
138
+
139
+ 接下来工具会调用相应的agent自动生成并执行相应步骤的代码,如下图:
140
+
141
+ ![docs/image-task-executing.png](https://raw.githubusercontent.com/viewstar000/jupyter-agent/refs/heads/main/docs/image-task-executing.png)
142
+
143
+ 一个cell中只会执行全局计划中的一个步骤,当前步骤执行完成后,需要手工新建一个cell并重复上述过程,直到完成全局目标完成(此时工具不会再生成新代码)
144
+
145
+ 在子任务执行的过程中,默认情况下每一个环节工具都会给出如下图的确认提示,可跟据实际情况输入相应的选项,或直接回车确认继续执行下一环节。
146
+
147
+ ![docs/image-task-confirm.png](https://raw.githubusercontent.com/viewstar000/jupyter-agent/refs/heads/main/docs/image-task-confirm.png)
148
+
149
+ > **注:**在执行`%%bot`命令前,必须确保当前Notebook已保存,否则Agent无法读取到完整的Notebook上下文。建议开启Notebook编辑器自动保存功能。
150
+
151
+ 更详细用法可参考[示例Notebook](https://github.com/viewstar000/jupyter-agent/blob/main/examples/data_loader.ipynb)
152
+
153
+ ## 贡献
154
+
155
+ 欢迎提交 issue 或 pull request 参与贡献。
156
+
157
+ ## 许可证
158
+
159
+ 本项目基于 [MIT License](./LICENSE) 开源。
160
+
161
+ Copyright (c) 2025 viewstar000
162
+
163
+ ---
164
+
165
+ ## EN
166
+
167
+ Implementing jupyter code planning, generation and execution for tasks using LLMs.
168
+
169
+ ## Features
170
+
171
+ - Support `%%bot` magic command, you can use it to work on task planning, code generation, execution and debugging.
172
+ - Support OpenAI Compatible API to call LLMs.
173
+
174
+ ## Installation
175
+
176
+ ```bash
177
+ # Activate the virtual environment
178
+ source /path/to/target_env/bin/activate
179
+
180
+ pip install jupyter-agent
181
+ ```
182
+
183
+ ## Build from Source
184
+
185
+ ```bash
186
+ # Clone the repository
187
+ git clone https://github.com/viewstar000/jupyter-agent.git
188
+ cd jupyter-agent
189
+
190
+ # Install the build environment
191
+ virtualenv .venv
192
+ source .venv/bin/activate
193
+ pip install build
194
+
195
+ # Build the package
196
+ python -m build
197
+
198
+ # Deactivate the virtual environment
199
+ deactivate
200
+
201
+ # Activate the Target virtual environment
202
+ source /path/to/target_env/bin/activate
203
+
204
+ # Install the package
205
+ pip install /path/to/jupyter-agent/dist/jupyter_agent-xxxx-py3-none-any.whl
206
+ ```
207
+
208
+ ## Install Vscode Extension
209
+
210
+ [Download](https://marketplace.visualstudio.com/items?itemName=viewstar000.jupyter-agent-extension)
211
+
212
+ ## Usage
213
+
214
+ After installing `jupyter-agent` and `jupyter-agent-extension`, you can use `%%bot` magic command to work on task planning, code generation and execution.
215
+
216
+ ### Configuration
217
+
218
+ Basic Configuration:
219
+
220
+ First create or open a notebook in Vscode, create a new cell, enter and execute the following commands:
221
+
222
+ ```python
223
+ # Load the Magic commands of the extension
224
+ %load_ext jupyter_agent.bot_magics
225
+
226
+ # Set the API address of the model to be called, different Agents can call different models, here we call the model deployed locally in lmstudio
227
+ %config BotMagics.default_api_url = 'http://127.0.0.1:1234/v1'
228
+ %config BotMagics.default_api_key = 'API_KEY'
229
+ %config BotMagics.default_model_name = 'qwen3-30b-a3b'
230
+ %config BotMagics.coding_model_name = 'devstral-small-2505-mlx'
231
+ ```
232
+
233
+ Advanced Configuration:
234
+
235
+ ```python
236
+ # Set the current notebook path, when it is not automatically obtained, it needs to be manually specified, for example, in Vscode Notebook
237
+ %config BotMagics.notebook_path = globals()["__vsc_ipynb_file__"]
238
+
239
+ # Set whether to save task data to Metadata, only Vscode installed with jupyter-agent-extension supports
240
+ %config BotMagics.support_save_meta = True
241
+
242
+ # Set the log level, available values are DEBUG、INFO、WARN、ERROR、FATAL, default is INFO
243
+ %config BotMagics.logging_level = 'DEBUG'
244
+
245
+ # Set whether to display thinking process, default is True
246
+ %config BotMagics.display_think = True
247
+
248
+ # Set whether to display messages sent to LLM and LLM responses, default is False
249
+ %config BotMagics.display_message = True
250
+ %config BotMagics.display_response = True
251
+ ```
252
+
253
+ Now, you can use the `%%bot` command to work on task rules and code generation.
254
+
255
+ ### Perform global task planning
256
+
257
+ ```python
258
+ %%bot -P
259
+
260
+ # Global Goal
261
+
262
+ ...
263
+ ```
264
+
265
+ Global task planning will analyze the user input prompt and generate a detailed execution plan, subsequent `%%bot` commands will generate code for each step (subtask) automatically.
266
+
267
+ ![docs/image-global-prompt.png](https://raw.githubusercontent.com/viewstar000/jupyter-agent/refs/heads/main/docs/image-global-prompt.png)
268
+ ![docs/image-global-plan.png](https://raw.githubusercontent.com/viewstar000/jupyter-agent/refs/heads/main/docs/image-global-plan.png)
269
+
270
+ ### Generate and execute subtask code
271
+
272
+ ```python
273
+ %%bot [-s stage]
274
+
275
+ # generated code ...
276
+ ```
277
+
278
+ After global task planning, the tool will generate code for each subtask, and you can use the `%%bot` command to invoke the corresponding agent to generate the code and execute it.
279
+
280
+ ![docs/image-task-empty.png](https://raw.githubusercontent.com/viewstar000/jupyter-agent/refs/heads/main/docs/image-task-empty.png)
281
+
282
+ > **Note:** The `%%bot` cell magic can not locate the empty cell, you must enter the `%%bot` command with some random text in the cell to trigger the magic command.
283
+
284
+ After generating code for a subtask, the tool will call the corresponding agent to generate the code, and then execute it.
285
+
286
+ ![docs/image-task-confirm.png](https://raw.githubusercontent.com/viewstar000/jupyter-agent/refs/heads/main/docs/image-task-confirm.png)
287
+
288
+ > **Note:** Before using the `%%bot` command, you must ensure that the current notebook has been saved, otherwise the agent will not be able to read the full context of the notebook. Suggested to enable the notebook editor's automatic save function.
289
+
290
+ For more details, please refer to [example notebook](https://github.com/viewstar000/jupyter-agent/blob/main/examples/data_loader.ipynb)
291
+
292
+ ## Contributing
293
+
294
+ Welcome to submit issues or pull requests to participate in contributions.
295
+
296
+ ## License
297
+
298
+ This project is based on the [MIT License](https://github.com/viewstar000/jupyter-agent-extension/blob/main/LICENSE) open source.
299
+
300
+ Copyright (c) 2025 viewstar000
@@ -1,7 +1,7 @@
1
1
  jupyter_agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  jupyter_agent/bot_chat.py,sha256=RkaT-Cpkp3G24F1AtbcgqjKo-LBxwMNAYHVitaPZNOg,8834
3
3
  jupyter_agent/bot_contexts.py,sha256=eFezr7ImokMz33jJJMlLLQspQBYnuE6Bc2bE1wLbXWU,19123
4
- jupyter_agent/bot_magics.py,sha256=PQib9GoefCAkh2Hy1InfdoiFo-KE-9wJ4qKEj_k9zO4,6570
4
+ jupyter_agent/bot_magics.py,sha256=whyGu6Jru7ZAIWXjwoq_CfNxqvlDawGTREUHX9XjHFY,7434
5
5
  jupyter_agent/bot_outputs.py,sha256=7_cbOBaGdoYMR6qu43nZEsB9KY6wp4zA0Dh7Jq7LMTg,14065
6
6
  jupyter_agent/utils.py,sha256=jbvDtVK6MfGaf5ZLoam_sq9R5TMriEG4HbMF0bHHDes,4387
7
7
  jupyter_agent/bot_agents/__init__.py,sha256=IdlBlvfaDUfp3qhkNuwUVV_CdplafZsgLezLVkZCREw,1323
@@ -26,8 +26,8 @@ jupyter_agent/bot_flows/master_planner.py,sha256=2MvAMikMsBIarTL4QNYTjAs70bxo7VA
26
26
  jupyter_agent/bot_flows/task_executor_v1.py,sha256=WzTfoOTjBpk1emvpiL3yeiudKdDf6EpVdJIugxxbqM4,2975
27
27
  jupyter_agent/bot_flows/task_executor_v2.py,sha256=IyfxhzA4TljNd6iqqUYxxzB63r9lxfe1Zbu177hytRs,2949
28
28
  jupyter_agent/bot_flows/task_executor_v3.py,sha256=NwJy7iAo2U3rl5iQYpACWVAkIA5DRMDdx0JadheRMMQ,3198
29
- jupyter_agent-2025.6.101.dist-info/licenses/LICENSE,sha256=nWMmSIg7OepTIDX_OPP0-T9ImeCBBoog7eJxm5awtcM,1068
30
- jupyter_agent-2025.6.101.dist-info/METADATA,sha256=NYsa293tWtXEWVKS_SUzIq0cxHiSbUOUzXRrmCpILkU,3815
31
- jupyter_agent-2025.6.101.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
32
- jupyter_agent-2025.6.101.dist-info/top_level.txt,sha256=c3USTBZ7DZGuvLKlEW-QfGIx0tzn98iCEn3bpdYnDtE,14
33
- jupyter_agent-2025.6.101.dist-info/RECORD,,
29
+ jupyter_agent-2025.6.103.dist-info/licenses/LICENSE,sha256=nWMmSIg7OepTIDX_OPP0-T9ImeCBBoog7eJxm5awtcM,1068
30
+ jupyter_agent-2025.6.103.dist-info/METADATA,sha256=ZtUJtanX1-RXpH1mMA6JH9fWCWK4YMaFU1h9e2nP_tE,9998
31
+ jupyter_agent-2025.6.103.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
32
+ jupyter_agent-2025.6.103.dist-info/top_level.txt,sha256=c3USTBZ7DZGuvLKlEW-QfGIx0tzn98iCEn3bpdYnDtE,14
33
+ jupyter_agent-2025.6.103.dist-info/RECORD,,
@@ -1,132 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: jupyter-agent
3
- Version: 2025.6.101
4
- Summary: 调用LLM实现Jupyter代码的自动生成、执行、调试等功能
5
- Author: viewstar000
6
- License: MIT
7
- Project-URL: Homepage, https://github.com/viewstar000/jupyter-agent
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: Operating System :: OS Independent
10
- Requires-Python: >=3.12
11
- Description-Content-Type: text/markdown
12
- License-File: LICENSE
13
- Requires-Dist: ipython
14
- Requires-Dist: nbformat
15
- Requires-Dist: ipynbname
16
- Requires-Dist: openai
17
- Requires-Dist: traitlets
18
- Requires-Dist: pyyaml
19
- Requires-Dist: jinja2
20
- Requires-Dist: pydantic
21
- Dynamic: license-file
22
-
23
- # jupyter-agent
24
-
25
- 调用LLM实现Jupyter代码的自动生成、执行、调试等功能
26
-
27
- ## 特性
28
-
29
- - 提供`%%bot`指令,在juyter环境中,通过调用LLM实现代码生成、执行、调试等能力
30
- - 支持调用OpenAI兼容API,实现LLM相关的功能
31
-
32
- ## 安装
33
-
34
- ```bash
35
- # 激活目标环境(视情况选择)
36
- source /path/to/target_env/bin/activate
37
-
38
- pip install jupyter-agent
39
- ```
40
-
41
- ## 源码打包安全(Build)
42
-
43
- ```bash
44
- # 下载代码
45
- git clone https://github.com/yourusername/jupyter-agent.git
46
- cd jupyter-agent
47
-
48
- # 安装打包环境
49
- virtualenv .venv
50
- source .venv/bin/activate
51
- pip install build
52
-
53
- # 编译打包
54
- python -m build
55
-
56
- # 退出打包环境
57
- deactivate
58
-
59
- # 激活目标环境
60
- source /path/to/target_env/bin/activate
61
-
62
- # 安装编译好的wheel包
63
- pip install /path/to/upyter-agent/dist/jupyter_agent-xxxx-py3-none-any.whl
64
- ```
65
-
66
- ## 使用方法
67
-
68
- 安装完成后,启动Jupyter环境(兼容Vscode的Notebook编译器)
69
-
70
- ### 全局配置
71
-
72
- ```python
73
- # 加载扩展的Magic命令
74
- %load_ext jupyter_agent.bot_magics
75
- # 设备模型调用的API地址,不同的Agent可以调用不同的模型,这里以调用lmstudio本地部署的模型为例
76
- %config BotMagics.default_api_url = 'http://127.0.0.1:1234/v1'
77
- %config BotMagics.default_api_key = 'API_KEY'
78
- %config BotMagics.default_model_name = 'qwen3-30b-a3b'
79
- %config BotMagics.coding_model_name = 'devstral-small-2505-mlx'
80
- # 设置当前Notebook的路径,由于vscode中运行里无法自动获取到该路径,需要手工指定
81
- %config BotMagics.notebook_path = globals()["__vsc_ipynb_file__"]
82
- ```
83
-
84
- ### 全局任务规划
85
-
86
- ```python
87
- %%bot -P
88
-
89
- # 全局目标
90
- ...
91
- ```
92
-
93
- 全局任务规划会解析用户输入的prompt,生成具体的执行计划,后续的%%bot指令会以该计划为蓝本自动生成每个步骤(子任务)的代码。
94
-
95
- ![alt text](docs/image-global-prompt.png)
96
- ![alt text](docs/image-global-plan.png)
97
-
98
- ### 生成并执行子任务代码
99
-
100
- ```python
101
- %% bot [-s stage]
102
-
103
- # generated code ...
104
- ```
105
-
106
- 在完成全局任务规划后,开始执行子任务时,只需要新建一个cell,输入并执行`%%bot`命令,如下图:
107
-
108
- ![alt text](docs/image-task-empty.png)
109
-
110
- > 注:由于cell magic命令无法直接定位当前cell,需要通过cell的内容进行匹配,因此首次执行%%bot命令时,需要在cell中额外添加一些随机字符
111
-
112
- 接下来工具会调用相应的agent自动生成并执行相应步骤的代码,如下图:
113
-
114
- ![alt text](docs/image-task-executing.png)
115
-
116
- 一个cell中只会执行全局计划中的一个步骤,当前步骤执行完成后,需要手工新建一个cell并重复上述过程,直到完成全局目标完成(此时工具不会再生成新代码)
117
-
118
- 在子任务执行的过程中,默认情况下每一个环节工具都会给出如下图的确认提示,可跟据实际情况输入相应的选项,或直接回车确认继续执行下一环节。
119
-
120
- ![alt text](docs/image-task-confirm.png)
121
-
122
- 更详细用法可参考[示例Notebook](examples/data_loader.ipynb)
123
-
124
- ## 贡献
125
-
126
- 欢迎提交 issue 或 pull request 参与贡献。
127
-
128
- ## 许可证
129
-
130
- 本项目基于 [MIT License](./LICENSE) 开源。
131
-
132
- Copyright (c) 2025 viewstar000