nonebot-plugin-aigf 0.2.0__tar.gz → 0.3.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.
Files changed (19) hide show
  1. {nonebot-plugin-aigf-0.2.0/nonebot_plugin_aigf.egg-info → nonebot-plugin-aigf-0.3.0}/PKG-INFO +70 -32
  2. nonebot-plugin-aigf-0.2.0/PKG-INFO → nonebot-plugin-aigf-0.3.0/README.md +329 -304
  3. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/nonebot_plugin_aigf/__init__.py +54 -9
  4. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/nonebot_plugin_aigf/image_manager.py +6 -4
  5. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/nonebot_plugin_aigf/meme_manager.py +9 -7
  6. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/nonebot_plugin_aigf/memory.py +54 -2
  7. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/nonebot_plugin_aigf/presets.py +4 -2
  8. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/nonebot_plugin_aigf/session.py +139 -72
  9. nonebot-plugin-aigf-0.2.0/README.md → nonebot-plugin-aigf-0.3.0/nonebot_plugin_aigf.egg-info/PKG-INFO +342 -291
  10. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/setup.py +1 -1
  11. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/nonebot_plugin_aigf/client.py +0 -0
  12. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/nonebot_plugin_aigf/config.py +0 -0
  13. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/nonebot_plugin_aigf/mem.py +0 -0
  14. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/nonebot_plugin_aigf/vlm.py +0 -0
  15. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/nonebot_plugin_aigf.egg-info/SOURCES.txt +0 -0
  16. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/nonebot_plugin_aigf.egg-info/dependency_links.txt +0 -0
  17. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/nonebot_plugin_aigf.egg-info/requires.txt +0 -0
  18. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/nonebot_plugin_aigf.egg-info/top_level.txt +0 -0
  19. {nonebot-plugin-aigf-0.2.0 → nonebot-plugin-aigf-0.3.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nonebot-plugin-aigf
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: 基于nonebot-plugin-nyaturingtest重构的群聊特化 LLM 聊天机器人,具有 LLM 驱动的记忆系统和表情包功能。
5
5
  Home-page: https://github.com/Funny1Potato/nonebot-plugin-aigf
6
6
  Author: Funny1Potato
@@ -15,7 +15,7 @@ Description-Content-Type: text/markdown
15
15
  <a href="https://v2.nonebot.dev/store">
16
16
  <img src="https://raw.githubusercontent.com/fllesser/nonebot-plugin-template/refs/heads/resource/.docs/NoneBotPlugin.svg" width="310" alt="logo"></a>
17
17
 
18
- ## ✨ nonebot-plugin-aigf
18
+ ## ✨ AI-group-friend
19
19
 
20
20
  群聊特化 LLM 聊天机器人,具有 LLM 驱动的记忆系统和表情包功能。
21
21
 
@@ -30,14 +30,16 @@ Description-Content-Type: text/markdown
30
30
  ## 📖 介绍
31
31
 
32
32
  > 基于 [shadow3aaa/nonebot-plugin-nyaturingtest](https://github.com/shadow3aaa/nonebot-plugin-nyaturingtest) 重构,移除了 HippoRAG 和情绪系统,改为 LLM 自主管理记忆,并添加表情包存储和发送功能。
33
+ * 本项目对原项目代码的修改及重构均有AI高度参与,若有做得不够好的地方,请手下留情。
33
34
 
34
35
  ### 特点:
35
36
 
36
37
  - 🧠 **LLM 驱动的记忆系统**:短期记忆、长期记忆、群友信息,LLM 自主增删改
37
38
  - 🖼️ **表情包功能**:AI 自主决定发表情包;自动从群聊中收藏表情包(缓存机制)
38
- - 🔍 **图片理解**:通过 VLM 或多模态大模型理解群友发的图片和表情包
39
+ - 🔍 **图片理解**:支持 VLM 模式和 LLM 直接看图模式
40
+ - 💬 **对话理解**:通过 reply 标记和 @ 理解群聊中的对话关系,自主决定是否发言
39
41
  - 📝 **预设系统**:支持角色预设,含可编辑的默认预设
40
- - ⚡ **轻量高效**:单次 LLM 调用完成对话 + 记忆管理,减少token消耗
42
+ - ⚡ **轻量高效**:单次 LLM 调用完成对话 + 记忆管理,节约token
41
43
 
42
44
  ## 💿 安装
43
45
 
@@ -77,22 +79,21 @@ plugins = ["nonebot-plugin-aigf"]
77
79
  ```env
78
80
  # === 必填 ===
79
81
  AIGF_CHAT_OPENAI_API_KEY="***" # LLM API Key
80
- AIGF_CHAT_OPENAI_BASE_URL="***" # LLM API 地址
81
- AIGF_CHAT_OPENAI_MODEL="***" # LLM 模型名称
82
+ AIGF_CHAT_OPENAI_BASE_URL="***" # LLM API 地址
83
+ AIGF_CHAT_OPENAI_MODEL="***" # LLM 模型名称
84
+ AIGF_ENABLED_GROUPS=[123456, 789012] # 启用的群号列表
82
85
 
83
86
  # === 可选 ===
84
- AIGF_ENABLED_GROUPS=[123456, 789012] # 启用的群号列表
85
87
  AIGF_MEME_ENABLED=true # 是否启用表情包功能(默认 true)
86
88
  AIGF_MEME_MAX_COUNT=200 # 自动收集的表情包最大数量(默认 200)
87
89
  AIGF_DEFAULT_PRESET=default # 默认预设名称(默认 "default")
88
90
 
89
91
  # === VLM 配置(图片理解) ===
90
- # === 图片理解 ===
91
92
  AIGF_IMAGE_MODE="vlm" # 图片模式: vlm=独立VLM分析, llm=LLM直接看图
92
- AIGF_VLM_ENABLED=true # 是否启用VLM(仅 vlm 模式有效,默认 true)
93
- AIGF_VLM_MODEL="Pro/Qwen/Qwen2.5-VL-7B-Instruct" # VLM 模型名称
93
+ AIGF_VLM_ENABLED=true # 是否启用VLM(仅 vlm 模式有效,默认 true)
94
+ AIGF_VLM_MODEL="Pro/Qwen/Qwen2.5-VL-7B-Instruct" # VLM 模型名称
94
95
  AIGF_VLM_BASE_URL="https://api.siliconflow.cn/v1" # VLM API 地址
95
- AIGF_VLM_API_KEY="***" # VLM API Key(为空时使用 chat 的 key)
96
+ AIGF_VLM_API_KEY="***" # VLM API Key(为空时使用 chat 的 key)
96
97
  ```
97
98
 
98
99
  ## 命令
@@ -110,24 +111,56 @@ AIGF_VLM_API_KEY="***" # VLM API Key(为空时使用
110
111
  ## 触发机制
111
112
 
112
113
  - 攒够 **5 条**新消息,或最后一条消息后 **5 秒**内无新消息,触发一次处理
113
- - 每次处理时,LLM 收到最近 **10 条**聊天记录 + 三层记忆 + 预设 + 表情包列表
114
+ - 每次处理时,LLM 收到最近 **15 条**聊天记录 + 三层记忆 + 预设 + 表情包列表
114
115
  - LLM 一次调用同时完成:回复决策 + 记忆管理 + 表情包选择
115
116
 
117
+ ## 对话理解
118
+
119
+ 机器人通过以下方式理解群聊中的对话关系:
120
+
121
+ - **reply 标记**:消息中包含 `[回复 xxx 的消息: "yyy"]`,表示在回复某人
122
+ - **@ 提及**:`@某人` 表示消息是发给那个人的
123
+ - **时间推断**:时间接近的消息通常在互相回复
124
+
125
+ **回复决策规则**:
126
+ - 有人 @ 了机器人 → 回复
127
+ - 有人回复了机器人之前的消息 → 回复
128
+ - 消息明显是对所有人说的,且有值得补充的内容 → 回复
129
+ - 不确定是否在和自己说话 → **不回复**
130
+
116
131
  ## 记忆系统
117
132
 
118
133
  机器人拥有三层记忆,由 LLM 在每次回复时自主管理:
119
134
 
120
135
  ### 短期记忆
121
136
 
122
- 存储在 `<插件数据目录>/memory/short_term.json`,内容为 LLM 维护的信息列表,包括对话摘要、临时上下文、有趣的梗等。LLM 可以添加、修改、删除条目,内容可以详细一些。
137
+ 存储在 `<插件数据目录>/memory/<群号>/short_term.json`,内容为 LLM 维护的信息列表,包括对话摘要、临时上下文、有趣的梗等。LLM 可以添加、修改、删除条目。
123
138
 
124
139
  ### 长期记忆
125
140
 
126
- 存储在 `<插件数据目录>/memory/long_term.json`,内容为 LLM 认为值得长期记住的信息,如群内发生的事件、群规、群友分享的有用知识等。
141
+ 存储在 `<插件数据目录>/memory/<群号>/long_term.json`,内容为 LLM 认为值得长期记住的信息,如群内发生的事件、群规、群友分享的有用知识等。LLM 可添加、修改、删除。不应记录临时对话或常识信息。
127
142
 
128
143
  ### 群友信息
129
144
 
130
- 存储在 `<插件数据目录>/memory/friends/<QQ号>.json`,每个群友一个文件,以 QQ 号命名。LLM 记录群友的昵称、职业、爱好、说过的话、与其他群友的关系等。当群友修改昵称时,LLM 可通过 `update_name` 更新。
145
+ 存储在 `<插件数据目录>/memory/friends/<QQ号>.json`,每个群友一个文件,以 QQ 号命名。LLM 记录群友的昵称、职业、爱好、说过的话、与其他群友的关系等。具体保存方式如下:
146
+ ```json
147
+ {
148
+ "id": "123456",
149
+ "nickname": "小明",
150
+ "aliases": ["小明哥", "明酱"],
151
+ "past_nicknames": ["明明"],
152
+ "info": ["职业:程序员", "爱好:打游戏"],
153
+ "groups": ["114514","1919810"]
154
+ }
155
+ ```
156
+
157
+ | 字段 | 来源 | 说明 |
158
+ |------|------|------|
159
+ | `nickname` | 系统自动更新 | QQ 全局昵称 |
160
+ | `aliases` | LLM 管理 | 群友对 ta 的称呼 |
161
+ | `past_nicknames` | 系统自动记录 | 曾用 QQ 昵称,便于从记忆中识别人物 |
162
+ | `info` | LLM 管理 | 一般信息(职业、爱好等) |
163
+ | `groups` | 系统自动维护 | 所在的群列表 |
131
164
 
132
165
  ## 表情包功能
133
166
 
@@ -184,31 +217,19 @@ memes/
184
217
 
185
218
  机器人收到图片时,VLM 分析后保存到缓存。LLM 在回复时看到缓存的表情包,决定是否收藏:
186
219
 
187
- ```json
188
- {
189
- "memory": {
190
- "save_meme": {"id": "a1b2c3d4e5f6", "description": "开心转圈的小人"}
191
- }
192
- }
193
- ```
194
-
195
- 支持一次收藏多个:
196
220
  ```json
197
221
  {
198
222
  "memory": {
199
223
  "save_meme": [
200
- {"id": "a1b2c3d4e5f6", "description": "开心转圈"},
201
- {"id": "e7f8g9h0i1j2", "description": "气鼓鼓"}
224
+ {"id": "a1b2c3d4e5f6", "description": "开心转圈的小人", "keywords": ["开心"]}
202
225
  ]
203
226
  }
204
227
  }
205
228
  ```
206
229
 
207
- #### 缓存机制
208
-
209
- - 图片缓存在 `<缓存目录>/sticker_cache/`,用图片内容的 MD5 作文件名,自动去重
210
- - 超过 7 天的缓存文件会自动清理
211
- - 自动收集的表情包超过 `AIGF_MEME_MAX_COUNT` 上限时,优先清理最近未使用的
230
+ - 图片按 MD5 hash 去重
231
+ - 超过 `AIGF_MEME_MAX_COUNT` 上限时,优先清理最近未使用的
232
+ - 缓存中的表情包只处理一次,处理后清空
212
233
 
213
234
  #### 发送表情包
214
235
 
@@ -218,6 +239,17 @@ LLM 在回复中指定表情包 id(来自 memes.json 或 collected.json):
218
239
  {"type": "meme", "id": "happy_spin"}
219
240
  ```
220
241
 
242
+ ## 图片理解模式
243
+
244
+ 通过 `AIGF_IMAGE_MODE` 配置:
245
+
246
+ | 模式 | 流程 | 适用场景 |
247
+ |------|------|---------|
248
+ | `vlm`(默认) | 图片 → VLM 分析 → 文字描述给 LLM | LLM 不支持图片输入 |
249
+ | `llm` | 图片 → base64 直接附在 LLM prompt 中 | LLM 支持视觉(GPT-4o 等) |
250
+
251
+ VLM 模式下,描述限制 50 字,情感只输出 3 个词,不识别具体角色名称(只描述外貌特征)。
252
+
221
253
  ## 预设系统
222
254
 
223
255
  首次运行后在 `<插件配置目录>/presets/` 下生成 `default.json`:
@@ -268,7 +300,7 @@ LLM 支持以下回复类型:
268
300
  | @ | `{"type": "at", "name": "群友昵称"}` | 艾特群友 |
269
301
  | 表情包 | `{"type": "meme", "id": "表情包id"}` | 发送表情包 |
270
302
 
271
- 文本和 @ 会合并为一条消息发送,表情包单独发送。也可以直接用纯字符串代替 `{"type": "text", "content": "..."}`。
303
+ 文本和 @ 会合并为一条消息发送,表情包单独发送。
272
304
 
273
305
  ## 图片理解模式
274
306
 
@@ -302,3 +334,9 @@ LLM 支持以下回复类型:
302
334
  - VLM API(图片理解,可选)
303
335
  - Pillow(图片处理)
304
336
  - httpx、anyio
337
+ - numpy
338
+
339
+ ## 一些碎碎念
340
+ - 本项目移除了原插件的 HippoRAG 和情绪系统,拟人程度远不如原插件
341
+ - 本项目的token消耗理论上相较原插件能减少约30-50%,但绝对值仍不低,每次请求约消耗 20K tokens,在记忆数据丰富之后会更高
342
+ - 推荐使用价格较为低廉的模型作为llm模型(群友就是要笨笨的才可爱呀),再以识图能力较好的vlm模型作为辅助(要是看不懂表情包还是会比较尴尬的)