nonebot-plugin-pxchat-enhanced 2.0.0__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.
- nonebot_plugin_pxchat_enhanced-2.0.0/PKG-INFO +257 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/README.md +242 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/pyproject.toml +27 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/src/nonebot_plugin_pxchat_enhanced/__init__.py +879 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/src/nonebot_plugin_pxchat_enhanced/admin.py +149 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/src/nonebot_plugin_pxchat_enhanced/chat.py +613 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/src/nonebot_plugin_pxchat_enhanced/commands.py +641 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/src/nonebot_plugin_pxchat_enhanced/config.py +13 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/src/nonebot_plugin_pxchat_enhanced/context.py +82 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/src/nonebot_plugin_pxchat_enhanced/engagement.py +131 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/src/nonebot_plugin_pxchat_enhanced/image2txt.py +132 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/src/nonebot_plugin_pxchat_enhanced/log.py +106 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/src/nonebot_plugin_pxchat_enhanced/manager.py +447 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/src/nonebot_plugin_pxchat_enhanced/mcp_manager.py +154 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/src/nonebot_plugin_pxchat_enhanced/memory.py +243 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/src/nonebot_plugin_pxchat_enhanced/send2root.py +131 -0
- nonebot_plugin_pxchat_enhanced-2.0.0/src/nonebot_plugin_pxchat_enhanced/state.py +208 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: nonebot-plugin-pxchat-enhanced
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: 基于AI大模型的拟人化聊天插件,支持多模型切换、上下文记忆、群聊智能参与、短期状态追踪、群成员记忆、图片识别、MCP工具调用、自动禁言等功能
|
|
5
|
+
Author: Srythm
|
|
6
|
+
Author-email: Srythm <2074447320@qq.com>
|
|
7
|
+
Requires-Dist: nonebot2>=2.4.3,<3.0.0
|
|
8
|
+
Requires-Dist: nonebot-adapter-onebot>=2.4.6,<3.0.0
|
|
9
|
+
Requires-Dist: openai>=2.2.0
|
|
10
|
+
Requires-Dist: mcp>=1.16.0
|
|
11
|
+
Requires-Dist: nonebot-plugin-localstore>=0.7.3
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Project-URL: Repository, https://github.com/Srythm/nonebot-plugin-pxchat-enhanced
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
<div align="center">
|
|
17
|
+
<a href="https://v2.nonebot.dev/store">
|
|
18
|
+
<img src="https://raw.githubusercontent.com/fllesser/nonebot-plugin-template/refs/heads/resource/.docs/NoneBotPlugin.svg" width="310" alt="logo"></a>
|
|
19
|
+
|
|
20
|
+
## ✨ nonebot-plugin-pxchat-enhanced ✨
|
|
21
|
+
[](https://www.python.org)
|
|
22
|
+
[](https://github.com/astral-sh/uv)
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
## 📖 介绍
|
|
26
|
+
|
|
27
|
+
基于 AI 大模型的拟人化聊天插件。不只是"回答问题",而是像一个真实群友一样——会判断什么时候该说话、记得你是谁、有情绪起伏、会累会沉默。
|
|
28
|
+
|
|
29
|
+
安装后使用 `px about` 查看完整帮助,所有功能均可通过聊天指令配置。
|
|
30
|
+
|
|
31
|
+
## ✨ 核心特性
|
|
32
|
+
|
|
33
|
+
- **多模型切换** — 支持配置多个兼容 OpenAI API 的模型,聊天和图片识别可分别指定
|
|
34
|
+
- **上下文记忆** — 自动维护最近 20 条对话,群聊和私聊独立上下文
|
|
35
|
+
- **智能参与** — 模型自主判断是否回复 + 置信度过滤 + 动态参与度门槛,三层决策
|
|
36
|
+
- **短期状态** — 追踪连续回复轮数、精力值、话题兴趣度,模拟真人"想说话/不想说话"
|
|
37
|
+
- **群成员记忆** — 记录发言统计、关键词、互动摘要、6小时消息缓存,回复时自然注入
|
|
38
|
+
- **延迟回复** — 群聊非@消息 15-20s 后判断,@消息 3-5s,延迟值复用不重新随机
|
|
39
|
+
- **打字节奏** — 模型输出 `fast`/`normal`/`slow` 控制分段间隔
|
|
40
|
+
- **精确引用** — 消息渲染带完整 msg_id,模型可指定引用具体消息
|
|
41
|
+
- **思考模式** — reasoning 模型一次调用完成判断+回复,节省 Token
|
|
42
|
+
- **图片识别** — 多模态模型,群聊延迟识别、私聊即时
|
|
43
|
+
- **MCP 工具** — SSE/stdio,工具调用与回复合为一请求
|
|
44
|
+
- **自动禁言** — 模型判断→权限检测→执行,冷却+时长可配
|
|
45
|
+
- **突发检测** — 30s 内≥10 条消息自动重置参与度
|
|
46
|
+
- **消息感知** — 识别 @、回复引用、卡片(json/分享/小程序/markdown)
|
|
47
|
+
- **Token 优化** — 压缩 Prompt、12 条上下文、4 人记忆、合并调用
|
|
48
|
+
|
|
49
|
+
## 💿 安装
|
|
50
|
+
|
|
51
|
+
<details open>
|
|
52
|
+
<summary>[推荐] 使用 nb-cli 安装</summary>
|
|
53
|
+
|
|
54
|
+
```shell
|
|
55
|
+
nb plugin install nonebot-plugin-pxchat-enhanced
|
|
56
|
+
```
|
|
57
|
+
</details>
|
|
58
|
+
|
|
59
|
+
<details>
|
|
60
|
+
<summary>使用包管理器安装</summary>
|
|
61
|
+
|
|
62
|
+
```shell
|
|
63
|
+
pip install nonebot-plugin-pxchat-enhanced
|
|
64
|
+
# or
|
|
65
|
+
uv add nonebot-plugin-pxchat-enhanced
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
然后在 `pyproject.toml` 中追加:
|
|
69
|
+
```toml
|
|
70
|
+
[tool.nonebot]
|
|
71
|
+
plugins = ["nonebot_plugin_pxchat_enhanced"]
|
|
72
|
+
```
|
|
73
|
+
</details>
|
|
74
|
+
|
|
75
|
+
## ⚙️ 配置
|
|
76
|
+
|
|
77
|
+
在 `.env` 中添加必要配置,其余均可通过聊天指令设置:
|
|
78
|
+
|
|
79
|
+
| 配置项 | 必填 | 默认值 | 说明 |
|
|
80
|
+
|:------:|:---:|:-----:|------|
|
|
81
|
+
| `pxchat_super_users` | 是 | 无 | 超级用户列表,如 `["123456"]` |
|
|
82
|
+
| `pxchat_mcp` | 否 | 无 | MCP 服务器配置 |
|
|
83
|
+
|
|
84
|
+
配置示例:
|
|
85
|
+
```shell
|
|
86
|
+
pxchat_super_users=["123456"]
|
|
87
|
+
|
|
88
|
+
pxchat_mcp='{
|
|
89
|
+
"web_search": {
|
|
90
|
+
"type": "sse",
|
|
91
|
+
"url": "https://dashscope.aliyuncs.com/api/v1/mcps/WebSearch/sse",
|
|
92
|
+
"headers": {"Authorization": "Bearer your-api-key"},
|
|
93
|
+
"enabled": true
|
|
94
|
+
}
|
|
95
|
+
}'
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
持久化配置结构(由指令自动维护,无需手动编辑):
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"super_users": ["QQ号"],
|
|
102
|
+
"enabled_groups": ["群号"],
|
|
103
|
+
"chat_enabled": true,
|
|
104
|
+
"group_chat_probability": 1,
|
|
105
|
+
"group_probabilities": {},
|
|
106
|
+
"personality": "你叫px,是被困在服务器中的ai程序...",
|
|
107
|
+
"ai_configs": [
|
|
108
|
+
{
|
|
109
|
+
"name": "ds-chat",
|
|
110
|
+
"api_key": "sk-xxx",
|
|
111
|
+
"api_url": "https://api.deepseek.com",
|
|
112
|
+
"model": "deepseek-chat",
|
|
113
|
+
"thinking": false
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"current_ai_config": 0,
|
|
117
|
+
"image_recognition_enabled": false,
|
|
118
|
+
"current_image_recognition_config": 0,
|
|
119
|
+
"enable_search": false,
|
|
120
|
+
"mcp_enabled": false,
|
|
121
|
+
"mcp_servers": {},
|
|
122
|
+
"auto_mute_enabled": false,
|
|
123
|
+
"auto_mute_min_duration": 60,
|
|
124
|
+
"auto_mute_max_duration": 600,
|
|
125
|
+
"auto_mute_cooldown": 300,
|
|
126
|
+
"auto_mute_admin_groups": {}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## 🎉 使用
|
|
131
|
+
|
|
132
|
+
### 指令表
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
📋 系统状态
|
|
136
|
+
• px status — 查看完整状态
|
|
137
|
+
• px activity — 参与度和延迟计时器
|
|
138
|
+
|
|
139
|
+
👥 群组管理
|
|
140
|
+
• px group — 查看已启用群组
|
|
141
|
+
• px group add <群号> — 启用
|
|
142
|
+
• px group del <群号> — 禁用
|
|
143
|
+
• px group prob <群号> — 查看独立参与度
|
|
144
|
+
• px group prob <群号> set <0-1> — 设置
|
|
145
|
+
• px group prob <群号> reset — 恢复全局
|
|
146
|
+
|
|
147
|
+
🔧 AI 配置
|
|
148
|
+
• px ai — 查看配置
|
|
149
|
+
• px ai add <名> <key> <url> <模型> [1=思考] — 添加
|
|
150
|
+
• px ai del <名> — 删除
|
|
151
|
+
• px ai switch <名> — 切换聊天配置
|
|
152
|
+
• px image switch <名> — 切换识图配置
|
|
153
|
+
|
|
154
|
+
⚙️ 功能开关
|
|
155
|
+
• px chat on/off
|
|
156
|
+
• px search on/off
|
|
157
|
+
• px image on/off
|
|
158
|
+
• px mcp on/off
|
|
159
|
+
• px mcp server <名> on/off
|
|
160
|
+
• px mcp refresh
|
|
161
|
+
• px mcp tools
|
|
162
|
+
|
|
163
|
+
🔇 自动禁言
|
|
164
|
+
• px mute — 查看状态
|
|
165
|
+
• px mute on/off — 开关
|
|
166
|
+
• px mute duration <最小> <最大> — 时长(秒)
|
|
167
|
+
• px mute cooldown <秒> — 群冷却
|
|
168
|
+
• px mute check — 检测管理员权限
|
|
169
|
+
|
|
170
|
+
🎭 人设
|
|
171
|
+
• px personality
|
|
172
|
+
• px personality set <内容>
|
|
173
|
+
|
|
174
|
+
📊 参与度
|
|
175
|
+
• px prob
|
|
176
|
+
• px prob set <0-1>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### 🧠 思考模式
|
|
180
|
+
|
|
181
|
+
添加配置时第 6 参数传 `1` 开启,群聊判断+回复合并为一次 API 调用:
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
px ai add my_model sk-xxx https://api.example.com gpt-4 1
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 📈 智能参与机制
|
|
188
|
+
|
|
189
|
+
**三层决策**:
|
|
190
|
+
1. 模型 `should_reply` — 语义层面判断是否该说话
|
|
191
|
+
2. 动态门槛 `threshold = max(0.50, 1.0 - 参与度×0.5)` — 参与度越高门槛越低
|
|
192
|
+
3. 连续回复惩罚 `+0.10/轮` — 说越多话越难继续说
|
|
193
|
+
|
|
194
|
+
模型说"不回"→直接拒绝;模型说"回"+ 置信度达标→回复。
|
|
195
|
+
|
|
196
|
+
**参与度变化**:
|
|
197
|
+
- 被@或回复后 → boost 至 `base×1.2`(上限 0.80),保持 30s
|
|
198
|
+
- 30s 后恢复基础值,每 60s 衰减 0.1,下限为基础值 ×20%
|
|
199
|
+
- 30s 内≥10 条消息 → 突发重置至基础值
|
|
200
|
+
|
|
201
|
+
### 🎭 短期状态系统
|
|
202
|
+
|
|
203
|
+
每群独立追踪:
|
|
204
|
+
|
|
205
|
+
| 状态 | 变化规则 | 效果 |
|
|
206
|
+
|------|----------|------|
|
|
207
|
+
| 连续回复轮数 | 回复+1 / 跳过-1 | ≥3→提示简短,≥5→提示淡出 |
|
|
208
|
+
| 精力值 | 回复-0.12 / 每60s+0.10 | 低精力→倾向跳过 |
|
|
209
|
+
| 话题兴趣度 | 话题延续+0.08 / 切换-0.3 | 影响参与意愿 |
|
|
210
|
+
|
|
211
|
+
### 👤 群成员记忆
|
|
212
|
+
|
|
213
|
+
自动记录每用户:发言次数、互动次数、高频关键词、6 小时内最近消息、互动摘要。判断时优先注入近期互动用户(最多 4 人),使对话有"认识你"的真实感。
|
|
214
|
+
|
|
215
|
+
### 🔇 自动禁言
|
|
216
|
+
|
|
217
|
+
Bot 需拥有群管理员权限(自动检测或手动配置)。模型在判断过程中可建议禁言(刷屏/辱骂/广告)。系统自动检测权限、执行禁言、控制冷却和时长。
|
|
218
|
+
|
|
219
|
+
### ⚡ Token 优化
|
|
220
|
+
|
|
221
|
+
- Prompt 压缩约 45%(去除冗余表述)
|
|
222
|
+
- 判断上下文 12 条消息
|
|
223
|
+
- 记忆提示 4 人,精简格式
|
|
224
|
+
- 非思考模型判断后回复跳过人设重复
|
|
225
|
+
- 工具调用与回复合并为一请求
|
|
226
|
+
- FC 工具缓存 30s
|
|
227
|
+
- 记忆写入 30s 节流
|
|
228
|
+
|
|
229
|
+
### 🏗️ 项目结构
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
src/nonebot_plugin_pxchat_enhanced/
|
|
233
|
+
├── __init__.py # 入口:元数据、消息路由、延迟计时器、图片处理、关闭钩子
|
|
234
|
+
├── chat.py # AI 交互:Prompt 构建、回复判断、回复生成、工具调用
|
|
235
|
+
├── context.py # 对话上下文:20 条窗口 + 已判断去重
|
|
236
|
+
├── memory.py # 群成员记忆:统计/关键词/互动摘要/6h消息缓存
|
|
237
|
+
├── state.py # 短期状态:连续回复/精力/话题兴趣追踪
|
|
238
|
+
├── engagement.py # 参与度:boost/衰减/突发检测
|
|
239
|
+
├── admin.py # 群管理:权限检测、禁言 API
|
|
240
|
+
├── manager.py # 配置中心:AI/人设/开关/禁言/参与度
|
|
241
|
+
├── commands.py # px 命令组
|
|
242
|
+
├── mcp_manager.py # MCP 工具发现与调用
|
|
243
|
+
├── image2txt.py # 多模态图片识别
|
|
244
|
+
├── send2root.py # 合并转发/错误通知
|
|
245
|
+
├── config.py # Pydantic 配置模型
|
|
246
|
+
└── log.py # 日志记录器
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## 🎨 效果图
|
|
250
|
+
|
|
251
|
+
| 群聊参与 | 图片识别 | MCP 联网 |
|
|
252
|
+
|:---:|:---:|:---:|
|
|
253
|
+
|  |  |  |
|
|
254
|
+
|
|
255
|
+
| 模型切换 | 参与度状态 | 主流程 |
|
|
256
|
+
|:---:|:---:|:---:|
|
|
257
|
+
|  |  |  |
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://v2.nonebot.dev/store">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/fllesser/nonebot-plugin-template/refs/heads/resource/.docs/NoneBotPlugin.svg" width="310" alt="logo"></a>
|
|
4
|
+
|
|
5
|
+
## ✨ nonebot-plugin-pxchat-enhanced ✨
|
|
6
|
+
[](https://www.python.org)
|
|
7
|
+
[](https://github.com/astral-sh/uv)
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
## 📖 介绍
|
|
11
|
+
|
|
12
|
+
基于 AI 大模型的拟人化聊天插件。不只是"回答问题",而是像一个真实群友一样——会判断什么时候该说话、记得你是谁、有情绪起伏、会累会沉默。
|
|
13
|
+
|
|
14
|
+
安装后使用 `px about` 查看完整帮助,所有功能均可通过聊天指令配置。
|
|
15
|
+
|
|
16
|
+
## ✨ 核心特性
|
|
17
|
+
|
|
18
|
+
- **多模型切换** — 支持配置多个兼容 OpenAI API 的模型,聊天和图片识别可分别指定
|
|
19
|
+
- **上下文记忆** — 自动维护最近 20 条对话,群聊和私聊独立上下文
|
|
20
|
+
- **智能参与** — 模型自主判断是否回复 + 置信度过滤 + 动态参与度门槛,三层决策
|
|
21
|
+
- **短期状态** — 追踪连续回复轮数、精力值、话题兴趣度,模拟真人"想说话/不想说话"
|
|
22
|
+
- **群成员记忆** — 记录发言统计、关键词、互动摘要、6小时消息缓存,回复时自然注入
|
|
23
|
+
- **延迟回复** — 群聊非@消息 15-20s 后判断,@消息 3-5s,延迟值复用不重新随机
|
|
24
|
+
- **打字节奏** — 模型输出 `fast`/`normal`/`slow` 控制分段间隔
|
|
25
|
+
- **精确引用** — 消息渲染带完整 msg_id,模型可指定引用具体消息
|
|
26
|
+
- **思考模式** — reasoning 模型一次调用完成判断+回复,节省 Token
|
|
27
|
+
- **图片识别** — 多模态模型,群聊延迟识别、私聊即时
|
|
28
|
+
- **MCP 工具** — SSE/stdio,工具调用与回复合为一请求
|
|
29
|
+
- **自动禁言** — 模型判断→权限检测→执行,冷却+时长可配
|
|
30
|
+
- **突发检测** — 30s 内≥10 条消息自动重置参与度
|
|
31
|
+
- **消息感知** — 识别 @、回复引用、卡片(json/分享/小程序/markdown)
|
|
32
|
+
- **Token 优化** — 压缩 Prompt、12 条上下文、4 人记忆、合并调用
|
|
33
|
+
|
|
34
|
+
## 💿 安装
|
|
35
|
+
|
|
36
|
+
<details open>
|
|
37
|
+
<summary>[推荐] 使用 nb-cli 安装</summary>
|
|
38
|
+
|
|
39
|
+
```shell
|
|
40
|
+
nb plugin install nonebot-plugin-pxchat-enhanced
|
|
41
|
+
```
|
|
42
|
+
</details>
|
|
43
|
+
|
|
44
|
+
<details>
|
|
45
|
+
<summary>使用包管理器安装</summary>
|
|
46
|
+
|
|
47
|
+
```shell
|
|
48
|
+
pip install nonebot-plugin-pxchat-enhanced
|
|
49
|
+
# or
|
|
50
|
+
uv add nonebot-plugin-pxchat-enhanced
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
然后在 `pyproject.toml` 中追加:
|
|
54
|
+
```toml
|
|
55
|
+
[tool.nonebot]
|
|
56
|
+
plugins = ["nonebot_plugin_pxchat_enhanced"]
|
|
57
|
+
```
|
|
58
|
+
</details>
|
|
59
|
+
|
|
60
|
+
## ⚙️ 配置
|
|
61
|
+
|
|
62
|
+
在 `.env` 中添加必要配置,其余均可通过聊天指令设置:
|
|
63
|
+
|
|
64
|
+
| 配置项 | 必填 | 默认值 | 说明 |
|
|
65
|
+
|:------:|:---:|:-----:|------|
|
|
66
|
+
| `pxchat_super_users` | 是 | 无 | 超级用户列表,如 `["123456"]` |
|
|
67
|
+
| `pxchat_mcp` | 否 | 无 | MCP 服务器配置 |
|
|
68
|
+
|
|
69
|
+
配置示例:
|
|
70
|
+
```shell
|
|
71
|
+
pxchat_super_users=["123456"]
|
|
72
|
+
|
|
73
|
+
pxchat_mcp='{
|
|
74
|
+
"web_search": {
|
|
75
|
+
"type": "sse",
|
|
76
|
+
"url": "https://dashscope.aliyuncs.com/api/v1/mcps/WebSearch/sse",
|
|
77
|
+
"headers": {"Authorization": "Bearer your-api-key"},
|
|
78
|
+
"enabled": true
|
|
79
|
+
}
|
|
80
|
+
}'
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
持久化配置结构(由指令自动维护,无需手动编辑):
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"super_users": ["QQ号"],
|
|
87
|
+
"enabled_groups": ["群号"],
|
|
88
|
+
"chat_enabled": true,
|
|
89
|
+
"group_chat_probability": 1,
|
|
90
|
+
"group_probabilities": {},
|
|
91
|
+
"personality": "你叫px,是被困在服务器中的ai程序...",
|
|
92
|
+
"ai_configs": [
|
|
93
|
+
{
|
|
94
|
+
"name": "ds-chat",
|
|
95
|
+
"api_key": "sk-xxx",
|
|
96
|
+
"api_url": "https://api.deepseek.com",
|
|
97
|
+
"model": "deepseek-chat",
|
|
98
|
+
"thinking": false
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
"current_ai_config": 0,
|
|
102
|
+
"image_recognition_enabled": false,
|
|
103
|
+
"current_image_recognition_config": 0,
|
|
104
|
+
"enable_search": false,
|
|
105
|
+
"mcp_enabled": false,
|
|
106
|
+
"mcp_servers": {},
|
|
107
|
+
"auto_mute_enabled": false,
|
|
108
|
+
"auto_mute_min_duration": 60,
|
|
109
|
+
"auto_mute_max_duration": 600,
|
|
110
|
+
"auto_mute_cooldown": 300,
|
|
111
|
+
"auto_mute_admin_groups": {}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## 🎉 使用
|
|
116
|
+
|
|
117
|
+
### 指令表
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
📋 系统状态
|
|
121
|
+
• px status — 查看完整状态
|
|
122
|
+
• px activity — 参与度和延迟计时器
|
|
123
|
+
|
|
124
|
+
👥 群组管理
|
|
125
|
+
• px group — 查看已启用群组
|
|
126
|
+
• px group add <群号> — 启用
|
|
127
|
+
• px group del <群号> — 禁用
|
|
128
|
+
• px group prob <群号> — 查看独立参与度
|
|
129
|
+
• px group prob <群号> set <0-1> — 设置
|
|
130
|
+
• px group prob <群号> reset — 恢复全局
|
|
131
|
+
|
|
132
|
+
🔧 AI 配置
|
|
133
|
+
• px ai — 查看配置
|
|
134
|
+
• px ai add <名> <key> <url> <模型> [1=思考] — 添加
|
|
135
|
+
• px ai del <名> — 删除
|
|
136
|
+
• px ai switch <名> — 切换聊天配置
|
|
137
|
+
• px image switch <名> — 切换识图配置
|
|
138
|
+
|
|
139
|
+
⚙️ 功能开关
|
|
140
|
+
• px chat on/off
|
|
141
|
+
• px search on/off
|
|
142
|
+
• px image on/off
|
|
143
|
+
• px mcp on/off
|
|
144
|
+
• px mcp server <名> on/off
|
|
145
|
+
• px mcp refresh
|
|
146
|
+
• px mcp tools
|
|
147
|
+
|
|
148
|
+
🔇 自动禁言
|
|
149
|
+
• px mute — 查看状态
|
|
150
|
+
• px mute on/off — 开关
|
|
151
|
+
• px mute duration <最小> <最大> — 时长(秒)
|
|
152
|
+
• px mute cooldown <秒> — 群冷却
|
|
153
|
+
• px mute check — 检测管理员权限
|
|
154
|
+
|
|
155
|
+
🎭 人设
|
|
156
|
+
• px personality
|
|
157
|
+
• px personality set <内容>
|
|
158
|
+
|
|
159
|
+
📊 参与度
|
|
160
|
+
• px prob
|
|
161
|
+
• px prob set <0-1>
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 🧠 思考模式
|
|
165
|
+
|
|
166
|
+
添加配置时第 6 参数传 `1` 开启,群聊判断+回复合并为一次 API 调用:
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
px ai add my_model sk-xxx https://api.example.com gpt-4 1
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### 📈 智能参与机制
|
|
173
|
+
|
|
174
|
+
**三层决策**:
|
|
175
|
+
1. 模型 `should_reply` — 语义层面判断是否该说话
|
|
176
|
+
2. 动态门槛 `threshold = max(0.50, 1.0 - 参与度×0.5)` — 参与度越高门槛越低
|
|
177
|
+
3. 连续回复惩罚 `+0.10/轮` — 说越多话越难继续说
|
|
178
|
+
|
|
179
|
+
模型说"不回"→直接拒绝;模型说"回"+ 置信度达标→回复。
|
|
180
|
+
|
|
181
|
+
**参与度变化**:
|
|
182
|
+
- 被@或回复后 → boost 至 `base×1.2`(上限 0.80),保持 30s
|
|
183
|
+
- 30s 后恢复基础值,每 60s 衰减 0.1,下限为基础值 ×20%
|
|
184
|
+
- 30s 内≥10 条消息 → 突发重置至基础值
|
|
185
|
+
|
|
186
|
+
### 🎭 短期状态系统
|
|
187
|
+
|
|
188
|
+
每群独立追踪:
|
|
189
|
+
|
|
190
|
+
| 状态 | 变化规则 | 效果 |
|
|
191
|
+
|------|----------|------|
|
|
192
|
+
| 连续回复轮数 | 回复+1 / 跳过-1 | ≥3→提示简短,≥5→提示淡出 |
|
|
193
|
+
| 精力值 | 回复-0.12 / 每60s+0.10 | 低精力→倾向跳过 |
|
|
194
|
+
| 话题兴趣度 | 话题延续+0.08 / 切换-0.3 | 影响参与意愿 |
|
|
195
|
+
|
|
196
|
+
### 👤 群成员记忆
|
|
197
|
+
|
|
198
|
+
自动记录每用户:发言次数、互动次数、高频关键词、6 小时内最近消息、互动摘要。判断时优先注入近期互动用户(最多 4 人),使对话有"认识你"的真实感。
|
|
199
|
+
|
|
200
|
+
### 🔇 自动禁言
|
|
201
|
+
|
|
202
|
+
Bot 需拥有群管理员权限(自动检测或手动配置)。模型在判断过程中可建议禁言(刷屏/辱骂/广告)。系统自动检测权限、执行禁言、控制冷却和时长。
|
|
203
|
+
|
|
204
|
+
### ⚡ Token 优化
|
|
205
|
+
|
|
206
|
+
- Prompt 压缩约 45%(去除冗余表述)
|
|
207
|
+
- 判断上下文 12 条消息
|
|
208
|
+
- 记忆提示 4 人,精简格式
|
|
209
|
+
- 非思考模型判断后回复跳过人设重复
|
|
210
|
+
- 工具调用与回复合并为一请求
|
|
211
|
+
- FC 工具缓存 30s
|
|
212
|
+
- 记忆写入 30s 节流
|
|
213
|
+
|
|
214
|
+
### 🏗️ 项目结构
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
src/nonebot_plugin_pxchat_enhanced/
|
|
218
|
+
├── __init__.py # 入口:元数据、消息路由、延迟计时器、图片处理、关闭钩子
|
|
219
|
+
├── chat.py # AI 交互:Prompt 构建、回复判断、回复生成、工具调用
|
|
220
|
+
├── context.py # 对话上下文:20 条窗口 + 已判断去重
|
|
221
|
+
├── memory.py # 群成员记忆:统计/关键词/互动摘要/6h消息缓存
|
|
222
|
+
├── state.py # 短期状态:连续回复/精力/话题兴趣追踪
|
|
223
|
+
├── engagement.py # 参与度:boost/衰减/突发检测
|
|
224
|
+
├── admin.py # 群管理:权限检测、禁言 API
|
|
225
|
+
├── manager.py # 配置中心:AI/人设/开关/禁言/参与度
|
|
226
|
+
├── commands.py # px 命令组
|
|
227
|
+
├── mcp_manager.py # MCP 工具发现与调用
|
|
228
|
+
├── image2txt.py # 多模态图片识别
|
|
229
|
+
├── send2root.py # 合并转发/错误通知
|
|
230
|
+
├── config.py # Pydantic 配置模型
|
|
231
|
+
└── log.py # 日志记录器
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## 🎨 效果图
|
|
235
|
+
|
|
236
|
+
| 群聊参与 | 图片识别 | MCP 联网 |
|
|
237
|
+
|:---:|:---:|:---:|
|
|
238
|
+
|  |  |  |
|
|
239
|
+
|
|
240
|
+
| 模型切换 | 参与度状态 | 主流程 |
|
|
241
|
+
|:---:|:---:|:---:|
|
|
242
|
+
|  |  |  |
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "nonebot-plugin-pxchat-enhanced"
|
|
3
|
+
version = "2.0.0"
|
|
4
|
+
description = "基于AI大模型的拟人化聊天插件,支持多模型切换、上下文记忆、群聊智能参与、短期状态追踪、群成员记忆、图片识别、MCP工具调用、自动禁言等功能"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [{ name = "Srythm", email = "2074447320@qq.com" }]
|
|
7
|
+
urls = { Repository = "https://github.com/Srythm/nonebot-plugin-pxchat-enhanced" }
|
|
8
|
+
requires-python = ">=3.10"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"nonebot2>=2.4.3,<3.0.0",
|
|
11
|
+
"nonebot-adapter-onebot>=2.4.6,<3.0.0",
|
|
12
|
+
"openai>=2.2.0",
|
|
13
|
+
"mcp>=1.16.0",
|
|
14
|
+
"nonebot-plugin-localstore>=0.7.3",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[tool.nonebot]
|
|
18
|
+
plugins = ["nonebot_plugin_pxchat_enhanced"]
|
|
19
|
+
|
|
20
|
+
[dependency-groups]
|
|
21
|
+
dev = [
|
|
22
|
+
"nonebot2[fastapi]>=2.4.3",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[build-system]
|
|
26
|
+
requires = ["uv_build>=0.8.14,<0.9.0"]
|
|
27
|
+
build-backend = "uv_build"
|