thonny-ai-assistant 0.6.4__tar.gz
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.
Potentially problematic release.
This version of thonny-ai-assistant might be problematic. Click here for more details.
- thonny_ai_assistant-0.6.4/LICENSE +22 -0
- thonny_ai_assistant-0.6.4/PKG-INFO +307 -0
- thonny_ai_assistant-0.6.4/README.md +255 -0
- thonny_ai_assistant-0.6.4/pyproject.toml +38 -0
- thonny_ai_assistant-0.6.4/setup.cfg +4 -0
- thonny_ai_assistant-0.6.4/setup.py +47 -0
- thonny_ai_assistant-0.6.4/tests/test_generation_settings.py +30 -0
- thonny_ai_assistant-0.6.4/tests/test_i18n.py +125 -0
- thonny_ai_assistant-0.6.4/thonny_ai_assistant.egg-info/PKG-INFO +307 -0
- thonny_ai_assistant-0.6.4/thonny_ai_assistant.egg-info/SOURCES.txt +15 -0
- thonny_ai_assistant-0.6.4/thonny_ai_assistant.egg-info/dependency_links.txt +1 -0
- thonny_ai_assistant-0.6.4/thonny_ai_assistant.egg-info/entry_points.txt +2 -0
- thonny_ai_assistant-0.6.4/thonny_ai_assistant.egg-info/requires.txt +1 -0
- thonny_ai_assistant-0.6.4/thonny_ai_assistant.egg-info/top_level.txt +1 -0
- thonny_ai_assistant-0.6.4/thonnycontrib/thonny_ai_assistant/__init__.py +50 -0
- thonny_ai_assistant-0.6.4/thonnycontrib/thonny_ai_assistant/i18n.py +231 -0
- thonny_ai_assistant-0.6.4/thonnycontrib/thonny_ai_assistant/thonny_ai_assistant_tool.py +2632 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Oliver0804
|
|
4
|
+
Copyright (c) 2026 TommyLee2009
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: thonny-ai-assistant
|
|
3
|
+
Version: 0.6.4
|
|
4
|
+
Summary: Bilingual AI assistant plugin for Thonny
|
|
5
|
+
Author: TommyLee2009
|
|
6
|
+
Author-email: TommyLee2009 <lcy28898830@gmail.com>
|
|
7
|
+
Maintainer-email: TommyLee2009 <lcy28898830@gmail.com>
|
|
8
|
+
License: MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2025 Oliver0804
|
|
11
|
+
Copyright (c) 2026 TommyLee2009
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
|
|
31
|
+
Project-URL: Homepage, https://github.com/TommyLee2009/thonny_ai_assistant
|
|
32
|
+
Project-URL: Repository, https://github.com/TommyLee2009/thonny_ai_assistant
|
|
33
|
+
Project-URL: Issues, https://github.com/TommyLee2009/thonny_ai_assistant/issues
|
|
34
|
+
Project-URL: Changelog, https://github.com/TommyLee2009/thonny_ai_assistant/blob/main/CHANGELOG.md
|
|
35
|
+
Platform: Windows
|
|
36
|
+
Platform: macOS
|
|
37
|
+
Platform: Linux
|
|
38
|
+
Classifier: Programming Language :: Python :: 3
|
|
39
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
40
|
+
Classifier: Operating System :: OS Independent
|
|
41
|
+
Classifier: Environment :: Plugins
|
|
42
|
+
Classifier: Intended Audience :: Education
|
|
43
|
+
Classifier: Intended Audience :: Developers
|
|
44
|
+
Requires-Python: >=3.8
|
|
45
|
+
Description-Content-Type: text/markdown
|
|
46
|
+
License-File: LICENSE
|
|
47
|
+
Requires-Dist: openai>=1.75.0
|
|
48
|
+
Dynamic: author
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
Dynamic: platform
|
|
51
|
+
Dynamic: requires-python
|
|
52
|
+
|
|
53
|
+
# Thonny AI Assistant
|
|
54
|
+
|
|
55
|
+
[简体中文](#简体中文) | [English](#English)
|
|
56
|
+
|
|
57
|
+

|
|
58
|
+
|
|
59
|
+
# 简体中文
|
|
60
|
+
|
|
61
|
+
这是一个为 Thonny Python IDE 提供双语界面的 AI 助手插件,支持侧边栏聊天、代码分析、流式回复、多供应商配置、模型参数调整和全局系统提示词。
|
|
62
|
+
|
|
63
|
+
## 项目来源
|
|
64
|
+
|
|
65
|
+
本项目基于
|
|
66
|
+
[Oliver0804/thonny_openai_gpt](https://github.com/Oliver0804/thonny_openai_gpt)
|
|
67
|
+
修改而来。上游项目在 README 和包元数据中声明使用 MIT 许可证,但当前没有单独
|
|
68
|
+
的 LICENSE 文件。本仓库补齐了完整 MIT 许可文本,并保留了原作者版权声明,
|
|
69
|
+
见 [LICENSE](LICENSE)。
|
|
70
|
+
|
|
71
|
+
本仓库的主要修改包括多供应商配置、模型列表同步、流式输出、Thonny 明暗主题
|
|
72
|
+
适配、自定义系统提示词和中英文界面。
|
|
73
|
+
|
|
74
|
+
**原项目作者:** Oliver0804
|
|
75
|
+
**原项目邮箱:** [icetzsr@gmail.com](mailto:icetzsr@gmail.com)
|
|
76
|
+
|
|
77
|
+
**软件作者及维护者:** TommyLee2009
|
|
78
|
+
**邮箱:** [lcy28898830@gmail.com](mailto:lcy28898830@gmail.com)
|
|
79
|
+
|
|
80
|
+
本项目与 Thonny、OpenAI、DeepSeek 和阿里云均无隶属或官方背书关系。
|
|
81
|
+
|
|
82
|
+
## 功能
|
|
83
|
+
|
|
84
|
+
- 在 Thonny 侧边栏中与 AI 对话。
|
|
85
|
+
- 分别配置多个 OpenAI 兼容模型供应商。
|
|
86
|
+
- 通过供应商的 `/models` 接口获取模型。
|
|
87
|
+
- 切换供应商和模型。
|
|
88
|
+
- 在设置窗口中调整温度和输出 tokens 上限。
|
|
89
|
+
- 在主面板的模型状态信息旁开关思考模式。
|
|
90
|
+
- 流式显示回复,网络请求不会阻塞 Tk 主线程。
|
|
91
|
+
- 分析当前选中的代码或完整文件。
|
|
92
|
+
- 设置全局系统提示词,用于限定角色、回答结构和质量要求。
|
|
93
|
+
- 自动附加 Thonny 当前编译器/解释器环境信息。
|
|
94
|
+
- 跟随 Thonny 明暗主题。
|
|
95
|
+
- 保存本地聊天记录。
|
|
96
|
+
- 根据 Thonny 界面语言自动使用中文或英文。
|
|
97
|
+
|
|
98
|
+
## 语言切换
|
|
99
|
+
|
|
100
|
+
插件读取 Thonny 的 `general.language` 设置:
|
|
101
|
+
|
|
102
|
+
- `zh_CN`、`zh_TW`、`zh_Hans` 以及其他 `zh_*` 语言显示中文。
|
|
103
|
+
- 其他界面语言统一显示英文。
|
|
104
|
+
|
|
105
|
+
Thonny 修改界面语言后需要重启。重启 Thonny 后,插件工具栏、页签、菜单、
|
|
106
|
+
设置窗口、状态提示和错误信息会一并切换。
|
|
107
|
+
|
|
108
|
+
## 安装
|
|
109
|
+
|
|
110
|
+
1. 确认 **Thonny 版本为 5.0.0 或更高版本**。低于 5.0.0 时,插件安装的用户
|
|
111
|
+
目录可能与 Thonny 实际加载目录不一致,导致插件无法正常加载或运行。
|
|
112
|
+
2. 打开 Thonny 的“工具 > 管理插件”。
|
|
113
|
+
3. 切换到“从PyPI安装”,搜索并安装 `thonny-ai-assistant`。
|
|
114
|
+
4. 离线安装时,先下载对应的 `.whl` 文件,再在“管理插件”中选择从本地安装
|
|
115
|
+
该 wheel 文件。
|
|
116
|
+
5. 安装完成后重启 Thonny。
|
|
117
|
+
|
|
118
|
+
如果插件刚完成首次 PyPI 发布但尚未出现在搜索结果中,请使用离线 wheel
|
|
119
|
+
安装方式。不要只把 wheel 放到 Thonny 目录中,必须通过“管理插件”安装,
|
|
120
|
+
以正确注册 Python 包和 Thonny 插件入口。
|
|
121
|
+
|
|
122
|
+
安装包入口为 `thonny-ai-assistant`,内部视图 ID 保持为 `AIChatView`。
|
|
123
|
+
|
|
124
|
+
PyPI 发布使用 GitHub Actions OIDC,配置和发布步骤见
|
|
125
|
+
[PUBLISHING.md](PUBLISHING.md)。
|
|
126
|
+
|
|
127
|
+
## 配置供应商
|
|
128
|
+
|
|
129
|
+
1. 打开 Thonny 的“视图 > AI助手”。
|
|
130
|
+
2. 点击设置按钮。
|
|
131
|
+
3. 填写供应商名称、API 地址和 API Key。
|
|
132
|
+
4. 在“生成参数”中调整温度和输出 tokens 上限。
|
|
133
|
+
5. 根据需要填写全局系统提示词。
|
|
134
|
+
6. 点击“保存并获取模型”。
|
|
135
|
+
7. 在顶部选择供应商和模型。
|
|
136
|
+
|
|
137
|
+
模型供应商需要兼容以下接口:
|
|
138
|
+
|
|
139
|
+
```text
|
|
140
|
+
GET {API 地址}/models
|
|
141
|
+
POST {API 地址}/chat/completions
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## 数据与隐私
|
|
145
|
+
|
|
146
|
+
本地配置和聊天记录保存在:
|
|
147
|
+
|
|
148
|
+
```text
|
|
149
|
+
~/.thonny/thonny_ai_assistant_config/config.json
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
API Key 以明文保存在本机配置文件中。不要将该文件上传到 GitHub、发送给他人
|
|
153
|
+
或截图公开。Key 一旦泄露,应立即到供应商平台撤销并重新创建。
|
|
154
|
+
|
|
155
|
+
代码和提示词会发送到用户选择的模型供应商。涉及个人信息时,应先脱敏并确认数据使用范围。
|
|
156
|
+
|
|
157
|
+
## 开发与验证
|
|
158
|
+
|
|
159
|
+
运行本地语言测试:
|
|
160
|
+
|
|
161
|
+
```powershell
|
|
162
|
+
& "C:\Program Files\Thonny\python.exe" -m unittest discover -s tests -v
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
构建 wheel:
|
|
166
|
+
|
|
167
|
+
```powershell
|
|
168
|
+
& "C:\Program Files\Thonny\python.exe" -m pip wheel . --no-deps --wheel-dir dist
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## 许可证
|
|
172
|
+
|
|
173
|
+
本项目采用 [MIT License](LICENSE)。
|
|
174
|
+
|
|
175
|
+
Copyright (c) 2025 Oliver0804
|
|
176
|
+
Copyright (c) 2026 TommyLee2009
|
|
177
|
+
|
|
178
|
+
----
|
|
179
|
+
# English
|
|
180
|
+
A bilingual AI assistant plugin for the Thonny Python IDE. It provides a
|
|
181
|
+
side-panel chat, code analysis, streaming responses, multiple
|
|
182
|
+
OpenAI-compatible providers, configurable generation parameters, and a global
|
|
183
|
+
system prompt.
|
|
184
|
+
|
|
185
|
+
## Attribution
|
|
186
|
+
|
|
187
|
+
This project is based on and substantially modified from
|
|
188
|
+
[Oliver0804/thonny_openai_gpt](https://github.com/Oliver0804/thonny_openai_gpt).
|
|
189
|
+
The upstream project declares the MIT License in its README and package
|
|
190
|
+
metadata, but does not currently provide a standalone license file. This
|
|
191
|
+
repository includes the complete MIT text and preserves the original copyright
|
|
192
|
+
notice in [LICENSE](LICENSE).
|
|
193
|
+
|
|
194
|
+
Major modifications in this repository include multi-provider configuration,
|
|
195
|
+
automatic model discovery, streaming output, theme integration, configurable
|
|
196
|
+
system prompts, and Chinese/English localization.
|
|
197
|
+
|
|
198
|
+
**Original project author:** Oliver0804
|
|
199
|
+
**Original project contact:** [icetzsr@gmail.com](mailto:icetzsr@gmail.com)
|
|
200
|
+
|
|
201
|
+
**Maintainer and software author:** TommyLee2009
|
|
202
|
+
**Email:** [lcy28898830@gmail.com](mailto:lcy28898830@gmail.com)
|
|
203
|
+
|
|
204
|
+
This project is not affiliated with or endorsed by the Thonny project, OpenAI,
|
|
205
|
+
DeepSeek, or Alibaba Cloud.
|
|
206
|
+
|
|
207
|
+
## Features
|
|
208
|
+
|
|
209
|
+
- Chat with AI from a Thonny side panel.
|
|
210
|
+
- Configure multiple OpenAI-compatible providers independently.
|
|
211
|
+
- Discover available models through the provider's `/models` endpoint.
|
|
212
|
+
- Select the provider and model from the panel.
|
|
213
|
+
- Configure temperature and output token limit in the settings dialog.
|
|
214
|
+
- Toggle thinking mode beside the model status in the main panel.
|
|
215
|
+
- Stream responses without blocking the Tk main thread.
|
|
216
|
+
- Analyze selected code or the complete file in the current editor.
|
|
217
|
+
- Configure a global system prompt for role and quality requirements.
|
|
218
|
+
- Automatically include Thonny's current interpreter environment context.
|
|
219
|
+
- Follow Thonny's light and dark UI themes.
|
|
220
|
+
- Save local chat history.
|
|
221
|
+
- Use Chinese or English automatically based on Thonny's UI language.
|
|
222
|
+
|
|
223
|
+
## Language behavior
|
|
224
|
+
|
|
225
|
+
The plugin reads Thonny's `general.language` option:
|
|
226
|
+
|
|
227
|
+
- `zh_CN`, `zh_TW`, `zh_Hans`, or any other `zh_*` language uses Chinese.
|
|
228
|
+
- Every other Thonny language falls back to English.
|
|
229
|
+
|
|
230
|
+
Thonny requires a restart after changing its interface language. Restart
|
|
231
|
+
Thonny for the plugin labels and dialogs to switch languages too.
|
|
232
|
+
|
|
233
|
+
## Requirements
|
|
234
|
+
|
|
235
|
+
- Thonny 5.0.0 or newer. Older versions may use a different user plugin
|
|
236
|
+
directory from the one Thonny actually loads, causing the plugin to
|
|
237
|
+
malfunction.
|
|
238
|
+
- `openai>=1.75.0`.
|
|
239
|
+
- Network access to the configured model provider.
|
|
240
|
+
- A valid API key for that provider.
|
|
241
|
+
|
|
242
|
+
## Installation
|
|
243
|
+
|
|
244
|
+
1. Confirm that **Thonny 5.0.0 or newer** is installed. Older versions may use
|
|
245
|
+
a different user plugin directory from the one Thonny actually loads.
|
|
246
|
+
2. Open **Tools > Manage plugins** in Thonny.
|
|
247
|
+
3. Open **Install from PyPI** and search for `thonny-ai-assistant`.
|
|
248
|
+
4. For offline installation, download the required `.whl` file and install it
|
|
249
|
+
from the local-file option in **Manage plugins**.
|
|
250
|
+
5. Restart Thonny after installation.
|
|
251
|
+
|
|
252
|
+
If the package has just been published to PyPI and does not appear in search
|
|
253
|
+
results yet, use the offline wheel option. Copying a wheel into the Thonny
|
|
254
|
+
directory is not sufficient; install it through **Manage plugins** so the
|
|
255
|
+
Python package and Thonny entry point are registered correctly.
|
|
256
|
+
|
|
257
|
+
The package entry point is `thonny-ai-assistant`. The internal Thonny view
|
|
258
|
+
identifier remains `AIChatView`.
|
|
259
|
+
|
|
260
|
+
PyPI publication uses GitHub Actions OIDC. See
|
|
261
|
+
[PUBLISHING.md](PUBLISHING.md) for trusted-publisher settings and the release
|
|
262
|
+
procedure.
|
|
263
|
+
|
|
264
|
+
## Configuration
|
|
265
|
+
|
|
266
|
+
1. Open **View > AI Assistant** (or **视图 > AI助手**).
|
|
267
|
+
2. Click the gear button.
|
|
268
|
+
3. Enter the provider name, API base URL, and API key.
|
|
269
|
+
4. Adjust temperature and output tokens in **Generation settings**.
|
|
270
|
+
5. Optionally define a global system prompt.
|
|
271
|
+
6. Click **Save and fetch models** (or **保存并获取模型**).
|
|
272
|
+
7. Select the provider and model in the panel.
|
|
273
|
+
|
|
274
|
+
The provider must implement:
|
|
275
|
+
|
|
276
|
+
```text
|
|
277
|
+
GET {API base URL}/models
|
|
278
|
+
POST {API base URL}/chat/completions
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Configuration and privacy
|
|
282
|
+
|
|
283
|
+
Local configuration and chat history are stored in:
|
|
284
|
+
|
|
285
|
+
```text
|
|
286
|
+
~/.thonny/thonny_ai_assistant_config/config.json
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
API keys are stored locally in plain text. Do not publish this file, commit it
|
|
290
|
+
to GitHub, or include it in screenshots. Revoke a key immediately if it is
|
|
291
|
+
exposed. Code and prompts are sent to the provider selected by the user.
|
|
292
|
+
Remove student names, student IDs, grades, employer information, and other
|
|
293
|
+
sensitive data before sending content to an external model.
|
|
294
|
+
|
|
295
|
+
See [SECURITY.md](SECURITY.md) for vulnerability reporting.
|
|
296
|
+
|
|
297
|
+
## License
|
|
298
|
+
|
|
299
|
+
This project is distributed under the [MIT License](LICENSE).
|
|
300
|
+
|
|
301
|
+
Copyright (c) 2025 Oliver0804
|
|
302
|
+
Copyright (c) 2026 TommyLee2009
|
|
303
|
+
|
|
304
|
+
The MIT terms require retaining the copyright and permission notice in copies
|
|
305
|
+
or substantial portions of the software.
|
|
306
|
+
|
|
307
|
+
---
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# Thonny AI Assistant
|
|
2
|
+
|
|
3
|
+
[简体中文](#简体中文) | [English](#English)
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
# 简体中文
|
|
8
|
+
|
|
9
|
+
这是一个为 Thonny Python IDE 提供双语界面的 AI 助手插件,支持侧边栏聊天、代码分析、流式回复、多供应商配置、模型参数调整和全局系统提示词。
|
|
10
|
+
|
|
11
|
+
## 项目来源
|
|
12
|
+
|
|
13
|
+
本项目基于
|
|
14
|
+
[Oliver0804/thonny_openai_gpt](https://github.com/Oliver0804/thonny_openai_gpt)
|
|
15
|
+
修改而来。上游项目在 README 和包元数据中声明使用 MIT 许可证,但当前没有单独
|
|
16
|
+
的 LICENSE 文件。本仓库补齐了完整 MIT 许可文本,并保留了原作者版权声明,
|
|
17
|
+
见 [LICENSE](LICENSE)。
|
|
18
|
+
|
|
19
|
+
本仓库的主要修改包括多供应商配置、模型列表同步、流式输出、Thonny 明暗主题
|
|
20
|
+
适配、自定义系统提示词和中英文界面。
|
|
21
|
+
|
|
22
|
+
**原项目作者:** Oliver0804
|
|
23
|
+
**原项目邮箱:** [icetzsr@gmail.com](mailto:icetzsr@gmail.com)
|
|
24
|
+
|
|
25
|
+
**软件作者及维护者:** TommyLee2009
|
|
26
|
+
**邮箱:** [lcy28898830@gmail.com](mailto:lcy28898830@gmail.com)
|
|
27
|
+
|
|
28
|
+
本项目与 Thonny、OpenAI、DeepSeek 和阿里云均无隶属或官方背书关系。
|
|
29
|
+
|
|
30
|
+
## 功能
|
|
31
|
+
|
|
32
|
+
- 在 Thonny 侧边栏中与 AI 对话。
|
|
33
|
+
- 分别配置多个 OpenAI 兼容模型供应商。
|
|
34
|
+
- 通过供应商的 `/models` 接口获取模型。
|
|
35
|
+
- 切换供应商和模型。
|
|
36
|
+
- 在设置窗口中调整温度和输出 tokens 上限。
|
|
37
|
+
- 在主面板的模型状态信息旁开关思考模式。
|
|
38
|
+
- 流式显示回复,网络请求不会阻塞 Tk 主线程。
|
|
39
|
+
- 分析当前选中的代码或完整文件。
|
|
40
|
+
- 设置全局系统提示词,用于限定角色、回答结构和质量要求。
|
|
41
|
+
- 自动附加 Thonny 当前编译器/解释器环境信息。
|
|
42
|
+
- 跟随 Thonny 明暗主题。
|
|
43
|
+
- 保存本地聊天记录。
|
|
44
|
+
- 根据 Thonny 界面语言自动使用中文或英文。
|
|
45
|
+
|
|
46
|
+
## 语言切换
|
|
47
|
+
|
|
48
|
+
插件读取 Thonny 的 `general.language` 设置:
|
|
49
|
+
|
|
50
|
+
- `zh_CN`、`zh_TW`、`zh_Hans` 以及其他 `zh_*` 语言显示中文。
|
|
51
|
+
- 其他界面语言统一显示英文。
|
|
52
|
+
|
|
53
|
+
Thonny 修改界面语言后需要重启。重启 Thonny 后,插件工具栏、页签、菜单、
|
|
54
|
+
设置窗口、状态提示和错误信息会一并切换。
|
|
55
|
+
|
|
56
|
+
## 安装
|
|
57
|
+
|
|
58
|
+
1. 确认 **Thonny 版本为 5.0.0 或更高版本**。低于 5.0.0 时,插件安装的用户
|
|
59
|
+
目录可能与 Thonny 实际加载目录不一致,导致插件无法正常加载或运行。
|
|
60
|
+
2. 打开 Thonny 的“工具 > 管理插件”。
|
|
61
|
+
3. 切换到“从PyPI安装”,搜索并安装 `thonny-ai-assistant`。
|
|
62
|
+
4. 离线安装时,先下载对应的 `.whl` 文件,再在“管理插件”中选择从本地安装
|
|
63
|
+
该 wheel 文件。
|
|
64
|
+
5. 安装完成后重启 Thonny。
|
|
65
|
+
|
|
66
|
+
如果插件刚完成首次 PyPI 发布但尚未出现在搜索结果中,请使用离线 wheel
|
|
67
|
+
安装方式。不要只把 wheel 放到 Thonny 目录中,必须通过“管理插件”安装,
|
|
68
|
+
以正确注册 Python 包和 Thonny 插件入口。
|
|
69
|
+
|
|
70
|
+
安装包入口为 `thonny-ai-assistant`,内部视图 ID 保持为 `AIChatView`。
|
|
71
|
+
|
|
72
|
+
PyPI 发布使用 GitHub Actions OIDC,配置和发布步骤见
|
|
73
|
+
[PUBLISHING.md](PUBLISHING.md)。
|
|
74
|
+
|
|
75
|
+
## 配置供应商
|
|
76
|
+
|
|
77
|
+
1. 打开 Thonny 的“视图 > AI助手”。
|
|
78
|
+
2. 点击设置按钮。
|
|
79
|
+
3. 填写供应商名称、API 地址和 API Key。
|
|
80
|
+
4. 在“生成参数”中调整温度和输出 tokens 上限。
|
|
81
|
+
5. 根据需要填写全局系统提示词。
|
|
82
|
+
6. 点击“保存并获取模型”。
|
|
83
|
+
7. 在顶部选择供应商和模型。
|
|
84
|
+
|
|
85
|
+
模型供应商需要兼容以下接口:
|
|
86
|
+
|
|
87
|
+
```text
|
|
88
|
+
GET {API 地址}/models
|
|
89
|
+
POST {API 地址}/chat/completions
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## 数据与隐私
|
|
93
|
+
|
|
94
|
+
本地配置和聊天记录保存在:
|
|
95
|
+
|
|
96
|
+
```text
|
|
97
|
+
~/.thonny/thonny_ai_assistant_config/config.json
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
API Key 以明文保存在本机配置文件中。不要将该文件上传到 GitHub、发送给他人
|
|
101
|
+
或截图公开。Key 一旦泄露,应立即到供应商平台撤销并重新创建。
|
|
102
|
+
|
|
103
|
+
代码和提示词会发送到用户选择的模型供应商。涉及个人信息时,应先脱敏并确认数据使用范围。
|
|
104
|
+
|
|
105
|
+
## 开发与验证
|
|
106
|
+
|
|
107
|
+
运行本地语言测试:
|
|
108
|
+
|
|
109
|
+
```powershell
|
|
110
|
+
& "C:\Program Files\Thonny\python.exe" -m unittest discover -s tests -v
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
构建 wheel:
|
|
114
|
+
|
|
115
|
+
```powershell
|
|
116
|
+
& "C:\Program Files\Thonny\python.exe" -m pip wheel . --no-deps --wheel-dir dist
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## 许可证
|
|
120
|
+
|
|
121
|
+
本项目采用 [MIT License](LICENSE)。
|
|
122
|
+
|
|
123
|
+
Copyright (c) 2025 Oliver0804
|
|
124
|
+
Copyright (c) 2026 TommyLee2009
|
|
125
|
+
|
|
126
|
+
----
|
|
127
|
+
# English
|
|
128
|
+
A bilingual AI assistant plugin for the Thonny Python IDE. It provides a
|
|
129
|
+
side-panel chat, code analysis, streaming responses, multiple
|
|
130
|
+
OpenAI-compatible providers, configurable generation parameters, and a global
|
|
131
|
+
system prompt.
|
|
132
|
+
|
|
133
|
+
## Attribution
|
|
134
|
+
|
|
135
|
+
This project is based on and substantially modified from
|
|
136
|
+
[Oliver0804/thonny_openai_gpt](https://github.com/Oliver0804/thonny_openai_gpt).
|
|
137
|
+
The upstream project declares the MIT License in its README and package
|
|
138
|
+
metadata, but does not currently provide a standalone license file. This
|
|
139
|
+
repository includes the complete MIT text and preserves the original copyright
|
|
140
|
+
notice in [LICENSE](LICENSE).
|
|
141
|
+
|
|
142
|
+
Major modifications in this repository include multi-provider configuration,
|
|
143
|
+
automatic model discovery, streaming output, theme integration, configurable
|
|
144
|
+
system prompts, and Chinese/English localization.
|
|
145
|
+
|
|
146
|
+
**Original project author:** Oliver0804
|
|
147
|
+
**Original project contact:** [icetzsr@gmail.com](mailto:icetzsr@gmail.com)
|
|
148
|
+
|
|
149
|
+
**Maintainer and software author:** TommyLee2009
|
|
150
|
+
**Email:** [lcy28898830@gmail.com](mailto:lcy28898830@gmail.com)
|
|
151
|
+
|
|
152
|
+
This project is not affiliated with or endorsed by the Thonny project, OpenAI,
|
|
153
|
+
DeepSeek, or Alibaba Cloud.
|
|
154
|
+
|
|
155
|
+
## Features
|
|
156
|
+
|
|
157
|
+
- Chat with AI from a Thonny side panel.
|
|
158
|
+
- Configure multiple OpenAI-compatible providers independently.
|
|
159
|
+
- Discover available models through the provider's `/models` endpoint.
|
|
160
|
+
- Select the provider and model from the panel.
|
|
161
|
+
- Configure temperature and output token limit in the settings dialog.
|
|
162
|
+
- Toggle thinking mode beside the model status in the main panel.
|
|
163
|
+
- Stream responses without blocking the Tk main thread.
|
|
164
|
+
- Analyze selected code or the complete file in the current editor.
|
|
165
|
+
- Configure a global system prompt for role and quality requirements.
|
|
166
|
+
- Automatically include Thonny's current interpreter environment context.
|
|
167
|
+
- Follow Thonny's light and dark UI themes.
|
|
168
|
+
- Save local chat history.
|
|
169
|
+
- Use Chinese or English automatically based on Thonny's UI language.
|
|
170
|
+
|
|
171
|
+
## Language behavior
|
|
172
|
+
|
|
173
|
+
The plugin reads Thonny's `general.language` option:
|
|
174
|
+
|
|
175
|
+
- `zh_CN`, `zh_TW`, `zh_Hans`, or any other `zh_*` language uses Chinese.
|
|
176
|
+
- Every other Thonny language falls back to English.
|
|
177
|
+
|
|
178
|
+
Thonny requires a restart after changing its interface language. Restart
|
|
179
|
+
Thonny for the plugin labels and dialogs to switch languages too.
|
|
180
|
+
|
|
181
|
+
## Requirements
|
|
182
|
+
|
|
183
|
+
- Thonny 5.0.0 or newer. Older versions may use a different user plugin
|
|
184
|
+
directory from the one Thonny actually loads, causing the plugin to
|
|
185
|
+
malfunction.
|
|
186
|
+
- `openai>=1.75.0`.
|
|
187
|
+
- Network access to the configured model provider.
|
|
188
|
+
- A valid API key for that provider.
|
|
189
|
+
|
|
190
|
+
## Installation
|
|
191
|
+
|
|
192
|
+
1. Confirm that **Thonny 5.0.0 or newer** is installed. Older versions may use
|
|
193
|
+
a different user plugin directory from the one Thonny actually loads.
|
|
194
|
+
2. Open **Tools > Manage plugins** in Thonny.
|
|
195
|
+
3. Open **Install from PyPI** and search for `thonny-ai-assistant`.
|
|
196
|
+
4. For offline installation, download the required `.whl` file and install it
|
|
197
|
+
from the local-file option in **Manage plugins**.
|
|
198
|
+
5. Restart Thonny after installation.
|
|
199
|
+
|
|
200
|
+
If the package has just been published to PyPI and does not appear in search
|
|
201
|
+
results yet, use the offline wheel option. Copying a wheel into the Thonny
|
|
202
|
+
directory is not sufficient; install it through **Manage plugins** so the
|
|
203
|
+
Python package and Thonny entry point are registered correctly.
|
|
204
|
+
|
|
205
|
+
The package entry point is `thonny-ai-assistant`. The internal Thonny view
|
|
206
|
+
identifier remains `AIChatView`.
|
|
207
|
+
|
|
208
|
+
PyPI publication uses GitHub Actions OIDC. See
|
|
209
|
+
[PUBLISHING.md](PUBLISHING.md) for trusted-publisher settings and the release
|
|
210
|
+
procedure.
|
|
211
|
+
|
|
212
|
+
## Configuration
|
|
213
|
+
|
|
214
|
+
1. Open **View > AI Assistant** (or **视图 > AI助手**).
|
|
215
|
+
2. Click the gear button.
|
|
216
|
+
3. Enter the provider name, API base URL, and API key.
|
|
217
|
+
4. Adjust temperature and output tokens in **Generation settings**.
|
|
218
|
+
5. Optionally define a global system prompt.
|
|
219
|
+
6. Click **Save and fetch models** (or **保存并获取模型**).
|
|
220
|
+
7. Select the provider and model in the panel.
|
|
221
|
+
|
|
222
|
+
The provider must implement:
|
|
223
|
+
|
|
224
|
+
```text
|
|
225
|
+
GET {API base URL}/models
|
|
226
|
+
POST {API base URL}/chat/completions
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Configuration and privacy
|
|
230
|
+
|
|
231
|
+
Local configuration and chat history are stored in:
|
|
232
|
+
|
|
233
|
+
```text
|
|
234
|
+
~/.thonny/thonny_ai_assistant_config/config.json
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
API keys are stored locally in plain text. Do not publish this file, commit it
|
|
238
|
+
to GitHub, or include it in screenshots. Revoke a key immediately if it is
|
|
239
|
+
exposed. Code and prompts are sent to the provider selected by the user.
|
|
240
|
+
Remove student names, student IDs, grades, employer information, and other
|
|
241
|
+
sensitive data before sending content to an external model.
|
|
242
|
+
|
|
243
|
+
See [SECURITY.md](SECURITY.md) for vulnerability reporting.
|
|
244
|
+
|
|
245
|
+
## License
|
|
246
|
+
|
|
247
|
+
This project is distributed under the [MIT License](LICENSE).
|
|
248
|
+
|
|
249
|
+
Copyright (c) 2025 Oliver0804
|
|
250
|
+
Copyright (c) 2026 TommyLee2009
|
|
251
|
+
|
|
252
|
+
The MIT terms require retaining the copyright and permission notice in copies
|
|
253
|
+
or substantial portions of the software.
|
|
254
|
+
|
|
255
|
+
---
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=42", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "thonny-ai-assistant"
|
|
7
|
+
version = "0.6.4"
|
|
8
|
+
description = "Bilingual AI assistant plugin for Thonny"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{name = "TommyLee2009", email = "lcy28898830@gmail.com"}
|
|
12
|
+
]
|
|
13
|
+
maintainers = [
|
|
14
|
+
{name = "TommyLee2009", email = "lcy28898830@gmail.com"}
|
|
15
|
+
]
|
|
16
|
+
license = {file = "LICENSE"}
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Environment :: Plugins",
|
|
22
|
+
"Intended Audience :: Education",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
]
|
|
25
|
+
dependencies = ["openai>=1.75.0"]
|
|
26
|
+
requires-python = ">=3.8"
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/TommyLee2009/thonny_ai_assistant"
|
|
30
|
+
Repository = "https://github.com/TommyLee2009/thonny_ai_assistant"
|
|
31
|
+
Issues = "https://github.com/TommyLee2009/thonny_ai_assistant/issues"
|
|
32
|
+
Changelog = "https://github.com/TommyLee2009/thonny_ai_assistant/blob/main/CHANGELOG.md"
|
|
33
|
+
|
|
34
|
+
[project.entry-points."thonny.plugins"]
|
|
35
|
+
thonny-ai-assistant = "thonnycontrib.thonny_ai_assistant"
|
|
36
|
+
|
|
37
|
+
[tool.setuptools.packages.find]
|
|
38
|
+
include = ["thonnycontrib", "thonnycontrib.*"]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from setuptools import setup, find_namespace_packages
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
README_PATH = Path(__file__).with_name("README.md")
|
|
7
|
+
|
|
8
|
+
setup(
|
|
9
|
+
name="thonny-ai-assistant",
|
|
10
|
+
version="0.6.4",
|
|
11
|
+
description="Bilingual AI assistant plugin for Thonny",
|
|
12
|
+
long_description=README_PATH.read_text(encoding="utf-8"),
|
|
13
|
+
long_description_content_type="text/markdown",
|
|
14
|
+
author="TommyLee2009",
|
|
15
|
+
author_email="lcy28898830@gmail.com",
|
|
16
|
+
license="MIT",
|
|
17
|
+
license_files=["LICENSE"],
|
|
18
|
+
packages=find_namespace_packages(
|
|
19
|
+
include=["thonnycontrib", "thonnycontrib.*"],
|
|
20
|
+
),
|
|
21
|
+
classifiers=[
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"License :: OSI Approved :: MIT License",
|
|
24
|
+
"Operating System :: OS Independent",
|
|
25
|
+
"Environment :: Plugins",
|
|
26
|
+
"Intended Audience :: Education",
|
|
27
|
+
"Intended Audience :: Developers",
|
|
28
|
+
],
|
|
29
|
+
install_requires=["openai>=1.75.0"],
|
|
30
|
+
python_requires=">=3.8",
|
|
31
|
+
platforms=["Windows", "macOS", "Linux"],
|
|
32
|
+
keywords=[
|
|
33
|
+
"thonny",
|
|
34
|
+
"openai",
|
|
35
|
+
"deepseek",
|
|
36
|
+
"ai",
|
|
37
|
+
"plugin",
|
|
38
|
+
"ide",
|
|
39
|
+
"education",
|
|
40
|
+
],
|
|
41
|
+
# Thonny 插件命名空间
|
|
42
|
+
entry_points={
|
|
43
|
+
"thonny.plugins": [
|
|
44
|
+
"thonny-ai-assistant = thonnycontrib.thonny_ai_assistant"
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
)
|