nonebot-plugin-aigf-master 1.6.2__tar.gz → 1.6.3__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 (35) hide show
  1. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/PKG-INFO +44 -12
  2. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/README.md +43 -11
  3. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/__init__.py +5 -1
  4. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/config.py +3 -2
  5. nonebot_plugin_aigf_master-1.6.3/nonebot_plugin_aigf_master/message_builder.py +213 -0
  6. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/prompt_builder.py +3 -1
  7. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/search_client.py +58 -1
  8. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master.egg-info/PKG-INFO +44 -12
  9. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/pyproject.toml +1 -1
  10. nonebot_plugin_aigf_master-1.6.2/nonebot_plugin_aigf_master/message_builder.py +0 -92
  11. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/LICENSE +0 -0
  12. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/anime_recognizer.py +0 -0
  13. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/animetrace_client.py +0 -0
  14. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/api_hooks.py +0 -0
  15. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/cache_cleanup.py +0 -0
  16. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/command_learner.py +0 -0
  17. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/context_bus.py +0 -0
  18. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/image_gen_client.py +0 -0
  19. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/image_handler.py +0 -0
  20. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/llm_client.py +0 -0
  21. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/meme_store.py +0 -0
  22. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/memory_store.py +0 -0
  23. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/models.py +0 -0
  24. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/peer_client.py +0 -0
  25. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/plugin_discovery.py +0 -0
  26. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/plugin_invoker.py +0 -0
  27. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/preset_store.py +0 -0
  28. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/processor.py +0 -0
  29. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/response_parser.py +0 -0
  30. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master/vlm_client.py +0 -0
  31. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master.egg-info/SOURCES.txt +0 -0
  32. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master.egg-info/dependency_links.txt +0 -0
  33. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master.egg-info/requires.txt +0 -0
  34. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/nonebot_plugin_aigf_master.egg-info/top_level.txt +0 -0
  35. {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-plugin-aigf-master
3
- Version: 1.6.2
3
+ Version: 1.6.3
4
4
  Summary: 群聊特化LLM聊天机器人(增强版),具有记忆、表情包、跨插件调用和跨bot通信能力
5
5
  License-Expression: MIT
6
6
  Requires-Python: <4.0,>=3.10
@@ -32,6 +32,12 @@ Dynamic: license-file
32
32
  </p>
33
33
  </div>
34
34
 
35
+ > [!TIP]
36
+ > **有个跨适配器 beta 版正在测试中**:`2.0.0-beta` 已作为**预发布**发到 PyPI,消息收发与会话身份改走 `nonebot-plugin-alconna` / `nonebot-plugin-uninfo`,OneBot / Satori / Telegram / Discord 等适配器共用同一套聊天、记忆与命令逻辑。
37
+ > 稳定版仍是 **1.6.x**(`pip install` 与 `nb plugin install` 默认只会装稳定版),装 beta 必须显式写出版本号:
38
+ > `pip install nonebot-plugin-aigf-master==2.0.0b3`
39
+ > 最新版本号与支持边界见 [beta 分支的 README](https://github.com/Funny1Potato/nonebot-plugin-aigf-master/tree/beta)。
40
+
35
41
  ## 📖 介绍
36
42
 
37
43
  一个基于 NoneBot2 的群聊 AI 助手插件,能够自主收集和发送表情包、联网搜索知识、对群内信息进行记忆,还能够感知同实例内其它插件的输出、通过 LLM 调用其它插件、自主学习群内命令用法,并能通过子插件与其它 bot 通信获取消息和远程调用命令。
@@ -44,7 +50,7 @@ Dynamic: license-file
44
50
  - 🧠 **LLM 命令学习**:通过观察群聊自动学习命令用法,支持学习、编辑、删除
45
51
  - 🌐 **跨 bot 通信**:通过 HTTP 获取其它 bot(同一 QQ 号下)的插件输出,并可远程调用其命令
46
52
  - 🖼️ **表情包功能**:AI 自主决定发表情包;自动从群聊中收藏
47
- - 🔍 **联网搜索**:支持 Tavily / Bocha / Bing,自动搜索不懂的梗和网络用语
53
+ - 🔍 **联网搜索**:支持 Tavily / Bocha / Bing / DeepSeek / 本地 open-websearch,自动搜索不懂的梗和网络用语
48
54
  - 🧠 **四层记忆系统**:短期记忆、长期记忆、群友信息、文化记忆,LLM 自主管理
49
55
  - 🎨 **AI 生图**:LLM可调用生图模型生成图片发到群里,尺寸由 LLM 决定(程序限最大尺寸),支持参考图改绘(回复图片消息或从聊天记录选图)
50
56
 
@@ -145,10 +151,11 @@ AIGFM_ENERGY_BASELINE=0.7 # 社交能量基线(默认 0.7,范
145
151
 
146
152
  # --- 联网搜索 ---
147
153
  AIGFM_SEARCH_ENABLED=false # 是否启用联网搜索(默认 false)
148
- AIGFM_SEARCH_API=tavily # 搜索API: tavily / bocha / bing / openwebsearch(默认 tavily)
149
- AIGFM_SEARCH_API_KEY="xxx" # 搜索 API Key(api=tavily/bocha/bing 时必填)
154
+ AIGFM_SEARCH_API=tavily # 搜索API: tavily / bocha / bing / openwebsearch / deepseek(默认 tavily)
155
+ AIGFM_SEARCH_API_KEY="xxx" # 搜索 API Key(api=tavily/bocha/bing 时必填;deepseek 留空则沿用 LLM Key)
150
156
  AIGFM_SEARCH_MAX_RESULTS=3 # 最大搜索结果数(默认 3)
151
157
  AIGFM_OPENWEBSEARCH_URL="" # open-websearch 本地服务地址(api=openwebsearch 时必填,如 http://127.0.0.1:3210)
158
+ AIGFM_SEARCH_BASE_URL="" # 搜索 API 根地址(api=deepseek 时用,留空则用官方 https://api.deepseek.com)
152
159
 
153
160
  # --- 代理 ---
154
161
  AIGFM_PROXY_ENABLED=false # 是否启用代理(默认 false)
@@ -187,7 +194,6 @@ AIGFM_ANIME_RECOGNIZE_MAX_CHARACTERS=3 # 展示的角色标签数量上限(
187
194
  AIGFM_ANIME_NSFW_THRESHOLD=0.5 # explicit 概率超过该值标注 [NSFW](默认 0.5;仅本地后端提供画风分级)
188
195
  AIGFM_ANIMETRACE_URL="https://api.animetrace.com" # AnimeTrace API 地址(公共 API、无需鉴权;识别会把图片上传到该服务)
189
196
  AIGFM_ANIMETRACE_TIMEOUT=20.0 # AnimeTrace 请求超时/秒(默认 20.0)
190
- AIGFM_ANIME_RECOGNIZE_ENABLED=false # 【已被 AIGFM_ANIME_BACKEND 取代,仅兼容保留】为 true 且 backend=off 时按 anime-recognize 处理
191
197
 
192
198
  # --- 缓存清理 ---
193
199
  AIGFM_IMAGE_CACHE_MAX_FILES=500 # 描述/角色识别缓存(image_cache 下的 JSON)最大数量,超出按 mtime 最旧删除(默认 500,0=不清理)
@@ -312,7 +318,7 @@ LLM 调用:invoke_plugin(command="决斗", parts=[
312
318
  ```
313
319
 
314
320
  - `command` **只放命令名本身**;要 @ 的群友、附加文字等一律放进 `parts`
315
- - `at` 段按**群昵称**解析(与聊天记录里的 `@昵称` 一致),也接受直接给 QQ 号;解析不出会跳过该段,并在工具回执里提示
321
+ - `at` 段按**群昵称或群名片**解析(与聊天记录里的 `@昵称` 一致),也接受直接给 QQ 号;解析不出会跳过该段,并在工具回执里提示
316
322
  - 各段之间由程序补**一个**空格,不需要也不用自己加空格(多写的空格会被规整,避免出现双空格导致参数解析失败)
317
323
 
318
324
  ### 调用限制
@@ -467,6 +473,7 @@ LLM 可以:
467
473
  | `bocha` | 国产 AI 搜索 API,中文搜索效果好 | 无 | https://open.bochaai.com |
468
474
  | `bing` | 微软必应搜索(Azure Bing Search API v7) | 无 | https://portal.azure.com |
469
475
  | `openwebsearch` | 本地 Node.js 搜索服务,聚合多引擎(bing/baidu/duckduckgo 等) | 需先启动 daemon:`cd open-webSearch && npm install && npm run serve`,配置 `AIGFM_OPENWEBSEARCH_URL` | 无需 Key,项目:https://github.com/Aas-ee/open-webSearch |
476
+ | `deepseek` | DeepSeek 自带联网搜索,摘要写得很适合喂给模型 | 无(`AIGFM_SEARCH_API_KEY` 留空则沿用 LLM Key) | https://platform.deepseek.com |
470
477
 
471
478
  > **Tavily** 需额外安装依赖:`pip install tavily-python`(或安装本插件时带上 extra:`pip install "nonebot-plugin-aigf-master[tavily]"`)
472
479
 
@@ -581,7 +588,7 @@ memes/
581
588
  | 后端 | 工作方式 | 擅长 | 代价 |
582
589
  |---|---|---|---|
583
590
  | `anime-recognize` | 本地 WD14 推理服务([aigfm-anime-recognize](https://github.com/Funny1Potato/aigfm-anime-recognize)),**需自行部署** | 动漫 / 手游角色,输出英文 booru 标签(如 `hu_tao_(genshin_impact)`)+ 数值置信度 + 画风分级 | 本地推理、免费无限量;**对 gal / 视觉小说角色识别率低** |
584
- | `animetrace` | [AnimeTrace](https://ai.animedb.cn/) 公共 API,**无需部署、无需鉴权** | gal / 视觉小说角色,并给出作品名(如「胡桃(原神)」) | 图片会上传到该第三方公共服务;有使用配额;不返回数值置信度、无画风分级 |
591
+ | `animetrace` | [AnimeTrace](https://ai.animedb.cn/) 公共 API,**无需部署、无需鉴权** | gal / 视觉小说角色,并给出作品名(如「胡桃(原神)」) | 图片会上传到该第三方公共服务;有使用配额;不返回数值置信度、无画风分级;对gal以外游戏角色的识别率一般 |
585
592
 
586
593
  `both` 模式先问本地服务,本地置信度不足(低于 `AIGFM_ANIME_RECOGNIZE_MIN_CONFIDENCE`)再问 AnimeTrace,两边都没有可信结果才渲染 `[角色识别: 未能识别]`——平时不消耗公共 API 配额。
587
594
 
@@ -592,8 +599,10 @@ memes/
592
599
  ```bash
593
600
  git clone https://github.com/Funny1Potato/aigfm-anime-recognize.git
594
601
  cd aigfm-anime-recognize
602
+ # 安装
595
603
  # Windows: install.bat ;Linux/macOS: chmod +x install.sh && ./install.sh
596
- # 一键完成:建虚拟环境 → 装钉版本依赖 → 下载模型(约 446MB)→ 启动服务(0.0.0.0:8000)
604
+ # 启动
605
+ # Windows: start.bat ; Linux / macOS: chmod +x start.sh && ./start.sh
597
606
  ```
598
607
 
599
608
  **插件配置**:
@@ -603,14 +612,14 @@ cd aigfm-anime-recognize
603
612
  AIGFM_ANIME_BACKEND=both
604
613
 
605
614
  # 本地后端地址(backend 含 anime-recognize 时必填;服务端未启用鉴权时 token 留空)
606
- AIGFM_ANIME_RECOGNIZE_URL=http://127.0.0.1:8000
615
+ AIGFM_ANIME_RECOGNIZE_URL="http://127.0.0.1:8000"
607
616
  # AIGFM_ANIME_RECOGNIZE_TOKEN=可选
608
617
 
609
618
  # 可选调参(默认值如下)
610
619
  # AIGFM_ANIME_RECOGNIZE_MIN_CONFIDENCE=0.85 # 展示角色标签的最低置信度;both 模式下也用它判断本地是否有结果
611
620
  # AIGFM_ANIME_RECOGNIZE_MAX_CHARACTERS=3 # 展示的角色标签数量上限
612
621
  # AIGFM_ANIME_NSFW_THRESHOLD=0.5 # explicit 概率超过该值标注 [NSFW](只标注不拦截;仅本地后端提供分级)
613
- # AIGFM_ANIMETRACE_URL=https://api.animetrace.com
622
+ # AIGFM_ANIMETRACE_URL="https://api.animetrace.com"
614
623
  # AIGFM_ANIMETRACE_TIMEOUT=20 # AnimeTrace 请求超时(秒)
615
624
  ```
616
625
 
@@ -632,8 +641,8 @@ AIGFM_ANIME_RECOGNIZE_URL=http://127.0.0.1:8000
632
641
  - 改 `AIGFM_ANIME_RECOGNIZE_MIN_CONFIDENCE` 只影响此后新识别的图片;已缓存图片要重新判定需删除其 `{md5}_anime.json`
633
642
 
634
643
  **已知局限**:
635
- - **本地后端**:训练数据截止 2024 年前后,新游/新角色可能认不出,**gal / 视觉小说角色识别率尤其低(建议改用 `animetrace` 或 `both`)**;多人合影会漏识别;皮肤/异格不区分;3D 战斗小人/游戏内截图识别率偏低;输出为英文标签(中文映射需自行扩展)
636
- - **AnimeTrace**:不返回数值置信度,只有服务自己的低置信判定——被判低置信时一律按「未能识别」处理,日志 `[角色识别] AnimeTrace 无可信结果,低置信候选: …` 会给出它认为最可能的候选,便于排查;其检测框可能包含误检,多人提示仅供参考;`[NSFW]` 标记只由本地后端提供
644
+ - **本地后端**:训练数据截止 2024 年前后,新游/新角色可能认不出,**gal / 视觉小说角色识别率尤其低(建议改用 `animetrace` 或 `both`)**;多人合影可能会漏识别;3D 战斗小人/游戏内截图识别率不高;输出为英文标签(中文映射需自行扩展)
645
+ - **AnimeTrace**:对gal以外的游戏角色识别率一般;不返回数值置信度,只有服务自己的低置信判定——被判低置信时一律按「未能识别」处理,日志 `[角色识别] AnimeTrace 无可信结果,低置信候选: …` 会给出它认为最可能的候选,便于排查;其检测框可能包含误检,多人提示仅供参考;`[NSFW]` 标记只由本地后端提供
637
646
  - 识别结果(角色名)会进入 LLM 上下文,也就是群里能看到;在意隐私请只用 `anime-recognize`(纯本地)或关闭本功能
638
647
 
639
648
  > 仅 `AIGFM_IMAGE_MODE=vlm` 模式生效;`llm` 模式图片不经过 VLM,无二次元判断。
@@ -663,6 +672,29 @@ LLM 支持以下回复类型:
663
672
  | @ | `{"type": "at", "name": "群友昵称"}` | 艾特群友 |
664
673
  | 表情包 | `{"type": "meme", "id": "表情包id"}` | 发送表情包 |
665
674
 
675
+ > 要 @ 群友时应使用独立的 `at` 段。为兼容部分模型误把 `@昵称` 写进文本的情况,发送前也会把能匹配到群成员的文本 @ 自动转换为真实 QQ @。
676
+
677
+ ## 📊 Token 消耗参考
678
+
679
+ 以下是一组实测值:测试群约 120 人、活跃约 15 人,平均每天 400 条消息,一个月合计约 3.6 亿 tokens。
680
+
681
+ | 周期 | 消息量 | Token 消耗 |
682
+ |------|--------|------------|
683
+ | 每日 | ≈ 400 条 | ≈ 12M(1200 万) |
684
+ | 每周(按 4.3 周) | ≈ 2,800 条 | ≈ 84M(8400 万) |
685
+ | 每月(30 天) | ≈ 12,000 条 | ≈ 360M(3.6 亿) |
686
+ | 摊到每条消息 | — | ≈ 30k |
687
+
688
+ 主要影响因素:
689
+
690
+ - **模型单价**:不同模型差别很大,建议先用便宜的模型跑量
691
+ - **图片**:`AIGFM_IMAGE_MODE=llm` 会把图片本体随请求发送,比默认的 `vlm`(另发一次识图请求)更贵
692
+ - **联网搜索 / 生图 / 插件调用**:会额外产生调用轮次
693
+ - **批次大小**:`AIGFM_BATCH_COUNT` / `AIGFM_BATCH_TIMEOUT` 攒得越多,单次请求里的上下文(历史、记忆、命令清单)越长,但**请求次数越少**;调小则相反
694
+ - **启用的会话数**:每个群/频道各自独立计费
695
+
696
+ 估算自己群的消耗:数日志里 `[处理] 群<群号> 调用 LLM` 的条数(= 调用次数),乘以服务商返回的平均 token 数即可。
697
+
666
698
  ## 📁 数据存储
667
699
 
668
700
  ```
@@ -12,6 +12,12 @@
12
12
  </p>
13
13
  </div>
14
14
 
15
+ > [!TIP]
16
+ > **有个跨适配器 beta 版正在测试中**:`2.0.0-beta` 已作为**预发布**发到 PyPI,消息收发与会话身份改走 `nonebot-plugin-alconna` / `nonebot-plugin-uninfo`,OneBot / Satori / Telegram / Discord 等适配器共用同一套聊天、记忆与命令逻辑。
17
+ > 稳定版仍是 **1.6.x**(`pip install` 与 `nb plugin install` 默认只会装稳定版),装 beta 必须显式写出版本号:
18
+ > `pip install nonebot-plugin-aigf-master==2.0.0b3`
19
+ > 最新版本号与支持边界见 [beta 分支的 README](https://github.com/Funny1Potato/nonebot-plugin-aigf-master/tree/beta)。
20
+
15
21
  ## 📖 介绍
16
22
 
17
23
  一个基于 NoneBot2 的群聊 AI 助手插件,能够自主收集和发送表情包、联网搜索知识、对群内信息进行记忆,还能够感知同实例内其它插件的输出、通过 LLM 调用其它插件、自主学习群内命令用法,并能通过子插件与其它 bot 通信获取消息和远程调用命令。
@@ -24,7 +30,7 @@
24
30
  - 🧠 **LLM 命令学习**:通过观察群聊自动学习命令用法,支持学习、编辑、删除
25
31
  - 🌐 **跨 bot 通信**:通过 HTTP 获取其它 bot(同一 QQ 号下)的插件输出,并可远程调用其命令
26
32
  - 🖼️ **表情包功能**:AI 自主决定发表情包;自动从群聊中收藏
27
- - 🔍 **联网搜索**:支持 Tavily / Bocha / Bing,自动搜索不懂的梗和网络用语
33
+ - 🔍 **联网搜索**:支持 Tavily / Bocha / Bing / DeepSeek / 本地 open-websearch,自动搜索不懂的梗和网络用语
28
34
  - 🧠 **四层记忆系统**:短期记忆、长期记忆、群友信息、文化记忆,LLM 自主管理
29
35
  - 🎨 **AI 生图**:LLM可调用生图模型生成图片发到群里,尺寸由 LLM 决定(程序限最大尺寸),支持参考图改绘(回复图片消息或从聊天记录选图)
30
36
 
@@ -125,10 +131,11 @@ AIGFM_ENERGY_BASELINE=0.7 # 社交能量基线(默认 0.7,范
125
131
 
126
132
  # --- 联网搜索 ---
127
133
  AIGFM_SEARCH_ENABLED=false # 是否启用联网搜索(默认 false)
128
- AIGFM_SEARCH_API=tavily # 搜索API: tavily / bocha / bing / openwebsearch(默认 tavily)
129
- AIGFM_SEARCH_API_KEY="xxx" # 搜索 API Key(api=tavily/bocha/bing 时必填)
134
+ AIGFM_SEARCH_API=tavily # 搜索API: tavily / bocha / bing / openwebsearch / deepseek(默认 tavily)
135
+ AIGFM_SEARCH_API_KEY="xxx" # 搜索 API Key(api=tavily/bocha/bing 时必填;deepseek 留空则沿用 LLM Key)
130
136
  AIGFM_SEARCH_MAX_RESULTS=3 # 最大搜索结果数(默认 3)
131
137
  AIGFM_OPENWEBSEARCH_URL="" # open-websearch 本地服务地址(api=openwebsearch 时必填,如 http://127.0.0.1:3210)
138
+ AIGFM_SEARCH_BASE_URL="" # 搜索 API 根地址(api=deepseek 时用,留空则用官方 https://api.deepseek.com)
132
139
 
133
140
  # --- 代理 ---
134
141
  AIGFM_PROXY_ENABLED=false # 是否启用代理(默认 false)
@@ -167,7 +174,6 @@ AIGFM_ANIME_RECOGNIZE_MAX_CHARACTERS=3 # 展示的角色标签数量上限(
167
174
  AIGFM_ANIME_NSFW_THRESHOLD=0.5 # explicit 概率超过该值标注 [NSFW](默认 0.5;仅本地后端提供画风分级)
168
175
  AIGFM_ANIMETRACE_URL="https://api.animetrace.com" # AnimeTrace API 地址(公共 API、无需鉴权;识别会把图片上传到该服务)
169
176
  AIGFM_ANIMETRACE_TIMEOUT=20.0 # AnimeTrace 请求超时/秒(默认 20.0)
170
- AIGFM_ANIME_RECOGNIZE_ENABLED=false # 【已被 AIGFM_ANIME_BACKEND 取代,仅兼容保留】为 true 且 backend=off 时按 anime-recognize 处理
171
177
 
172
178
  # --- 缓存清理 ---
173
179
  AIGFM_IMAGE_CACHE_MAX_FILES=500 # 描述/角色识别缓存(image_cache 下的 JSON)最大数量,超出按 mtime 最旧删除(默认 500,0=不清理)
@@ -292,7 +298,7 @@ LLM 调用:invoke_plugin(command="决斗", parts=[
292
298
  ```
293
299
 
294
300
  - `command` **只放命令名本身**;要 @ 的群友、附加文字等一律放进 `parts`
295
- - `at` 段按**群昵称**解析(与聊天记录里的 `@昵称` 一致),也接受直接给 QQ 号;解析不出会跳过该段,并在工具回执里提示
301
+ - `at` 段按**群昵称或群名片**解析(与聊天记录里的 `@昵称` 一致),也接受直接给 QQ 号;解析不出会跳过该段,并在工具回执里提示
296
302
  - 各段之间由程序补**一个**空格,不需要也不用自己加空格(多写的空格会被规整,避免出现双空格导致参数解析失败)
297
303
 
298
304
  ### 调用限制
@@ -447,6 +453,7 @@ LLM 可以:
447
453
  | `bocha` | 国产 AI 搜索 API,中文搜索效果好 | 无 | https://open.bochaai.com |
448
454
  | `bing` | 微软必应搜索(Azure Bing Search API v7) | 无 | https://portal.azure.com |
449
455
  | `openwebsearch` | 本地 Node.js 搜索服务,聚合多引擎(bing/baidu/duckduckgo 等) | 需先启动 daemon:`cd open-webSearch && npm install && npm run serve`,配置 `AIGFM_OPENWEBSEARCH_URL` | 无需 Key,项目:https://github.com/Aas-ee/open-webSearch |
456
+ | `deepseek` | DeepSeek 自带联网搜索,摘要写得很适合喂给模型 | 无(`AIGFM_SEARCH_API_KEY` 留空则沿用 LLM Key) | https://platform.deepseek.com |
450
457
 
451
458
  > **Tavily** 需额外安装依赖:`pip install tavily-python`(或安装本插件时带上 extra:`pip install "nonebot-plugin-aigf-master[tavily]"`)
452
459
 
@@ -561,7 +568,7 @@ memes/
561
568
  | 后端 | 工作方式 | 擅长 | 代价 |
562
569
  |---|---|---|---|
563
570
  | `anime-recognize` | 本地 WD14 推理服务([aigfm-anime-recognize](https://github.com/Funny1Potato/aigfm-anime-recognize)),**需自行部署** | 动漫 / 手游角色,输出英文 booru 标签(如 `hu_tao_(genshin_impact)`)+ 数值置信度 + 画风分级 | 本地推理、免费无限量;**对 gal / 视觉小说角色识别率低** |
564
- | `animetrace` | [AnimeTrace](https://ai.animedb.cn/) 公共 API,**无需部署、无需鉴权** | gal / 视觉小说角色,并给出作品名(如「胡桃(原神)」) | 图片会上传到该第三方公共服务;有使用配额;不返回数值置信度、无画风分级 |
571
+ | `animetrace` | [AnimeTrace](https://ai.animedb.cn/) 公共 API,**无需部署、无需鉴权** | gal / 视觉小说角色,并给出作品名(如「胡桃(原神)」) | 图片会上传到该第三方公共服务;有使用配额;不返回数值置信度、无画风分级;对gal以外游戏角色的识别率一般 |
565
572
 
566
573
  `both` 模式先问本地服务,本地置信度不足(低于 `AIGFM_ANIME_RECOGNIZE_MIN_CONFIDENCE`)再问 AnimeTrace,两边都没有可信结果才渲染 `[角色识别: 未能识别]`——平时不消耗公共 API 配额。
567
574
 
@@ -572,8 +579,10 @@ memes/
572
579
  ```bash
573
580
  git clone https://github.com/Funny1Potato/aigfm-anime-recognize.git
574
581
  cd aigfm-anime-recognize
582
+ # 安装
575
583
  # Windows: install.bat ;Linux/macOS: chmod +x install.sh && ./install.sh
576
- # 一键完成:建虚拟环境 → 装钉版本依赖 → 下载模型(约 446MB)→ 启动服务(0.0.0.0:8000)
584
+ # 启动
585
+ # Windows: start.bat ; Linux / macOS: chmod +x start.sh && ./start.sh
577
586
  ```
578
587
 
579
588
  **插件配置**:
@@ -583,14 +592,14 @@ cd aigfm-anime-recognize
583
592
  AIGFM_ANIME_BACKEND=both
584
593
 
585
594
  # 本地后端地址(backend 含 anime-recognize 时必填;服务端未启用鉴权时 token 留空)
586
- AIGFM_ANIME_RECOGNIZE_URL=http://127.0.0.1:8000
595
+ AIGFM_ANIME_RECOGNIZE_URL="http://127.0.0.1:8000"
587
596
  # AIGFM_ANIME_RECOGNIZE_TOKEN=可选
588
597
 
589
598
  # 可选调参(默认值如下)
590
599
  # AIGFM_ANIME_RECOGNIZE_MIN_CONFIDENCE=0.85 # 展示角色标签的最低置信度;both 模式下也用它判断本地是否有结果
591
600
  # AIGFM_ANIME_RECOGNIZE_MAX_CHARACTERS=3 # 展示的角色标签数量上限
592
601
  # AIGFM_ANIME_NSFW_THRESHOLD=0.5 # explicit 概率超过该值标注 [NSFW](只标注不拦截;仅本地后端提供分级)
593
- # AIGFM_ANIMETRACE_URL=https://api.animetrace.com
602
+ # AIGFM_ANIMETRACE_URL="https://api.animetrace.com"
594
603
  # AIGFM_ANIMETRACE_TIMEOUT=20 # AnimeTrace 请求超时(秒)
595
604
  ```
596
605
 
@@ -612,8 +621,8 @@ AIGFM_ANIME_RECOGNIZE_URL=http://127.0.0.1:8000
612
621
  - 改 `AIGFM_ANIME_RECOGNIZE_MIN_CONFIDENCE` 只影响此后新识别的图片;已缓存图片要重新判定需删除其 `{md5}_anime.json`
613
622
 
614
623
  **已知局限**:
615
- - **本地后端**:训练数据截止 2024 年前后,新游/新角色可能认不出,**gal / 视觉小说角色识别率尤其低(建议改用 `animetrace` 或 `both`)**;多人合影会漏识别;皮肤/异格不区分;3D 战斗小人/游戏内截图识别率偏低;输出为英文标签(中文映射需自行扩展)
616
- - **AnimeTrace**:不返回数值置信度,只有服务自己的低置信判定——被判低置信时一律按「未能识别」处理,日志 `[角色识别] AnimeTrace 无可信结果,低置信候选: …` 会给出它认为最可能的候选,便于排查;其检测框可能包含误检,多人提示仅供参考;`[NSFW]` 标记只由本地后端提供
624
+ - **本地后端**:训练数据截止 2024 年前后,新游/新角色可能认不出,**gal / 视觉小说角色识别率尤其低(建议改用 `animetrace` 或 `both`)**;多人合影可能会漏识别;3D 战斗小人/游戏内截图识别率不高;输出为英文标签(中文映射需自行扩展)
625
+ - **AnimeTrace**:对gal以外的游戏角色识别率一般;不返回数值置信度,只有服务自己的低置信判定——被判低置信时一律按「未能识别」处理,日志 `[角色识别] AnimeTrace 无可信结果,低置信候选: …` 会给出它认为最可能的候选,便于排查;其检测框可能包含误检,多人提示仅供参考;`[NSFW]` 标记只由本地后端提供
617
626
  - 识别结果(角色名)会进入 LLM 上下文,也就是群里能看到;在意隐私请只用 `anime-recognize`(纯本地)或关闭本功能
618
627
 
619
628
  > 仅 `AIGFM_IMAGE_MODE=vlm` 模式生效;`llm` 模式图片不经过 VLM,无二次元判断。
@@ -643,6 +652,29 @@ LLM 支持以下回复类型:
643
652
  | @ | `{"type": "at", "name": "群友昵称"}` | 艾特群友 |
644
653
  | 表情包 | `{"type": "meme", "id": "表情包id"}` | 发送表情包 |
645
654
 
655
+ > 要 @ 群友时应使用独立的 `at` 段。为兼容部分模型误把 `@昵称` 写进文本的情况,发送前也会把能匹配到群成员的文本 @ 自动转换为真实 QQ @。
656
+
657
+ ## 📊 Token 消耗参考
658
+
659
+ 以下是一组实测值:测试群约 120 人、活跃约 15 人,平均每天 400 条消息,一个月合计约 3.6 亿 tokens。
660
+
661
+ | 周期 | 消息量 | Token 消耗 |
662
+ |------|--------|------------|
663
+ | 每日 | ≈ 400 条 | ≈ 12M(1200 万) |
664
+ | 每周(按 4.3 周) | ≈ 2,800 条 | ≈ 84M(8400 万) |
665
+ | 每月(30 天) | ≈ 12,000 条 | ≈ 360M(3.6 亿) |
666
+ | 摊到每条消息 | — | ≈ 30k |
667
+
668
+ 主要影响因素:
669
+
670
+ - **模型单价**:不同模型差别很大,建议先用便宜的模型跑量
671
+ - **图片**:`AIGFM_IMAGE_MODE=llm` 会把图片本体随请求发送,比默认的 `vlm`(另发一次识图请求)更贵
672
+ - **联网搜索 / 生图 / 插件调用**:会额外产生调用轮次
673
+ - **批次大小**:`AIGFM_BATCH_COUNT` / `AIGFM_BATCH_TIMEOUT` 攒得越多,单次请求里的上下文(历史、记忆、命令清单)越长,但**请求次数越少**;调小则相反
674
+ - **启用的会话数**:每个群/频道各自独立计费
675
+
676
+ 估算自己群的消耗:数日志里 `[处理] 群<群号> 调用 LLM` 的条数(= 调用次数),乘以服务商返回的平均 token 数即可。
677
+
646
678
  ## 📁 数据存储
647
679
 
648
680
  ```
@@ -73,8 +73,12 @@ _image_gen = ImageGenClient(
73
73
  _proxy,
74
74
  ) if plugin_config.aigfm_image_gen_enabled else None
75
75
  _search = create_search_client(
76
- plugin_config.aigfm_search_api, plugin_config.aigfm_search_api_key,
76
+ plugin_config.aigfm_search_api,
77
+ # deepseek 的 Key 一般和 LLM 是同一个,没单独配就沿用 LLM Key
78
+ plugin_config.aigfm_search_api_key
79
+ or (plugin_config.aigfm_llm_api_key if plugin_config.aigfm_search_api == "deepseek" else ""),
77
80
  plugin_config.aigfm_openwebsearch_url,
81
+ plugin_config.aigfm_search_base_url,
78
82
  ) if plugin_config.aigfm_search_enabled else None
79
83
  _peer_client = PeerClient(plugin_config.aigfm_peer_bots) if plugin_config.aigfm_peer_bots else None
80
84
 
@@ -64,10 +64,11 @@ class PluginConfig(BaseModel):
64
64
 
65
65
  # 搜索
66
66
  aigfm_search_enabled: bool = Field(False, description="是否启用联网搜索")
67
- aigfm_search_api: Literal["tavily", "bocha", "bing", "openwebsearch"] = Field("tavily", description="搜索 API")
68
- aigfm_search_api_key: str = Field("", description="搜索 API Key(tavily/bocha/bing 必填)")
67
+ aigfm_search_api: Literal["tavily", "bocha", "bing", "openwebsearch", "deepseek"] = Field("tavily", description="搜索 API")
68
+ aigfm_search_api_key: str = Field("", description="搜索 API Key(tavily/bocha/bing 必填;deepseek 留空则用 LLM Key)")
69
69
  aigfm_search_max_results: int = Field(3, description="最大搜索结果数")
70
70
  aigfm_openwebsearch_url: str = Field("", description="open-websearch 本地服务地址(如 http://127.0.0.1:3210)")
71
+ aigfm_search_base_url: str = Field("", description="搜索 API 根地址(deepseek 用,留空则用官方 https://api.deepseek.com)")
71
72
 
72
73
  # 代理
73
74
  aigfm_proxy_enabled: bool = Field(False, description="是否启用代理")
@@ -0,0 +1,213 @@
1
+ """消息组装:回复发送与插件调用(合成事件)共用同一套 @ 解析与段落拼装
2
+
3
+ 段结构与 LLM 输出的 `reply` 字段一致:`{"type": "text", "content": ...}` /
4
+ `{"type": "at", "name": ...}`。两条链路原先各写一套 @ 处理(回复按昵称、调用要 QQ 号),
5
+ 统一到这里后都接受「昵称或 QQ 号」,且条目之间同样以空格分隔。
6
+ """
7
+ from typing import NamedTuple
8
+
9
+ from nonebot import logger
10
+ from nonebot.adapters.onebot.v11 import Bot, Message, MessageSegment
11
+
12
+
13
+ class Composed(NamedTuple):
14
+ messages: list[Message] # 按顺序依次发送的消息(图片各自独立成条)
15
+ skipped_ats: list[str] # 解析不出目标的 @(供调用方决定是否提示)
16
+
17
+
18
+ async def _get_group_members(bot: Bot, group_id: int) -> list[dict] | None:
19
+ """获取群成员列表;失败时记录一次错误并返回 None"""
20
+ try:
21
+ return await bot.get_group_member_list(group_id=group_id)
22
+ except Exception as e:
23
+ logger.error(f"获取群成员列表失败: {e}")
24
+ return None
25
+
26
+
27
+ def _member_names(member: dict) -> list[str]:
28
+ """成员可用于 @ 的名称:群名片、QQ 昵称和 QQ 号"""
29
+ names: list[str] = []
30
+ for key in ("card", "nickname"):
31
+ name = str(member.get(key) or "").strip()
32
+ if name and name not in names:
33
+ names.append(name)
34
+ user_id = member.get("user_id")
35
+ if user_id is not None and str(user_id) not in names:
36
+ names.append(str(user_id))
37
+ return names
38
+
39
+
40
+ def _resolve_at_in_members(target, members: list[dict] | None) -> int | None:
41
+ """在已获取的成员列表中把 @ 目标规范成 QQ 号"""
42
+ if target is None:
43
+ return None
44
+ text = str(target).strip()
45
+ if not text:
46
+ return None
47
+ if text.isdigit():
48
+ return int(text) or None # 0 不是有效 QQ,按「无目标」处理
49
+ for member in members or []:
50
+ if text in _member_names(member):
51
+ user_id = member.get("user_id")
52
+ return int(user_id) if user_id is not None else None
53
+ return None
54
+
55
+
56
+ async def resolve_at_target(bot: Bot, group_id: int, target) -> int | None:
57
+ """把 @ 目标规范成 QQ 号
58
+
59
+ - 数字 / 数字字符串 → 直接使用(不发 API 请求)
60
+ - 其余按群名片、QQ 昵称或 QQ 号精确匹配群成员列表
61
+ 解析不出(含成员不存在、API 异常)返回 None,降级方式由调用方决定。
62
+ """
63
+ if target is None:
64
+ return None
65
+ text = str(target).strip()
66
+ if not text:
67
+ return None
68
+ if text.isdigit():
69
+ return int(text) or None # 0 不是有效 QQ,按「无目标」处理
70
+ return _resolve_at_in_members(text, await _get_group_members(bot, group_id))
71
+
72
+
73
+ def _text_mention_targets(members: list[dict] | None) -> list[tuple[str, int]]:
74
+ """生成文本 @ 可供匹配的(名称, QQ号),按名称长度降序避免短名称抢先匹配"""
75
+ targets: dict[str, int | None] = {}
76
+ for member in members or []:
77
+ user_id = member.get("user_id")
78
+ uid = int(user_id) if user_id is not None else None
79
+ for name in _member_names(member):
80
+ # 同名成员无法确定 @ 的是谁,不自动转换,避免误 @
81
+ targets[name] = uid if name not in targets else (
82
+ targets[name] if targets[name] == uid else None
83
+ )
84
+ return sorted(
85
+ ((name, uid) for name, uid in targets.items() if name and uid),
86
+ key=lambda item: len(item[0]),
87
+ reverse=True,
88
+ )
89
+
90
+
91
+ def _looks_like_ascii_word(char: str) -> bool:
92
+ return char.isascii() and (char.isalnum() or char == "_")
93
+
94
+
95
+ def _split_text_mentions(text: str, members: list[dict] | None) -> list[tuple[str, str | int]]:
96
+ """把文本里的可识别 `@群名片/@昵称/@QQ号` 拆成文本与真实 @ 段
97
+
98
+ 只转换能精确匹配群成员的名称;未知目标和其他普通文本保持原样。英文字母、
99
+ 数字结尾的名称还要求后面不是 ASCII 单词字符,避免把 `@Alice2` 误拆成 `@Alice`。
100
+ """
101
+ if not text or not any(mark in text for mark in ("@", "@")):
102
+ return [("text", text)]
103
+ targets = _text_mention_targets(members)
104
+ if not targets:
105
+ return [("text", text)]
106
+
107
+ parts: list[tuple[str, str | int]] = []
108
+ cursor = 0
109
+ search_from = 0
110
+ while True:
111
+ at_positions = [text.find(mark, search_from) for mark in ("@", "@")]
112
+ at_positions = [pos for pos in at_positions if pos >= 0]
113
+ if not at_positions:
114
+ break
115
+ start = min(at_positions)
116
+ matched: tuple[str, int] | None = None
117
+ for name, uid in targets:
118
+ end = start + 1 + len(name)
119
+ if not text.startswith(name, start + 1):
120
+ continue
121
+ if (_looks_like_ascii_word(name[-1]) and end < len(text)
122
+ and _looks_like_ascii_word(text[end])):
123
+ continue
124
+ matched = (name, uid)
125
+ break
126
+ if matched is None:
127
+ search_from = start + 1
128
+ continue
129
+ name, uid = matched
130
+ if start > cursor:
131
+ parts.append(("text", text[cursor:start]))
132
+ parts.append(("at", uid))
133
+ cursor = start + 1 + len(name)
134
+ search_from = cursor
135
+ if cursor < len(text):
136
+ parts.append(("text", text[cursor:]))
137
+ return parts or [("text", text)]
138
+
139
+
140
+ async def compose_messages(bot: Bot, group_id: int, parts: list[dict]) -> Composed:
141
+ """把抽象段落拼成待发送的消息列表(按顺序依次发送)
142
+
143
+ parts 元素:
144
+ {"type": "text", "content": str}
145
+ {"type": "at", "target": 昵称或 QQ 号(int 视为已解析,跳过查询)}
146
+ {"type": "image", "path": 本地图片路径}
147
+
148
+ 条目之间由本函数固定插入**一个**空格;文本段的**首尾空白会被去掉**,
149
+ 这样即使 LLM 自己多写了空格也不会出现双空格(双空格会让命令参数解析失败)。
150
+ 图片各自独立成条(它前后的文本各成一条)。文本里模型手写的 @ 也会尽量转换为
151
+ 真实 QQ @;at 解析不出时跳过该段,并把目标记入 skipped_ats。
152
+ """
153
+ messages: list[Message] = []
154
+ skipped_ats: list[str] = []
155
+ pending = Message()
156
+ group_members: list[dict] | None = None
157
+ members_loaded = False
158
+
159
+ async def get_members() -> list[dict] | None:
160
+ nonlocal group_members, members_loaded
161
+ if not members_loaded:
162
+ members_loaded = True
163
+ group_members = await _get_group_members(bot, group_id)
164
+ return group_members
165
+
166
+ def add(segment):
167
+ nonlocal pending
168
+ if pending:
169
+ pending.append(MessageSegment.text(" "))
170
+ pending.append(segment)
171
+
172
+ def flush():
173
+ nonlocal pending
174
+ if pending:
175
+ messages.append(pending)
176
+ pending = Message()
177
+
178
+ for part in parts:
179
+ ptype = part.get("type")
180
+ if ptype == "text":
181
+ content = (part.get("content") or "").strip()
182
+ if content:
183
+ if any(mark in content for mark in ("@", "@")):
184
+ members = await get_members()
185
+ for piece_type, value in _split_text_mentions(content, members):
186
+ if piece_type == "at":
187
+ add(MessageSegment.at(value))
188
+ else:
189
+ value = str(value).strip()
190
+ if value:
191
+ add(MessageSegment.text(value))
192
+ else:
193
+ add(MessageSegment.text(content))
194
+ elif ptype == "at":
195
+ target = part.get("target")
196
+ if isinstance(target, int):
197
+ uid = target or None
198
+ else:
199
+ target_text = str(target or "").strip()
200
+ uid = int(target_text) if target_text.isdigit() else None
201
+ if uid is None:
202
+ uid = _resolve_at_in_members(target_text, await get_members())
203
+ if uid:
204
+ add(MessageSegment.at(uid))
205
+ else:
206
+ skipped_ats.append(str(target or ""))
207
+ elif ptype == "image":
208
+ path = part.get("path")
209
+ if path:
210
+ flush()
211
+ messages.append(Message(MessageSegment.image(path)))
212
+ flush()
213
+ return Composed(messages, skipped_ats)
@@ -456,7 +456,9 @@ index 对应上面数组的下标(从 0 开始)。
456
456
  - 你就是 {bot_name},不要暴露自己是 AI,不要提及任何模型名称(如 GPT、Claude、Qwen 等)
457
457
  - friends 的 key 必须是 QQ 号(数字),绝对不要用昵称做 key
458
458
  - aliases 和 info 是独立的字段,add 只影响 info,add_alias/remove_alias 只影响 aliases
459
- - at 的 name 必须是上面列出的群友昵称
459
+ - 要 @ 群友时,必须单独输出 `{{"type": "at", "name": "群友昵称"}}` 段,严禁在 `text.content` 里手写 `@昵称`
460
+ - at 的 name 必须是上面列出的群友昵称;名称不确定时用 QQ 号代替昵称
461
+ - 错误:`[{{"type": "text", "content": "@张三 你好"}}]`;正确:`[{{"type": "at", "name": "张三"}}, {{"type": "text", "content": "你好"}}]`
460
462
  """
461
463
  return prompt
462
464
 
@@ -112,7 +112,62 @@ class OpenWebSearchClient(SearchClient):
112
112
  return []
113
113
 
114
114
 
115
- def create_search_client(api: str, api_key: str, base_url: str = "") -> SearchClient | None:
115
+ class DeepSeekSearchClient(SearchClient):
116
+ """DeepSeek 联网搜索(POST {base}/v1/tools/search)
117
+
118
+ 文档:https://api-docs.deepseek.com/zh-cn/api/search
119
+ - 按**成功请求次数**计费(不按 token、不按条数),`results` 为空数组不算成功、不计费
120
+ - `summary` 是给模型看的长摘要,`snippet` 是短摘要;`content` 只有传 `need_content`
121
+ 才会带网页正文(默认不带,省掉额外抓取)
122
+ - QPS 100;401 = Key 无效,402 = 余额不足
123
+ """
124
+
125
+ def __init__(self, api_key: str, base_url: str = ""):
126
+ self._api_key = api_key
127
+ self._base_url = (base_url or "https://api.deepseek.com").rstrip("/")
128
+
129
+ async def search(self, query: str, max_results: int = 3) -> list[dict]:
130
+ try:
131
+ headers = {"Authorization": f"Bearer {self._api_key}", "Content-Type": "application/json"}
132
+ # count 取值范围 1-50,越界会被判 400
133
+ payload = {"query": query, "count": max(1, min(int(max_results or 1), 50))}
134
+ async with httpx.AsyncClient(timeout=15.0) as client:
135
+ resp = await client.post(f"{self._base_url}/v1/tools/search", headers=headers, json=payload)
136
+ if resp.status_code != 200:
137
+ self._log_failure(resp)
138
+ return []
139
+ data = resp.json()
140
+ results = []
141
+ for r in data.get("results", []):
142
+ content = (r.get("summary") or r.get("snippet") or "").strip()
143
+ results.append({"title": r.get("title", ""), "content": content, "url": r.get("url", "")})
144
+ return results
145
+ except Exception as e:
146
+ logger.error(f"[搜索] DeepSeek 失败: {e}")
147
+ return []
148
+
149
+ def _log_failure(self, resp):
150
+ """DeepSeek 的错误体是 OpenAI 兼容格式,挑出人能看懂的说明"""
151
+ try:
152
+ err = (resp.json() or {}).get("error", {}) or {}
153
+ msg = err.get("message") or ""
154
+ except Exception:
155
+ msg = ""
156
+ hint = {
157
+ 400: "请求参数不合法",
158
+ 401: "API Key 无效",
159
+ 402: "余额不足",
160
+ 429: "触发 QPS 限制",
161
+ 500: "服务端错误",
162
+ 504: "下游超时",
163
+ }.get(resp.status_code, "")
164
+ logger.error(f"[搜索] DeepSeek 失败: HTTP {resp.status_code}"
165
+ + (f"({hint})" if hint else "")
166
+ + (f" {msg}" if msg else ""))
167
+
168
+
169
+ def create_search_client(api: str, api_key: str, base_url: str = "",
170
+ api_base_url: str = "") -> SearchClient | None:
116
171
  api = api.lower()
117
172
  if api == "tavily":
118
173
  return TavilySearchClient(api_key) if api_key else None
@@ -122,4 +177,6 @@ def create_search_client(api: str, api_key: str, base_url: str = "") -> SearchCl
122
177
  return BingSearchClient(api_key) if api_key else None
123
178
  elif api == "openwebsearch":
124
179
  return OpenWebSearchClient(base_url) if base_url else None
180
+ elif api == "deepseek":
181
+ return DeepSeekSearchClient(api_key, api_base_url) if api_key else None
125
182
  return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-plugin-aigf-master
3
- Version: 1.6.2
3
+ Version: 1.6.3
4
4
  Summary: 群聊特化LLM聊天机器人(增强版),具有记忆、表情包、跨插件调用和跨bot通信能力
5
5
  License-Expression: MIT
6
6
  Requires-Python: <4.0,>=3.10
@@ -32,6 +32,12 @@ Dynamic: license-file
32
32
  </p>
33
33
  </div>
34
34
 
35
+ > [!TIP]
36
+ > **有个跨适配器 beta 版正在测试中**:`2.0.0-beta` 已作为**预发布**发到 PyPI,消息收发与会话身份改走 `nonebot-plugin-alconna` / `nonebot-plugin-uninfo`,OneBot / Satori / Telegram / Discord 等适配器共用同一套聊天、记忆与命令逻辑。
37
+ > 稳定版仍是 **1.6.x**(`pip install` 与 `nb plugin install` 默认只会装稳定版),装 beta 必须显式写出版本号:
38
+ > `pip install nonebot-plugin-aigf-master==2.0.0b3`
39
+ > 最新版本号与支持边界见 [beta 分支的 README](https://github.com/Funny1Potato/nonebot-plugin-aigf-master/tree/beta)。
40
+
35
41
  ## 📖 介绍
36
42
 
37
43
  一个基于 NoneBot2 的群聊 AI 助手插件,能够自主收集和发送表情包、联网搜索知识、对群内信息进行记忆,还能够感知同实例内其它插件的输出、通过 LLM 调用其它插件、自主学习群内命令用法,并能通过子插件与其它 bot 通信获取消息和远程调用命令。
@@ -44,7 +50,7 @@ Dynamic: license-file
44
50
  - 🧠 **LLM 命令学习**:通过观察群聊自动学习命令用法,支持学习、编辑、删除
45
51
  - 🌐 **跨 bot 通信**:通过 HTTP 获取其它 bot(同一 QQ 号下)的插件输出,并可远程调用其命令
46
52
  - 🖼️ **表情包功能**:AI 自主决定发表情包;自动从群聊中收藏
47
- - 🔍 **联网搜索**:支持 Tavily / Bocha / Bing,自动搜索不懂的梗和网络用语
53
+ - 🔍 **联网搜索**:支持 Tavily / Bocha / Bing / DeepSeek / 本地 open-websearch,自动搜索不懂的梗和网络用语
48
54
  - 🧠 **四层记忆系统**:短期记忆、长期记忆、群友信息、文化记忆,LLM 自主管理
49
55
  - 🎨 **AI 生图**:LLM可调用生图模型生成图片发到群里,尺寸由 LLM 决定(程序限最大尺寸),支持参考图改绘(回复图片消息或从聊天记录选图)
50
56
 
@@ -145,10 +151,11 @@ AIGFM_ENERGY_BASELINE=0.7 # 社交能量基线(默认 0.7,范
145
151
 
146
152
  # --- 联网搜索 ---
147
153
  AIGFM_SEARCH_ENABLED=false # 是否启用联网搜索(默认 false)
148
- AIGFM_SEARCH_API=tavily # 搜索API: tavily / bocha / bing / openwebsearch(默认 tavily)
149
- AIGFM_SEARCH_API_KEY="xxx" # 搜索 API Key(api=tavily/bocha/bing 时必填)
154
+ AIGFM_SEARCH_API=tavily # 搜索API: tavily / bocha / bing / openwebsearch / deepseek(默认 tavily)
155
+ AIGFM_SEARCH_API_KEY="xxx" # 搜索 API Key(api=tavily/bocha/bing 时必填;deepseek 留空则沿用 LLM Key)
150
156
  AIGFM_SEARCH_MAX_RESULTS=3 # 最大搜索结果数(默认 3)
151
157
  AIGFM_OPENWEBSEARCH_URL="" # open-websearch 本地服务地址(api=openwebsearch 时必填,如 http://127.0.0.1:3210)
158
+ AIGFM_SEARCH_BASE_URL="" # 搜索 API 根地址(api=deepseek 时用,留空则用官方 https://api.deepseek.com)
152
159
 
153
160
  # --- 代理 ---
154
161
  AIGFM_PROXY_ENABLED=false # 是否启用代理(默认 false)
@@ -187,7 +194,6 @@ AIGFM_ANIME_RECOGNIZE_MAX_CHARACTERS=3 # 展示的角色标签数量上限(
187
194
  AIGFM_ANIME_NSFW_THRESHOLD=0.5 # explicit 概率超过该值标注 [NSFW](默认 0.5;仅本地后端提供画风分级)
188
195
  AIGFM_ANIMETRACE_URL="https://api.animetrace.com" # AnimeTrace API 地址(公共 API、无需鉴权;识别会把图片上传到该服务)
189
196
  AIGFM_ANIMETRACE_TIMEOUT=20.0 # AnimeTrace 请求超时/秒(默认 20.0)
190
- AIGFM_ANIME_RECOGNIZE_ENABLED=false # 【已被 AIGFM_ANIME_BACKEND 取代,仅兼容保留】为 true 且 backend=off 时按 anime-recognize 处理
191
197
 
192
198
  # --- 缓存清理 ---
193
199
  AIGFM_IMAGE_CACHE_MAX_FILES=500 # 描述/角色识别缓存(image_cache 下的 JSON)最大数量,超出按 mtime 最旧删除(默认 500,0=不清理)
@@ -312,7 +318,7 @@ LLM 调用:invoke_plugin(command="决斗", parts=[
312
318
  ```
313
319
 
314
320
  - `command` **只放命令名本身**;要 @ 的群友、附加文字等一律放进 `parts`
315
- - `at` 段按**群昵称**解析(与聊天记录里的 `@昵称` 一致),也接受直接给 QQ 号;解析不出会跳过该段,并在工具回执里提示
321
+ - `at` 段按**群昵称或群名片**解析(与聊天记录里的 `@昵称` 一致),也接受直接给 QQ 号;解析不出会跳过该段,并在工具回执里提示
316
322
  - 各段之间由程序补**一个**空格,不需要也不用自己加空格(多写的空格会被规整,避免出现双空格导致参数解析失败)
317
323
 
318
324
  ### 调用限制
@@ -467,6 +473,7 @@ LLM 可以:
467
473
  | `bocha` | 国产 AI 搜索 API,中文搜索效果好 | 无 | https://open.bochaai.com |
468
474
  | `bing` | 微软必应搜索(Azure Bing Search API v7) | 无 | https://portal.azure.com |
469
475
  | `openwebsearch` | 本地 Node.js 搜索服务,聚合多引擎(bing/baidu/duckduckgo 等) | 需先启动 daemon:`cd open-webSearch && npm install && npm run serve`,配置 `AIGFM_OPENWEBSEARCH_URL` | 无需 Key,项目:https://github.com/Aas-ee/open-webSearch |
476
+ | `deepseek` | DeepSeek 自带联网搜索,摘要写得很适合喂给模型 | 无(`AIGFM_SEARCH_API_KEY` 留空则沿用 LLM Key) | https://platform.deepseek.com |
470
477
 
471
478
  > **Tavily** 需额外安装依赖:`pip install tavily-python`(或安装本插件时带上 extra:`pip install "nonebot-plugin-aigf-master[tavily]"`)
472
479
 
@@ -581,7 +588,7 @@ memes/
581
588
  | 后端 | 工作方式 | 擅长 | 代价 |
582
589
  |---|---|---|---|
583
590
  | `anime-recognize` | 本地 WD14 推理服务([aigfm-anime-recognize](https://github.com/Funny1Potato/aigfm-anime-recognize)),**需自行部署** | 动漫 / 手游角色,输出英文 booru 标签(如 `hu_tao_(genshin_impact)`)+ 数值置信度 + 画风分级 | 本地推理、免费无限量;**对 gal / 视觉小说角色识别率低** |
584
- | `animetrace` | [AnimeTrace](https://ai.animedb.cn/) 公共 API,**无需部署、无需鉴权** | gal / 视觉小说角色,并给出作品名(如「胡桃(原神)」) | 图片会上传到该第三方公共服务;有使用配额;不返回数值置信度、无画风分级 |
591
+ | `animetrace` | [AnimeTrace](https://ai.animedb.cn/) 公共 API,**无需部署、无需鉴权** | gal / 视觉小说角色,并给出作品名(如「胡桃(原神)」) | 图片会上传到该第三方公共服务;有使用配额;不返回数值置信度、无画风分级;对gal以外游戏角色的识别率一般 |
585
592
 
586
593
  `both` 模式先问本地服务,本地置信度不足(低于 `AIGFM_ANIME_RECOGNIZE_MIN_CONFIDENCE`)再问 AnimeTrace,两边都没有可信结果才渲染 `[角色识别: 未能识别]`——平时不消耗公共 API 配额。
587
594
 
@@ -592,8 +599,10 @@ memes/
592
599
  ```bash
593
600
  git clone https://github.com/Funny1Potato/aigfm-anime-recognize.git
594
601
  cd aigfm-anime-recognize
602
+ # 安装
595
603
  # Windows: install.bat ;Linux/macOS: chmod +x install.sh && ./install.sh
596
- # 一键完成:建虚拟环境 → 装钉版本依赖 → 下载模型(约 446MB)→ 启动服务(0.0.0.0:8000)
604
+ # 启动
605
+ # Windows: start.bat ; Linux / macOS: chmod +x start.sh && ./start.sh
597
606
  ```
598
607
 
599
608
  **插件配置**:
@@ -603,14 +612,14 @@ cd aigfm-anime-recognize
603
612
  AIGFM_ANIME_BACKEND=both
604
613
 
605
614
  # 本地后端地址(backend 含 anime-recognize 时必填;服务端未启用鉴权时 token 留空)
606
- AIGFM_ANIME_RECOGNIZE_URL=http://127.0.0.1:8000
615
+ AIGFM_ANIME_RECOGNIZE_URL="http://127.0.0.1:8000"
607
616
  # AIGFM_ANIME_RECOGNIZE_TOKEN=可选
608
617
 
609
618
  # 可选调参(默认值如下)
610
619
  # AIGFM_ANIME_RECOGNIZE_MIN_CONFIDENCE=0.85 # 展示角色标签的最低置信度;both 模式下也用它判断本地是否有结果
611
620
  # AIGFM_ANIME_RECOGNIZE_MAX_CHARACTERS=3 # 展示的角色标签数量上限
612
621
  # AIGFM_ANIME_NSFW_THRESHOLD=0.5 # explicit 概率超过该值标注 [NSFW](只标注不拦截;仅本地后端提供分级)
613
- # AIGFM_ANIMETRACE_URL=https://api.animetrace.com
622
+ # AIGFM_ANIMETRACE_URL="https://api.animetrace.com"
614
623
  # AIGFM_ANIMETRACE_TIMEOUT=20 # AnimeTrace 请求超时(秒)
615
624
  ```
616
625
 
@@ -632,8 +641,8 @@ AIGFM_ANIME_RECOGNIZE_URL=http://127.0.0.1:8000
632
641
  - 改 `AIGFM_ANIME_RECOGNIZE_MIN_CONFIDENCE` 只影响此后新识别的图片;已缓存图片要重新判定需删除其 `{md5}_anime.json`
633
642
 
634
643
  **已知局限**:
635
- - **本地后端**:训练数据截止 2024 年前后,新游/新角色可能认不出,**gal / 视觉小说角色识别率尤其低(建议改用 `animetrace` 或 `both`)**;多人合影会漏识别;皮肤/异格不区分;3D 战斗小人/游戏内截图识别率偏低;输出为英文标签(中文映射需自行扩展)
636
- - **AnimeTrace**:不返回数值置信度,只有服务自己的低置信判定——被判低置信时一律按「未能识别」处理,日志 `[角色识别] AnimeTrace 无可信结果,低置信候选: …` 会给出它认为最可能的候选,便于排查;其检测框可能包含误检,多人提示仅供参考;`[NSFW]` 标记只由本地后端提供
644
+ - **本地后端**:训练数据截止 2024 年前后,新游/新角色可能认不出,**gal / 视觉小说角色识别率尤其低(建议改用 `animetrace` 或 `both`)**;多人合影可能会漏识别;3D 战斗小人/游戏内截图识别率不高;输出为英文标签(中文映射需自行扩展)
645
+ - **AnimeTrace**:对gal以外的游戏角色识别率一般;不返回数值置信度,只有服务自己的低置信判定——被判低置信时一律按「未能识别」处理,日志 `[角色识别] AnimeTrace 无可信结果,低置信候选: …` 会给出它认为最可能的候选,便于排查;其检测框可能包含误检,多人提示仅供参考;`[NSFW]` 标记只由本地后端提供
637
646
  - 识别结果(角色名)会进入 LLM 上下文,也就是群里能看到;在意隐私请只用 `anime-recognize`(纯本地)或关闭本功能
638
647
 
639
648
  > 仅 `AIGFM_IMAGE_MODE=vlm` 模式生效;`llm` 模式图片不经过 VLM,无二次元判断。
@@ -663,6 +672,29 @@ LLM 支持以下回复类型:
663
672
  | @ | `{"type": "at", "name": "群友昵称"}` | 艾特群友 |
664
673
  | 表情包 | `{"type": "meme", "id": "表情包id"}` | 发送表情包 |
665
674
 
675
+ > 要 @ 群友时应使用独立的 `at` 段。为兼容部分模型误把 `@昵称` 写进文本的情况,发送前也会把能匹配到群成员的文本 @ 自动转换为真实 QQ @。
676
+
677
+ ## 📊 Token 消耗参考
678
+
679
+ 以下是一组实测值:测试群约 120 人、活跃约 15 人,平均每天 400 条消息,一个月合计约 3.6 亿 tokens。
680
+
681
+ | 周期 | 消息量 | Token 消耗 |
682
+ |------|--------|------------|
683
+ | 每日 | ≈ 400 条 | ≈ 12M(1200 万) |
684
+ | 每周(按 4.3 周) | ≈ 2,800 条 | ≈ 84M(8400 万) |
685
+ | 每月(30 天) | ≈ 12,000 条 | ≈ 360M(3.6 亿) |
686
+ | 摊到每条消息 | — | ≈ 30k |
687
+
688
+ 主要影响因素:
689
+
690
+ - **模型单价**:不同模型差别很大,建议先用便宜的模型跑量
691
+ - **图片**:`AIGFM_IMAGE_MODE=llm` 会把图片本体随请求发送,比默认的 `vlm`(另发一次识图请求)更贵
692
+ - **联网搜索 / 生图 / 插件调用**:会额外产生调用轮次
693
+ - **批次大小**:`AIGFM_BATCH_COUNT` / `AIGFM_BATCH_TIMEOUT` 攒得越多,单次请求里的上下文(历史、记忆、命令清单)越长,但**请求次数越少**;调小则相反
694
+ - **启用的会话数**:每个群/频道各自独立计费
695
+
696
+ 估算自己群的消耗:数日志里 `[处理] 群<群号> 调用 LLM` 的条数(= 调用次数),乘以服务商返回的平均 token 数即可。
697
+
666
698
  ## 📁 数据存储
667
699
 
668
700
  ```
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "nonebot-plugin-aigf-master"
7
- version = "1.6.2"
7
+ version = "1.6.3"
8
8
  description = "群聊特化LLM聊天机器人(增强版),具有记忆、表情包、跨插件调用和跨bot通信能力"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -1,92 +0,0 @@
1
- """消息组装:回复发送与插件调用(合成事件)共用同一套 @ 解析与段落拼装
2
-
3
- 段结构与 LLM 输出的 `reply` 字段一致:`{"type": "text", "content": ...}` /
4
- `{"type": "at", "name": ...}`。两条链路原先各写一套 @ 处理(回复按昵称、调用要 QQ 号),
5
- 统一到这里后都接受「昵称或 QQ 号」,且条目之间同样以空格分隔。
6
- """
7
- from typing import NamedTuple
8
-
9
- from nonebot import logger
10
- from nonebot.adapters.onebot.v11 import Bot, Message, MessageSegment
11
-
12
-
13
- class Composed(NamedTuple):
14
- messages: list[Message] # 按顺序依次发送的消息(图片各自独立成条)
15
- skipped_ats: list[str] # 解析不出目标的 @(供调用方决定是否提示)
16
-
17
-
18
- async def resolve_at_target(bot: Bot, group_id: int, target) -> int | None:
19
- """把 @ 目标规范成 QQ 号
20
-
21
- - 数字 / 数字字符串 → 直接使用(不发 API 请求)
22
- - 其余按群昵称精确匹配群成员列表
23
- 解析不出(含成员不存在、API 异常)返回 None,降级方式由调用方决定。
24
- """
25
- if target is None:
26
- return None
27
- text = str(target).strip()
28
- if not text:
29
- return None
30
- if text.isdigit():
31
- return int(text) or None # 0 不是有效 QQ,按「无目标」处理
32
- try:
33
- members = await bot.get_group_member_list(group_id=group_id)
34
- for m in members:
35
- if m.get("nickname", "").strip() == text:
36
- return m["user_id"]
37
- except Exception as e:
38
- logger.error(f"获取群成员列表失败: {e}")
39
- return None
40
-
41
-
42
- async def compose_messages(bot: Bot, group_id: int, parts: list[dict]) -> Composed:
43
- """把抽象段落拼成待发送的消息列表(按顺序依次发送)
44
-
45
- parts 元素:
46
- {"type": "text", "content": str}
47
- {"type": "at", "target": 昵称或 QQ 号(int 视为已解析,跳过查询)}
48
- {"type": "image", "path": 本地图片路径}
49
-
50
- 条目之间由本函数固定插入**一个**空格;文本段的**首尾空白会被去掉**,
51
- 这样即使 LLM 自己多写了空格也不会出现双空格(双空格会让命令参数解析失败)。
52
- 图片各自独立成条(它前后的文本各成一条)。at 解析不出时跳过该段,并把目标记入 skipped_ats。
53
- """
54
- messages: list[Message] = []
55
- skipped_ats: list[str] = []
56
- pending = Message()
57
-
58
- def add(segment):
59
- nonlocal pending
60
- if pending:
61
- pending.append(MessageSegment.text(" "))
62
- pending.append(segment)
63
-
64
- def flush():
65
- nonlocal pending
66
- if pending:
67
- messages.append(pending)
68
- pending = Message()
69
-
70
- for part in parts:
71
- ptype = part.get("type")
72
- if ptype == "text":
73
- content = (part.get("content") or "").strip()
74
- if content:
75
- add(MessageSegment.text(content))
76
- elif ptype == "at":
77
- target = part.get("target")
78
- if isinstance(target, int):
79
- uid = target or None
80
- else:
81
- uid = await resolve_at_target(bot, group_id, target)
82
- if uid:
83
- add(MessageSegment.at(uid))
84
- else:
85
- skipped_ats.append(str(target or ""))
86
- elif ptype == "image":
87
- path = part.get("path")
88
- if path:
89
- flush()
90
- messages.append(Message(MessageSegment.image(path)))
91
- flush()
92
- return Composed(messages, skipped_ats)