nonebot-plugin-aigf-master 1.6.2__tar.gz → 1.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.
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/PKG-INFO +60 -17
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/README.md +59 -16
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/__init__.py +57 -3
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/config.py +12 -5
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/image_handler.py +6 -3
- nonebot_plugin_aigf_master-1.6.4/nonebot_plugin_aigf_master/llm_client.py +257 -0
- nonebot_plugin_aigf_master-1.6.4/nonebot_plugin_aigf_master/message_builder.py +213 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/processor.py +22 -6
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/prompt_builder.py +3 -1
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/search_client.py +58 -1
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master.egg-info/PKG-INFO +60 -17
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/pyproject.toml +1 -1
- nonebot_plugin_aigf_master-1.6.2/nonebot_plugin_aigf_master/llm_client.py +0 -118
- nonebot_plugin_aigf_master-1.6.2/nonebot_plugin_aigf_master/message_builder.py +0 -92
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/LICENSE +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/anime_recognizer.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/animetrace_client.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/api_hooks.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/cache_cleanup.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/command_learner.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/context_bus.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/image_gen_client.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/meme_store.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/memory_store.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/models.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/peer_client.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/plugin_discovery.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/plugin_invoker.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/preset_store.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/response_parser.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master/vlm_client.py +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master.egg-info/SOURCES.txt +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master.egg-info/dependency_links.txt +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master.egg-info/requires.txt +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/nonebot_plugin_aigf_master.egg-info/top_level.txt +0 -0
- {nonebot_plugin_aigf_master-1.6.2 → nonebot_plugin_aigf_master-1.6.4}/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.
|
|
3
|
+
Version: 1.6.4
|
|
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.0b4`
|
|
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
|
|
|
@@ -105,9 +111,10 @@ AIGFM_LLM_BASE_URL="https://api.deepseek.com" # LLM API 地
|
|
|
105
111
|
AIGFM_LLM_MODEL="deepseek-v4-flash" # LLM 模型名称
|
|
106
112
|
AIGFM_ENABLED_GROUPS=[123456, 789012] # 启用的群号列表
|
|
107
113
|
|
|
108
|
-
# ---
|
|
109
|
-
AIGFM_IMAGE_MODE="
|
|
110
|
-
|
|
114
|
+
# --- 图片理解(多模态 LLM / VLM) ---
|
|
115
|
+
AIGFM_IMAGE_MODE="llm" # 图片模式: llm(默认,多模态统一模型)/ vlm(独立视觉模型)
|
|
116
|
+
AIGFM_LLM_MULTIMODAL="" # 主模型是否支持图片: 留空=启动时自动探测 / true=强制支持 / false=强制不支持并回落到 vlm
|
|
117
|
+
AIGFM_VLM_ENABLED=true # 是否启用VLM(vlm 模式必需;llm 模式主模型不支持图片时作为回落通道,默认 true)
|
|
111
118
|
AIGFM_VLM_MODEL="..." # VLM 模型名称(vlm 模式必填)
|
|
112
119
|
AIGFM_VLM_BASE_URL="https://..." # VLM API 地址
|
|
113
120
|
AIGFM_VLM_API_KEY="" # VLM API Key(为空时使用 llm 的 key)
|
|
@@ -145,10 +152,11 @@ AIGFM_ENERGY_BASELINE=0.7 # 社交能量基线(默认 0.7,范
|
|
|
145
152
|
|
|
146
153
|
# --- 联网搜索 ---
|
|
147
154
|
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
|
|
155
|
+
AIGFM_SEARCH_API=tavily # 搜索API: tavily / bocha / bing / openwebsearch / deepseek(默认 tavily)
|
|
156
|
+
AIGFM_SEARCH_API_KEY="xxx" # 搜索 API Key(api=tavily/bocha/bing 时必填;deepseek 留空则沿用 LLM Key)
|
|
150
157
|
AIGFM_SEARCH_MAX_RESULTS=3 # 最大搜索结果数(默认 3)
|
|
151
158
|
AIGFM_OPENWEBSEARCH_URL="" # open-websearch 本地服务地址(api=openwebsearch 时必填,如 http://127.0.0.1:3210)
|
|
159
|
+
AIGFM_SEARCH_BASE_URL="" # 搜索 API 根地址(api=deepseek 时用,留空则用官方 https://api.deepseek.com)
|
|
152
160
|
|
|
153
161
|
# --- 代理 ---
|
|
154
162
|
AIGFM_PROXY_ENABLED=false # 是否启用代理(默认 false)
|
|
@@ -187,7 +195,6 @@ AIGFM_ANIME_RECOGNIZE_MAX_CHARACTERS=3 # 展示的角色标签数量上限(
|
|
|
187
195
|
AIGFM_ANIME_NSFW_THRESHOLD=0.5 # explicit 概率超过该值标注 [NSFW](默认 0.5;仅本地后端提供画风分级)
|
|
188
196
|
AIGFM_ANIMETRACE_URL="https://api.animetrace.com" # AnimeTrace API 地址(公共 API、无需鉴权;识别会把图片上传到该服务)
|
|
189
197
|
AIGFM_ANIMETRACE_TIMEOUT=20.0 # AnimeTrace 请求超时/秒(默认 20.0)
|
|
190
|
-
AIGFM_ANIME_RECOGNIZE_ENABLED=false # 【已被 AIGFM_ANIME_BACKEND 取代,仅兼容保留】为 true 且 backend=off 时按 anime-recognize 处理
|
|
191
198
|
|
|
192
199
|
# --- 缓存清理 ---
|
|
193
200
|
AIGFM_IMAGE_CACHE_MAX_FILES=500 # 描述/角色识别缓存(image_cache 下的 JSON)最大数量,超出按 mtime 最旧删除(默认 500,0=不清理)
|
|
@@ -312,7 +319,7 @@ LLM 调用:invoke_plugin(command="决斗", parts=[
|
|
|
312
319
|
```
|
|
313
320
|
|
|
314
321
|
- `command` **只放命令名本身**;要 @ 的群友、附加文字等一律放进 `parts`
|
|
315
|
-
- `at`
|
|
322
|
+
- `at` 段按**群昵称或群名片**解析(与聊天记录里的 `@昵称` 一致),也接受直接给 QQ 号;解析不出会跳过该段,并在工具回执里提示
|
|
316
323
|
- 各段之间由程序补**一个**空格,不需要也不用自己加空格(多写的空格会被规整,避免出现双空格导致参数解析失败)
|
|
317
324
|
|
|
318
325
|
### 调用限制
|
|
@@ -467,6 +474,7 @@ LLM 可以:
|
|
|
467
474
|
| `bocha` | 国产 AI 搜索 API,中文搜索效果好 | 无 | https://open.bochaai.com |
|
|
468
475
|
| `bing` | 微软必应搜索(Azure Bing Search API v7) | 无 | https://portal.azure.com |
|
|
469
476
|
| `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 |
|
|
477
|
+
| `deepseek` | DeepSeek 自带联网搜索,摘要写得很适合喂给模型 | 无(`AIGFM_SEARCH_API_KEY` 留空则沿用 LLM Key) | https://platform.deepseek.com |
|
|
470
478
|
|
|
471
479
|
> **Tavily** 需额外安装依赖:`pip install tavily-python`(或安装本插件时带上 extra:`pip install "nonebot-plugin-aigf-master[tavily]"`)
|
|
472
480
|
|
|
@@ -563,8 +571,18 @@ memes/
|
|
|
563
571
|
|
|
564
572
|
| 模式 | 流程 | 适用场景 |
|
|
565
573
|
|------|------|---------|
|
|
566
|
-
| `
|
|
567
|
-
| `
|
|
574
|
+
| `llm`(默认) | 图片 → base64 直接附在 LLM prompt 中 | 主模型支持视觉;推荐用统一多模态模型 |
|
|
575
|
+
| `vlm` | 图片 → VLM 分析 → 文字描述给 LLM | 主 LLM 不支持图片输入 |
|
|
576
|
+
|
|
577
|
+
> 默认使用 `llm` 模式,适应当前主流多模态模型。若主 LLM 只能处理文字,请显式设置 `AIGFM_IMAGE_MODE=vlm` 并配置 VLM,否则图片请求可能被服务端拒绝。
|
|
578
|
+
|
|
579
|
+
`llm` 模式下主模型不支持图片时的自动回落:
|
|
580
|
+
|
|
581
|
+
- 启动时用一张 16×16 的小图探测一次主模型是否接受图片输入,探不过就自动回落到 `vlm` 模式(解析期把图片转成文字描述,请求期只发文本),存量用户升级后不会因为主模型只支持文本而整批不回复
|
|
582
|
+
- 运行期若带图请求被服务端明确拒绝(400/415/422),同样标记为不支持多模态,**下一批**消息起自动回落到 `vlm` 模式
|
|
583
|
+
- 回落到 `vlm` 模式需要 VLM 可用:没配 `AIGFM_VLM_MODEL` / `AIGFM_VLM_BASE_URL` 时图片只能以「识图失败」进上下文
|
|
584
|
+
- `AIGFM_LLM_MULTIMODAL` 可覆盖探测结果:`true` 强制按支持处理(跳过探测,不额外消耗请求)、`false` 强制按不支持处理并直接回落 `vlm`
|
|
585
|
+
- 探测本身出问题时(鉴权失败、限流、网络异常)不做判定,仍按支持处理,避免掩盖真实错误
|
|
568
586
|
|
|
569
587
|
`vlm` 模式下的行为说明:
|
|
570
588
|
|
|
@@ -581,7 +599,7 @@ memes/
|
|
|
581
599
|
| 后端 | 工作方式 | 擅长 | 代价 |
|
|
582
600
|
|---|---|---|---|
|
|
583
601
|
| `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 / 视觉小说角色,并给出作品名(如「胡桃(原神)」) |
|
|
602
|
+
| `animetrace` | [AnimeTrace](https://ai.animedb.cn/) 公共 API,**无需部署、无需鉴权** | gal / 视觉小说角色,并给出作品名(如「胡桃(原神)」) | 图片会上传到该第三方公共服务;有使用配额;不返回数值置信度、无画风分级;对gal以外游戏角色的识别率一般 |
|
|
585
603
|
|
|
586
604
|
`both` 模式先问本地服务,本地置信度不足(低于 `AIGFM_ANIME_RECOGNIZE_MIN_CONFIDENCE`)再问 AnimeTrace,两边都没有可信结果才渲染 `[角色识别: 未能识别]`——平时不消耗公共 API 配额。
|
|
587
605
|
|
|
@@ -592,8 +610,10 @@ memes/
|
|
|
592
610
|
```bash
|
|
593
611
|
git clone https://github.com/Funny1Potato/aigfm-anime-recognize.git
|
|
594
612
|
cd aigfm-anime-recognize
|
|
613
|
+
# 安装
|
|
595
614
|
# Windows: install.bat ;Linux/macOS: chmod +x install.sh && ./install.sh
|
|
596
|
-
#
|
|
615
|
+
# 启动
|
|
616
|
+
# Windows: start.bat ; Linux / macOS: chmod +x start.sh && ./start.sh
|
|
597
617
|
```
|
|
598
618
|
|
|
599
619
|
**插件配置**:
|
|
@@ -603,14 +623,14 @@ cd aigfm-anime-recognize
|
|
|
603
623
|
AIGFM_ANIME_BACKEND=both
|
|
604
624
|
|
|
605
625
|
# 本地后端地址(backend 含 anime-recognize 时必填;服务端未启用鉴权时 token 留空)
|
|
606
|
-
AIGFM_ANIME_RECOGNIZE_URL=http://127.0.0.1:8000
|
|
626
|
+
AIGFM_ANIME_RECOGNIZE_URL="http://127.0.0.1:8000"
|
|
607
627
|
# AIGFM_ANIME_RECOGNIZE_TOKEN=可选
|
|
608
628
|
|
|
609
629
|
# 可选调参(默认值如下)
|
|
610
630
|
# AIGFM_ANIME_RECOGNIZE_MIN_CONFIDENCE=0.85 # 展示角色标签的最低置信度;both 模式下也用它判断本地是否有结果
|
|
611
631
|
# AIGFM_ANIME_RECOGNIZE_MAX_CHARACTERS=3 # 展示的角色标签数量上限
|
|
612
632
|
# AIGFM_ANIME_NSFW_THRESHOLD=0.5 # explicit 概率超过该值标注 [NSFW](只标注不拦截;仅本地后端提供分级)
|
|
613
|
-
# AIGFM_ANIMETRACE_URL=https://api.animetrace.com
|
|
633
|
+
# AIGFM_ANIMETRACE_URL="https://api.animetrace.com"
|
|
614
634
|
# AIGFM_ANIMETRACE_TIMEOUT=20 # AnimeTrace 请求超时(秒)
|
|
615
635
|
```
|
|
616
636
|
|
|
@@ -632,8 +652,8 @@ AIGFM_ANIME_RECOGNIZE_URL=http://127.0.0.1:8000
|
|
|
632
652
|
- 改 `AIGFM_ANIME_RECOGNIZE_MIN_CONFIDENCE` 只影响此后新识别的图片;已缓存图片要重新判定需删除其 `{md5}_anime.json`
|
|
633
653
|
|
|
634
654
|
**已知局限**:
|
|
635
|
-
- **本地后端**:训练数据截止 2024 年前后,新游/新角色可能认不出,**gal / 视觉小说角色识别率尤其低(建议改用 `animetrace` 或 `both
|
|
636
|
-
- **AnimeTrace
|
|
655
|
+
- **本地后端**:训练数据截止 2024 年前后,新游/新角色可能认不出,**gal / 视觉小说角色识别率尤其低(建议改用 `animetrace` 或 `both`)**;多人合影可能会漏识别;3D 战斗小人/游戏内截图识别率不高;输出为英文标签(中文映射需自行扩展)
|
|
656
|
+
- **AnimeTrace**:对gal以外的游戏角色识别率一般;不返回数值置信度,只有服务自己的低置信判定——被判低置信时一律按「未能识别」处理,日志 `[角色识别] AnimeTrace 无可信结果,低置信候选: …` 会给出它认为最可能的候选,便于排查;其检测框可能包含误检,多人提示仅供参考;`[NSFW]` 标记只由本地后端提供
|
|
637
657
|
- 识别结果(角色名)会进入 LLM 上下文,也就是群里能看到;在意隐私请只用 `anime-recognize`(纯本地)或关闭本功能
|
|
638
658
|
|
|
639
659
|
> 仅 `AIGFM_IMAGE_MODE=vlm` 模式生效;`llm` 模式图片不经过 VLM,无二次元判断。
|
|
@@ -663,6 +683,29 @@ LLM 支持以下回复类型:
|
|
|
663
683
|
| @ | `{"type": "at", "name": "群友昵称"}` | 艾特群友 |
|
|
664
684
|
| 表情包 | `{"type": "meme", "id": "表情包id"}` | 发送表情包 |
|
|
665
685
|
|
|
686
|
+
> 要 @ 群友时应使用独立的 `at` 段。为兼容部分模型误把 `@昵称` 写进文本的情况,发送前也会把能匹配到群成员的文本 @ 自动转换为真实 QQ @。
|
|
687
|
+
|
|
688
|
+
## 📊 Token 消耗参考
|
|
689
|
+
|
|
690
|
+
以下是一组实测值:测试群约 120 人、活跃约 15 人,平均每天 400 条消息,一个月合计约 3.6 亿 tokens。
|
|
691
|
+
|
|
692
|
+
| 周期 | 消息量 | Token 消耗 |
|
|
693
|
+
|------|--------|------------|
|
|
694
|
+
| 每日 | ≈ 400 条 | ≈ 12M(1200 万) |
|
|
695
|
+
| 每周(按 4.3 周) | ≈ 2,800 条 | ≈ 84M(8400 万) |
|
|
696
|
+
| 每月(30 天) | ≈ 12,000 条 | ≈ 360M(3.6 亿) |
|
|
697
|
+
| 摊到每条消息 | — | ≈ 30k |
|
|
698
|
+
|
|
699
|
+
主要影响因素:
|
|
700
|
+
|
|
701
|
+
- **模型单价**:不同模型差别很大,建议先用便宜的模型跑量
|
|
702
|
+
- **图片**:默认的 `AIGFM_IMAGE_MODE=llm` 会把图片本体随主请求发送,费用按主模型的多模态输入计算;也可改用 `vlm`(另发一次识图请求),适合主模型不支持图片或希望使用轻量视觉模型的场景
|
|
703
|
+
- **联网搜索 / 生图 / 插件调用**:会额外产生调用轮次
|
|
704
|
+
- **批次大小**:`AIGFM_BATCH_COUNT` / `AIGFM_BATCH_TIMEOUT` 攒得越多,单次请求里的上下文(历史、记忆、命令清单)越长,但**请求次数越少**;调小则相反
|
|
705
|
+
- **启用的会话数**:每个群/频道各自独立计费
|
|
706
|
+
|
|
707
|
+
估算自己群的消耗:数日志里 `[处理] 群<群号> 调用 LLM` 的条数(= 调用次数),乘以服务商返回的平均 token 数即可。
|
|
708
|
+
|
|
666
709
|
## 📁 数据存储
|
|
667
710
|
|
|
668
711
|
```
|
|
@@ -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.0b4`
|
|
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
|
|
|
@@ -85,9 +91,10 @@ AIGFM_LLM_BASE_URL="https://api.deepseek.com" # LLM API 地
|
|
|
85
91
|
AIGFM_LLM_MODEL="deepseek-v4-flash" # LLM 模型名称
|
|
86
92
|
AIGFM_ENABLED_GROUPS=[123456, 789012] # 启用的群号列表
|
|
87
93
|
|
|
88
|
-
# ---
|
|
89
|
-
AIGFM_IMAGE_MODE="
|
|
90
|
-
|
|
94
|
+
# --- 图片理解(多模态 LLM / VLM) ---
|
|
95
|
+
AIGFM_IMAGE_MODE="llm" # 图片模式: llm(默认,多模态统一模型)/ vlm(独立视觉模型)
|
|
96
|
+
AIGFM_LLM_MULTIMODAL="" # 主模型是否支持图片: 留空=启动时自动探测 / true=强制支持 / false=强制不支持并回落到 vlm
|
|
97
|
+
AIGFM_VLM_ENABLED=true # 是否启用VLM(vlm 模式必需;llm 模式主模型不支持图片时作为回落通道,默认 true)
|
|
91
98
|
AIGFM_VLM_MODEL="..." # VLM 模型名称(vlm 模式必填)
|
|
92
99
|
AIGFM_VLM_BASE_URL="https://..." # VLM API 地址
|
|
93
100
|
AIGFM_VLM_API_KEY="" # VLM API Key(为空时使用 llm 的 key)
|
|
@@ -125,10 +132,11 @@ AIGFM_ENERGY_BASELINE=0.7 # 社交能量基线(默认 0.7,范
|
|
|
125
132
|
|
|
126
133
|
# --- 联网搜索 ---
|
|
127
134
|
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
|
|
135
|
+
AIGFM_SEARCH_API=tavily # 搜索API: tavily / bocha / bing / openwebsearch / deepseek(默认 tavily)
|
|
136
|
+
AIGFM_SEARCH_API_KEY="xxx" # 搜索 API Key(api=tavily/bocha/bing 时必填;deepseek 留空则沿用 LLM Key)
|
|
130
137
|
AIGFM_SEARCH_MAX_RESULTS=3 # 最大搜索结果数(默认 3)
|
|
131
138
|
AIGFM_OPENWEBSEARCH_URL="" # open-websearch 本地服务地址(api=openwebsearch 时必填,如 http://127.0.0.1:3210)
|
|
139
|
+
AIGFM_SEARCH_BASE_URL="" # 搜索 API 根地址(api=deepseek 时用,留空则用官方 https://api.deepseek.com)
|
|
132
140
|
|
|
133
141
|
# --- 代理 ---
|
|
134
142
|
AIGFM_PROXY_ENABLED=false # 是否启用代理(默认 false)
|
|
@@ -167,7 +175,6 @@ AIGFM_ANIME_RECOGNIZE_MAX_CHARACTERS=3 # 展示的角色标签数量上限(
|
|
|
167
175
|
AIGFM_ANIME_NSFW_THRESHOLD=0.5 # explicit 概率超过该值标注 [NSFW](默认 0.5;仅本地后端提供画风分级)
|
|
168
176
|
AIGFM_ANIMETRACE_URL="https://api.animetrace.com" # AnimeTrace API 地址(公共 API、无需鉴权;识别会把图片上传到该服务)
|
|
169
177
|
AIGFM_ANIMETRACE_TIMEOUT=20.0 # AnimeTrace 请求超时/秒(默认 20.0)
|
|
170
|
-
AIGFM_ANIME_RECOGNIZE_ENABLED=false # 【已被 AIGFM_ANIME_BACKEND 取代,仅兼容保留】为 true 且 backend=off 时按 anime-recognize 处理
|
|
171
178
|
|
|
172
179
|
# --- 缓存清理 ---
|
|
173
180
|
AIGFM_IMAGE_CACHE_MAX_FILES=500 # 描述/角色识别缓存(image_cache 下的 JSON)最大数量,超出按 mtime 最旧删除(默认 500,0=不清理)
|
|
@@ -292,7 +299,7 @@ LLM 调用:invoke_plugin(command="决斗", parts=[
|
|
|
292
299
|
```
|
|
293
300
|
|
|
294
301
|
- `command` **只放命令名本身**;要 @ 的群友、附加文字等一律放进 `parts`
|
|
295
|
-
- `at`
|
|
302
|
+
- `at` 段按**群昵称或群名片**解析(与聊天记录里的 `@昵称` 一致),也接受直接给 QQ 号;解析不出会跳过该段,并在工具回执里提示
|
|
296
303
|
- 各段之间由程序补**一个**空格,不需要也不用自己加空格(多写的空格会被规整,避免出现双空格导致参数解析失败)
|
|
297
304
|
|
|
298
305
|
### 调用限制
|
|
@@ -447,6 +454,7 @@ LLM 可以:
|
|
|
447
454
|
| `bocha` | 国产 AI 搜索 API,中文搜索效果好 | 无 | https://open.bochaai.com |
|
|
448
455
|
| `bing` | 微软必应搜索(Azure Bing Search API v7) | 无 | https://portal.azure.com |
|
|
449
456
|
| `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 |
|
|
457
|
+
| `deepseek` | DeepSeek 自带联网搜索,摘要写得很适合喂给模型 | 无(`AIGFM_SEARCH_API_KEY` 留空则沿用 LLM Key) | https://platform.deepseek.com |
|
|
450
458
|
|
|
451
459
|
> **Tavily** 需额外安装依赖:`pip install tavily-python`(或安装本插件时带上 extra:`pip install "nonebot-plugin-aigf-master[tavily]"`)
|
|
452
460
|
|
|
@@ -543,8 +551,18 @@ memes/
|
|
|
543
551
|
|
|
544
552
|
| 模式 | 流程 | 适用场景 |
|
|
545
553
|
|------|------|---------|
|
|
546
|
-
| `
|
|
547
|
-
| `
|
|
554
|
+
| `llm`(默认) | 图片 → base64 直接附在 LLM prompt 中 | 主模型支持视觉;推荐用统一多模态模型 |
|
|
555
|
+
| `vlm` | 图片 → VLM 分析 → 文字描述给 LLM | 主 LLM 不支持图片输入 |
|
|
556
|
+
|
|
557
|
+
> 默认使用 `llm` 模式,适应当前主流多模态模型。若主 LLM 只能处理文字,请显式设置 `AIGFM_IMAGE_MODE=vlm` 并配置 VLM,否则图片请求可能被服务端拒绝。
|
|
558
|
+
|
|
559
|
+
`llm` 模式下主模型不支持图片时的自动回落:
|
|
560
|
+
|
|
561
|
+
- 启动时用一张 16×16 的小图探测一次主模型是否接受图片输入,探不过就自动回落到 `vlm` 模式(解析期把图片转成文字描述,请求期只发文本),存量用户升级后不会因为主模型只支持文本而整批不回复
|
|
562
|
+
- 运行期若带图请求被服务端明确拒绝(400/415/422),同样标记为不支持多模态,**下一批**消息起自动回落到 `vlm` 模式
|
|
563
|
+
- 回落到 `vlm` 模式需要 VLM 可用:没配 `AIGFM_VLM_MODEL` / `AIGFM_VLM_BASE_URL` 时图片只能以「识图失败」进上下文
|
|
564
|
+
- `AIGFM_LLM_MULTIMODAL` 可覆盖探测结果:`true` 强制按支持处理(跳过探测,不额外消耗请求)、`false` 强制按不支持处理并直接回落 `vlm`
|
|
565
|
+
- 探测本身出问题时(鉴权失败、限流、网络异常)不做判定,仍按支持处理,避免掩盖真实错误
|
|
548
566
|
|
|
549
567
|
`vlm` 模式下的行为说明:
|
|
550
568
|
|
|
@@ -561,7 +579,7 @@ memes/
|
|
|
561
579
|
| 后端 | 工作方式 | 擅长 | 代价 |
|
|
562
580
|
|---|---|---|---|
|
|
563
581
|
| `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 / 视觉小说角色,并给出作品名(如「胡桃(原神)」) |
|
|
582
|
+
| `animetrace` | [AnimeTrace](https://ai.animedb.cn/) 公共 API,**无需部署、无需鉴权** | gal / 视觉小说角色,并给出作品名(如「胡桃(原神)」) | 图片会上传到该第三方公共服务;有使用配额;不返回数值置信度、无画风分级;对gal以外游戏角色的识别率一般 |
|
|
565
583
|
|
|
566
584
|
`both` 模式先问本地服务,本地置信度不足(低于 `AIGFM_ANIME_RECOGNIZE_MIN_CONFIDENCE`)再问 AnimeTrace,两边都没有可信结果才渲染 `[角色识别: 未能识别]`——平时不消耗公共 API 配额。
|
|
567
585
|
|
|
@@ -572,8 +590,10 @@ memes/
|
|
|
572
590
|
```bash
|
|
573
591
|
git clone https://github.com/Funny1Potato/aigfm-anime-recognize.git
|
|
574
592
|
cd aigfm-anime-recognize
|
|
593
|
+
# 安装
|
|
575
594
|
# Windows: install.bat ;Linux/macOS: chmod +x install.sh && ./install.sh
|
|
576
|
-
#
|
|
595
|
+
# 启动
|
|
596
|
+
# Windows: start.bat ; Linux / macOS: chmod +x start.sh && ./start.sh
|
|
577
597
|
```
|
|
578
598
|
|
|
579
599
|
**插件配置**:
|
|
@@ -583,14 +603,14 @@ cd aigfm-anime-recognize
|
|
|
583
603
|
AIGFM_ANIME_BACKEND=both
|
|
584
604
|
|
|
585
605
|
# 本地后端地址(backend 含 anime-recognize 时必填;服务端未启用鉴权时 token 留空)
|
|
586
|
-
AIGFM_ANIME_RECOGNIZE_URL=http://127.0.0.1:8000
|
|
606
|
+
AIGFM_ANIME_RECOGNIZE_URL="http://127.0.0.1:8000"
|
|
587
607
|
# AIGFM_ANIME_RECOGNIZE_TOKEN=可选
|
|
588
608
|
|
|
589
609
|
# 可选调参(默认值如下)
|
|
590
610
|
# AIGFM_ANIME_RECOGNIZE_MIN_CONFIDENCE=0.85 # 展示角色标签的最低置信度;both 模式下也用它判断本地是否有结果
|
|
591
611
|
# AIGFM_ANIME_RECOGNIZE_MAX_CHARACTERS=3 # 展示的角色标签数量上限
|
|
592
612
|
# AIGFM_ANIME_NSFW_THRESHOLD=0.5 # explicit 概率超过该值标注 [NSFW](只标注不拦截;仅本地后端提供分级)
|
|
593
|
-
# AIGFM_ANIMETRACE_URL=https://api.animetrace.com
|
|
613
|
+
# AIGFM_ANIMETRACE_URL="https://api.animetrace.com"
|
|
594
614
|
# AIGFM_ANIMETRACE_TIMEOUT=20 # AnimeTrace 请求超时(秒)
|
|
595
615
|
```
|
|
596
616
|
|
|
@@ -612,8 +632,8 @@ AIGFM_ANIME_RECOGNIZE_URL=http://127.0.0.1:8000
|
|
|
612
632
|
- 改 `AIGFM_ANIME_RECOGNIZE_MIN_CONFIDENCE` 只影响此后新识别的图片;已缓存图片要重新判定需删除其 `{md5}_anime.json`
|
|
613
633
|
|
|
614
634
|
**已知局限**:
|
|
615
|
-
- **本地后端**:训练数据截止 2024 年前后,新游/新角色可能认不出,**gal / 视觉小说角色识别率尤其低(建议改用 `animetrace` 或 `both
|
|
616
|
-
- **AnimeTrace
|
|
635
|
+
- **本地后端**:训练数据截止 2024 年前后,新游/新角色可能认不出,**gal / 视觉小说角色识别率尤其低(建议改用 `animetrace` 或 `both`)**;多人合影可能会漏识别;3D 战斗小人/游戏内截图识别率不高;输出为英文标签(中文映射需自行扩展)
|
|
636
|
+
- **AnimeTrace**:对gal以外的游戏角色识别率一般;不返回数值置信度,只有服务自己的低置信判定——被判低置信时一律按「未能识别」处理,日志 `[角色识别] AnimeTrace 无可信结果,低置信候选: …` 会给出它认为最可能的候选,便于排查;其检测框可能包含误检,多人提示仅供参考;`[NSFW]` 标记只由本地后端提供
|
|
617
637
|
- 识别结果(角色名)会进入 LLM 上下文,也就是群里能看到;在意隐私请只用 `anime-recognize`(纯本地)或关闭本功能
|
|
618
638
|
|
|
619
639
|
> 仅 `AIGFM_IMAGE_MODE=vlm` 模式生效;`llm` 模式图片不经过 VLM,无二次元判断。
|
|
@@ -643,6 +663,29 @@ LLM 支持以下回复类型:
|
|
|
643
663
|
| @ | `{"type": "at", "name": "群友昵称"}` | 艾特群友 |
|
|
644
664
|
| 表情包 | `{"type": "meme", "id": "表情包id"}` | 发送表情包 |
|
|
645
665
|
|
|
666
|
+
> 要 @ 群友时应使用独立的 `at` 段。为兼容部分模型误把 `@昵称` 写进文本的情况,发送前也会把能匹配到群成员的文本 @ 自动转换为真实 QQ @。
|
|
667
|
+
|
|
668
|
+
## 📊 Token 消耗参考
|
|
669
|
+
|
|
670
|
+
以下是一组实测值:测试群约 120 人、活跃约 15 人,平均每天 400 条消息,一个月合计约 3.6 亿 tokens。
|
|
671
|
+
|
|
672
|
+
| 周期 | 消息量 | Token 消耗 |
|
|
673
|
+
|------|--------|------------|
|
|
674
|
+
| 每日 | ≈ 400 条 | ≈ 12M(1200 万) |
|
|
675
|
+
| 每周(按 4.3 周) | ≈ 2,800 条 | ≈ 84M(8400 万) |
|
|
676
|
+
| 每月(30 天) | ≈ 12,000 条 | ≈ 360M(3.6 亿) |
|
|
677
|
+
| 摊到每条消息 | — | ≈ 30k |
|
|
678
|
+
|
|
679
|
+
主要影响因素:
|
|
680
|
+
|
|
681
|
+
- **模型单价**:不同模型差别很大,建议先用便宜的模型跑量
|
|
682
|
+
- **图片**:默认的 `AIGFM_IMAGE_MODE=llm` 会把图片本体随主请求发送,费用按主模型的多模态输入计算;也可改用 `vlm`(另发一次识图请求),适合主模型不支持图片或希望使用轻量视觉模型的场景
|
|
683
|
+
- **联网搜索 / 生图 / 插件调用**:会额外产生调用轮次
|
|
684
|
+
- **批次大小**:`AIGFM_BATCH_COUNT` / `AIGFM_BATCH_TIMEOUT` 攒得越多,单次请求里的上下文(历史、记忆、命令清单)越长,但**请求次数越少**;调小则相反
|
|
685
|
+
- **启用的会话数**:每个群/频道各自独立计费
|
|
686
|
+
|
|
687
|
+
估算自己群的消耗:数日志里 `[处理] 群<群号> 调用 LLM` 的条数(= 调用次数),乘以服务商返回的平均 token 数即可。
|
|
688
|
+
|
|
646
689
|
## 📁 数据存储
|
|
647
690
|
|
|
648
691
|
```
|
|
@@ -73,14 +73,67 @@ _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,
|
|
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
|
|
|
81
85
|
_processors: dict[int, MessageProcessor] = {}
|
|
82
86
|
|
|
83
87
|
|
|
88
|
+
def _effective_image_mode() -> str:
|
|
89
|
+
"""实际生效的图片理解模式。
|
|
90
|
+
|
|
91
|
+
llm 模式下若主模型不支持图片输入(启动探测或运行期判定为不支持),自动回落到 vlm 模式:
|
|
92
|
+
解析期就把图片转成文字描述,请求期只发文本,不会整批请求失败。
|
|
93
|
+
"""
|
|
94
|
+
if plugin_config.aigfm_image_mode != "llm":
|
|
95
|
+
return plugin_config.aigfm_image_mode
|
|
96
|
+
return "llm" if _llm.multimodal else "vlm"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
async def _resolve_llm_multimodal():
|
|
100
|
+
"""判定主模型是否支持图片输入。
|
|
101
|
+
|
|
102
|
+
llm 模式下启动时探一次:探不过就回落到 vlm 模式,避免存量用户升级后
|
|
103
|
+
(默认模式变成 llm)因主模型只支持文本而整批请求失败。
|
|
104
|
+
显式配置 aigfm_llm_multimodal 时以配置为准,不再探测。
|
|
105
|
+
"""
|
|
106
|
+
if plugin_config.aigfm_image_mode != "llm":
|
|
107
|
+
return
|
|
108
|
+
forced = plugin_config.aigfm_llm_multimodal
|
|
109
|
+
if forced is True:
|
|
110
|
+
_llm.set_multimodal(True)
|
|
111
|
+
logger.success("[启动] 主模型多模态: 已按配置强制启用")
|
|
112
|
+
elif forced is False:
|
|
113
|
+
_llm.set_multimodal(False)
|
|
114
|
+
logger.warning("[启动] 主模型多模态: 已按配置关闭,图片理解回落到 VLM 模式")
|
|
115
|
+
else:
|
|
116
|
+
ok = await _llm.probe_multimodal(plugin_config.aigfm_llm_model)
|
|
117
|
+
if ok is True:
|
|
118
|
+
_llm.set_multimodal(True)
|
|
119
|
+
logger.success("[启动] 主模型多模态: 探测通过")
|
|
120
|
+
elif ok is False:
|
|
121
|
+
_llm.set_multimodal(False)
|
|
122
|
+
logger.warning("[启动] 主模型多模态: 探测不通过,图片理解回落到 VLM 模式")
|
|
123
|
+
else:
|
|
124
|
+
logger.warning(
|
|
125
|
+
"[启动] 主模型多模态: 探测未得出结论,按支持处理"
|
|
126
|
+
"(若带图请求失败,请显式设置 AIGFM_LLM_MULTIMODAL)")
|
|
127
|
+
if not _llm.multimodal and not (
|
|
128
|
+
plugin_config.aigfm_vlm_enabled
|
|
129
|
+
and plugin_config.aigfm_vlm_model
|
|
130
|
+
and plugin_config.aigfm_vlm_base_url
|
|
131
|
+
):
|
|
132
|
+
logger.error(
|
|
133
|
+
"[启动] 未配置 VLM(aigfm_vlm_model / aigfm_vlm_base_url),"
|
|
134
|
+
"回落后将无法识别图片")
|
|
135
|
+
|
|
136
|
+
|
|
84
137
|
def _get_processor(group_id: int) -> MessageProcessor:
|
|
85
138
|
if group_id not in _processors:
|
|
86
139
|
_processors[group_id] = MessageProcessor(
|
|
@@ -155,7 +208,7 @@ async def _parse_message(bot: Bot, event: GroupMessageEvent, message: Message, b
|
|
|
155
208
|
image_bytes = await _load_image_bytes(img)
|
|
156
209
|
image_base64 = base64.b64encode(image_bytes).decode()
|
|
157
210
|
|
|
158
|
-
if
|
|
211
|
+
if _effective_image_mode() == "llm":
|
|
159
212
|
cache_id = await _memes.save_to_cache(event.group_id, image_bytes, "", "")
|
|
160
213
|
content += f"\n[发送了一张图片, id: {cache_id}]\n"
|
|
161
214
|
else:
|
|
@@ -332,7 +385,7 @@ async def _extract_reply_content(bot: Bot, message_content, group_id: int) -> st
|
|
|
332
385
|
is_sticker = seg.data.get("sub_type") == 1
|
|
333
386
|
image_bytes = await _load_image_bytes(img)
|
|
334
387
|
image_base64 = base64.b64encode(image_bytes).decode()
|
|
335
|
-
if
|
|
388
|
+
if _effective_image_mode() == "llm":
|
|
336
389
|
cache_id = await _memes.save_to_cache(group_id, image_bytes, "", "")
|
|
337
390
|
parts.append(f"[发送了一张图片, id: {cache_id}]")
|
|
338
391
|
else:
|
|
@@ -789,6 +842,7 @@ async def handle_group_notice(bot: Bot, event: Event):
|
|
|
789
842
|
@get_driver().on_startup
|
|
790
843
|
async def _on_startup():
|
|
791
844
|
logger.success(f"[启动] 图片理解模式: {plugin_config.aigfm_image_mode}")
|
|
845
|
+
await _resolve_llm_multimodal()
|
|
792
846
|
anime_backend = effective_backend()
|
|
793
847
|
if anime_backend == "off":
|
|
794
848
|
logger.info("[启动] 二次元角色识别: 未启用")
|
|
@@ -15,9 +15,15 @@ class PluginConfig(BaseModel):
|
|
|
15
15
|
aigfm_llm_tools_json_strict: bool = Field(False, description="工具调用路径首次请求也强制 JSON 输出(部分 OpenAI 兼容服务不支持 tools+json_object 组合,开启前请确认服务商支持)")
|
|
16
16
|
aigfm_llm_temperature: float = Field(0.5, description="LLM 温度参数")
|
|
17
17
|
|
|
18
|
-
#
|
|
19
|
-
aigfm_image_mode: Literal["vlm", "llm"] = Field(
|
|
20
|
-
|
|
18
|
+
# 图片理解配置
|
|
19
|
+
aigfm_image_mode: Literal["vlm", "llm"] = Field(
|
|
20
|
+
"llm", description="图片理解模式(默认 llm;主模型不支持图片时自动回落 vlm)")
|
|
21
|
+
aigfm_llm_multimodal: bool | None = Field(
|
|
22
|
+
None,
|
|
23
|
+
description="主模型是否支持图片输入:未设置=启动时自动探测一次;true=强制按支持处理(跳过探测);false=强制按不支持处理并回落到 VLM 模式",
|
|
24
|
+
)
|
|
25
|
+
aigfm_vlm_enabled: bool = Field(
|
|
26
|
+
True, description="是否启用 VLM(vlm 模式必需;llm 模式下作为主模型不支持图片时的回落通道)")
|
|
21
27
|
aigfm_vlm_model: str = Field("", description="VLM 模型名称")
|
|
22
28
|
aigfm_vlm_base_url: str = Field("", description="VLM API 地址")
|
|
23
29
|
aigfm_vlm_api_key: str = Field("", description="VLM API Key(为空时使用 llm_api_key)")
|
|
@@ -64,10 +70,11 @@ class PluginConfig(BaseModel):
|
|
|
64
70
|
|
|
65
71
|
# 搜索
|
|
66
72
|
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
|
|
73
|
+
aigfm_search_api: Literal["tavily", "bocha", "bing", "openwebsearch", "deepseek"] = Field("tavily", description="搜索 API")
|
|
74
|
+
aigfm_search_api_key: str = Field("", description="搜索 API Key(tavily/bocha/bing 必填;deepseek 留空则用 LLM Key)")
|
|
69
75
|
aigfm_search_max_results: int = Field(3, description="最大搜索结果数")
|
|
70
76
|
aigfm_openwebsearch_url: str = Field("", description="open-websearch 本地服务地址(如 http://127.0.0.1:3210)")
|
|
77
|
+
aigfm_search_base_url: str = Field("", description="搜索 API 根地址(deepseek 用,留空则用官方 https://api.deepseek.com)")
|
|
71
78
|
|
|
72
79
|
# 代理
|
|
73
80
|
aigfm_proxy_enabled: bool = Field(False, description="是否启用代理")
|
|
@@ -28,9 +28,10 @@ class ImageHandler:
|
|
|
28
28
|
self._cache_dir.mkdir(parents=True, exist_ok=True)
|
|
29
29
|
self._anime = AnimeRecognizer(cache_dir)
|
|
30
30
|
self._vlm: VLMClient | None = None
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
# VLM 客户端:vlm 模式必需;llm 模式下还兼作「主模型不支持图片输入」时的回落通道,
|
|
32
|
+
# 因此只要配置齐全就建好,用不用由运行时的生效模式决定
|
|
33
|
+
vlm_ready = bool(plugin_config.aigfm_vlm_model and plugin_config.aigfm_vlm_base_url)
|
|
34
|
+
if plugin_config.aigfm_vlm_enabled and vlm_ready:
|
|
34
35
|
api_key = plugin_config.aigfm_vlm_api_key or plugin_config.aigfm_llm_api_key
|
|
35
36
|
proxy = (plugin_config.aigfm_https_proxy or plugin_config.aigfm_http_proxy) if plugin_config.aigfm_proxy_enabled else None
|
|
36
37
|
self._vlm = VLMClient(
|
|
@@ -38,6 +39,8 @@ class ImageHandler:
|
|
|
38
39
|
base_url=plugin_config.aigfm_vlm_base_url,
|
|
39
40
|
http_client=make_http_client(proxy),
|
|
40
41
|
)
|
|
42
|
+
elif plugin_config.aigfm_image_mode == "vlm" and plugin_config.aigfm_vlm_enabled:
|
|
43
|
+
raise ValueError("VLM 模式已启用,但 vlm_model 或 vlm_base_url 未配置")
|
|
41
44
|
|
|
42
45
|
async def warmup_anime(self) -> None:
|
|
43
46
|
"""启动预热角色识别后端(目前仅有 AnimeTrace 的模型列表查询)"""
|