nonebot-plugin-aigf-master 1.5.2__tar.gz → 1.5.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.5.2 → nonebot_plugin_aigf_master-1.5.4}/PKG-INFO +12 -4
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/README.md +11 -3
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/__init__.py +2 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/config.py +3 -1
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/peer_client.py +3 -2
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/plugin_invoker.py +9 -4
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/processor.py +26 -11
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/prompt_builder.py +1 -1
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master.egg-info/PKG-INFO +12 -4
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/pyproject.toml +1 -1
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/LICENSE +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/api_hooks.py +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/command_learner.py +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/context_bus.py +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/image_gen_client.py +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/image_handler.py +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/llm_client.py +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/meme_store.py +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/memory_store.py +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/message_builder.py +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/models.py +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/plugin_discovery.py +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/preset_store.py +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/response_parser.py +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/search_client.py +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master/vlm_client.py +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master.egg-info/SOURCES.txt +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master.egg-info/dependency_links.txt +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master.egg-info/requires.txt +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.4}/nonebot_plugin_aigf_master.egg-info/top_level.txt +0 -0
- {nonebot_plugin_aigf_master-1.5.2 → nonebot_plugin_aigf_master-1.5.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.5.
|
|
3
|
+
Version: 1.5.4
|
|
4
4
|
Summary: 群聊特化LLM聊天机器人(增强版),具有记忆、表情包、跨插件调用和跨bot通信能力
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Requires-Python: <4.0,>=3.10
|
|
@@ -164,7 +164,9 @@ AIGFM_STICKER_CACHE_MAX_FILES=300 # 图片缓存文件(sticker_cache)
|
|
|
164
164
|
# --- 插件调用 ---
|
|
165
165
|
AIGFM_INVOKE_ENABLED=true # 是否允许 LLM 调用其它插件(默认 true)
|
|
166
166
|
AIGFM_INVOKE_TIMEOUT=30.0 # 插件调用超时时间(秒,默认 30.0)
|
|
167
|
-
AIGFM_INVOKE_DEDUP_ENABLED=true # 拒绝调用最近调用过的相同命令(默认 true
|
|
167
|
+
AIGFM_INVOKE_DEDUP_ENABLED=true # 拒绝调用最近调用过的相同命令(默认 true;命令+参数+调用身份完全相同)
|
|
168
|
+
AIGFM_INVOKE_DEDUP_WINDOW=1200.0 # 去重时间窗口(秒,默认 1200 = 20 分钟;0 = 不限时间,只看最近 N 条台账)
|
|
169
|
+
AIGFM_INVOKE_DEDUP_RECORDS=15 # 去重比对保留的调用台账条数(默认 15;prompt 里只展示其中最近 10 条)
|
|
168
170
|
AIGFM_INVOKE_ENERGY_COST=0.1 # 每次调用插件消耗的社交能量(默认 0.1;0 表示不消耗)
|
|
169
171
|
AIGFM_INVOKE_ENERGY_MIN=0.4 # 社交能量低于此值时拒绝调用插件(默认 0.4;0 表示不限制)
|
|
170
172
|
|
|
@@ -305,10 +307,16 @@ LLM 调用:invoke_plugin(command="决斗", parts=[
|
|
|
305
307
|
| 限制 | 默认 | 配置项 |
|
|
306
308
|
|---|---|---|
|
|
307
309
|
| **重复调用去重** | 开启 | `AIGFM_INVOKE_DEDUP_ENABLED` |
|
|
310
|
+
| **去重时间窗口** | 20 分钟 | `AIGFM_INVOKE_DEDUP_WINDOW`(秒;0 = 不限时间) |
|
|
311
|
+
| **去重比对条数** | 15 | `AIGFM_INVOKE_DEDUP_RECORDS` |
|
|
308
312
|
| **每次调用消耗能量** | 0.1 | `AIGFM_INVOKE_ENERGY_COST`(0 = 不消耗) |
|
|
309
313
|
| **能量门槛** | 低于 0.4 拒绝 | `AIGFM_INVOKE_ENERGY_MIN`(0 = 不限制) |
|
|
310
314
|
|
|
311
|
-
- 去重判定为**命令 + 参数 + 调用身份(QQ
|
|
315
|
+
- 去重判定为**命令 + 参数 + 调用身份(QQ 号)三者完全相同**;拦截范围 = **时间窗口内**(`AIGFM_INVOKE_DEDUP_WINDOW`)∩ **调用台账保留的最近 N 条**(`AIGFM_INVOKE_DEDUP_RECORDS`)
|
|
316
|
+
- **不区分本机与其它 bot**:同一命令、同一身份在范围内只执行一次
|
|
317
|
+
- 换个参数(`决斗 @张三` → `决斗 @李四`)或换个身份(不同 QQ 号)视为不同调用,正常放行
|
|
318
|
+
- prompt 里的「你最近代为执行过的命令」段只展示**其中最近 10 条**(防止 prompt 随条数膨胀)
|
|
319
|
+
- 执行 `/reset` 会一并清空调用台账(重置后不再被"刚调用过"挡住)
|
|
312
320
|
- 每次**实际投递**扣 `AIGFM_INVOKE_ENERGY_COST` 点社交能量(被拒绝时不扣);能量会按社交能量机制自然回充,所以能量不足只是暂时无法代为执行命令
|
|
313
321
|
- 被拒绝时:工具结果**当场**告知 LLM 原因,同时在聊天记录里留下 `已拒绝调用命令「xxx」(原因)`,**下一轮** LLM 能看到;拒绝**不写入调用台账**(不会阻止之后真正的再调用)
|
|
314
322
|
|
|
@@ -350,7 +358,7 @@ LLM 只能调用 prompt 里「可用的群功能」/「其它 bot 的命令」
|
|
|
350
358
|
| 需要管理员 / 群主 / 超级用户权限 | `sender.role` 固定为 `"member"`,且传入的 `user_id` 一般不在 `SUPERUSERS` 内,权限检查直接拒绝 |
|
|
351
359
|
| 私聊命令 | 合成事件固定 `message_type="group"`,不会命中只监听私聊的 Matcher |
|
|
352
360
|
| 必须先回复/引用某条消息才能执行 | 合成事件的 `reply` 恒为 `None`,且真实消息里的 `reply` 段会被适配器展开,这里没有 |
|
|
353
|
-
| 依赖群名片 / 头衔 / 等级 / 地区判断身份 | `sender` 只填 `user_id`、`nickname
|
|
361
|
+
| 依赖群名片 / 头衔 / 等级 / 地区判断身份 | `sender` 只填 `user_id`、`nickname`(当前群预设名,默认「小助手」;peer 侧由 Bot A 传入同一名字)、`role`,其余字段为空 |
|
|
354
362
|
| 依赖真实 `message_id` 的后续操作 | `message_id` 是占位值 `0`,插件拿它去 `get_msg` / 撤回 / 引用回复会失败 |
|
|
355
363
|
|
|
356
364
|
两点补充:
|
|
@@ -144,7 +144,9 @@ AIGFM_STICKER_CACHE_MAX_FILES=300 # 图片缓存文件(sticker_cache)
|
|
|
144
144
|
# --- 插件调用 ---
|
|
145
145
|
AIGFM_INVOKE_ENABLED=true # 是否允许 LLM 调用其它插件(默认 true)
|
|
146
146
|
AIGFM_INVOKE_TIMEOUT=30.0 # 插件调用超时时间(秒,默认 30.0)
|
|
147
|
-
AIGFM_INVOKE_DEDUP_ENABLED=true # 拒绝调用最近调用过的相同命令(默认 true
|
|
147
|
+
AIGFM_INVOKE_DEDUP_ENABLED=true # 拒绝调用最近调用过的相同命令(默认 true;命令+参数+调用身份完全相同)
|
|
148
|
+
AIGFM_INVOKE_DEDUP_WINDOW=1200.0 # 去重时间窗口(秒,默认 1200 = 20 分钟;0 = 不限时间,只看最近 N 条台账)
|
|
149
|
+
AIGFM_INVOKE_DEDUP_RECORDS=15 # 去重比对保留的调用台账条数(默认 15;prompt 里只展示其中最近 10 条)
|
|
148
150
|
AIGFM_INVOKE_ENERGY_COST=0.1 # 每次调用插件消耗的社交能量(默认 0.1;0 表示不消耗)
|
|
149
151
|
AIGFM_INVOKE_ENERGY_MIN=0.4 # 社交能量低于此值时拒绝调用插件(默认 0.4;0 表示不限制)
|
|
150
152
|
|
|
@@ -285,10 +287,16 @@ LLM 调用:invoke_plugin(command="决斗", parts=[
|
|
|
285
287
|
| 限制 | 默认 | 配置项 |
|
|
286
288
|
|---|---|---|
|
|
287
289
|
| **重复调用去重** | 开启 | `AIGFM_INVOKE_DEDUP_ENABLED` |
|
|
290
|
+
| **去重时间窗口** | 20 分钟 | `AIGFM_INVOKE_DEDUP_WINDOW`(秒;0 = 不限时间) |
|
|
291
|
+
| **去重比对条数** | 15 | `AIGFM_INVOKE_DEDUP_RECORDS` |
|
|
288
292
|
| **每次调用消耗能量** | 0.1 | `AIGFM_INVOKE_ENERGY_COST`(0 = 不消耗) |
|
|
289
293
|
| **能量门槛** | 低于 0.4 拒绝 | `AIGFM_INVOKE_ENERGY_MIN`(0 = 不限制) |
|
|
290
294
|
|
|
291
|
-
- 去重判定为**命令 + 参数 + 调用身份(QQ
|
|
295
|
+
- 去重判定为**命令 + 参数 + 调用身份(QQ 号)三者完全相同**;拦截范围 = **时间窗口内**(`AIGFM_INVOKE_DEDUP_WINDOW`)∩ **调用台账保留的最近 N 条**(`AIGFM_INVOKE_DEDUP_RECORDS`)
|
|
296
|
+
- **不区分本机与其它 bot**:同一命令、同一身份在范围内只执行一次
|
|
297
|
+
- 换个参数(`决斗 @张三` → `决斗 @李四`)或换个身份(不同 QQ 号)视为不同调用,正常放行
|
|
298
|
+
- prompt 里的「你最近代为执行过的命令」段只展示**其中最近 10 条**(防止 prompt 随条数膨胀)
|
|
299
|
+
- 执行 `/reset` 会一并清空调用台账(重置后不再被"刚调用过"挡住)
|
|
292
300
|
- 每次**实际投递**扣 `AIGFM_INVOKE_ENERGY_COST` 点社交能量(被拒绝时不扣);能量会按社交能量机制自然回充,所以能量不足只是暂时无法代为执行命令
|
|
293
301
|
- 被拒绝时:工具结果**当场**告知 LLM 原因,同时在聊天记录里留下 `已拒绝调用命令「xxx」(原因)`,**下一轮** LLM 能看到;拒绝**不写入调用台账**(不会阻止之后真正的再调用)
|
|
294
302
|
|
|
@@ -330,7 +338,7 @@ LLM 只能调用 prompt 里「可用的群功能」/「其它 bot 的命令」
|
|
|
330
338
|
| 需要管理员 / 群主 / 超级用户权限 | `sender.role` 固定为 `"member"`,且传入的 `user_id` 一般不在 `SUPERUSERS` 内,权限检查直接拒绝 |
|
|
331
339
|
| 私聊命令 | 合成事件固定 `message_type="group"`,不会命中只监听私聊的 Matcher |
|
|
332
340
|
| 必须先回复/引用某条消息才能执行 | 合成事件的 `reply` 恒为 `None`,且真实消息里的 `reply` 段会被适配器展开,这里没有 |
|
|
333
|
-
| 依赖群名片 / 头衔 / 等级 / 地区判断身份 | `sender` 只填 `user_id`、`nickname
|
|
341
|
+
| 依赖群名片 / 头衔 / 等级 / 地区判断身份 | `sender` 只填 `user_id`、`nickname`(当前群预设名,默认「小助手」;peer 侧由 Bot A 传入同一名字)、`role`,其余字段为空 |
|
|
334
342
|
| 依赖真实 `message_id` 的后续操作 | `message_id` 是占位值 `0`,插件拿它去 `get_msg` / 撤回 / 引用回复会失败 |
|
|
335
343
|
|
|
336
344
|
两点补充:
|
|
@@ -642,6 +642,8 @@ async def _(event: GroupMessageEvent):
|
|
|
642
642
|
processor.context_bus.clear(int(event.group_id))
|
|
643
643
|
# 图片缓存索引随聊天记录一起清(历史 id 已不在 prompt 中,留着也无可收藏的上下文)
|
|
644
644
|
_memes.clear_cache(int(event.group_id))
|
|
645
|
+
# 调用台账一起清:重置后不应再被「刚调用过同一条命令」挡住
|
|
646
|
+
processor._invoke_log.clear()
|
|
645
647
|
processor.social_energy = 0.75
|
|
646
648
|
await processor.load_preset(plugin_config.aigfm_default_preset)
|
|
647
649
|
await reset_cmd.finish("已重置会话")
|
|
@@ -71,7 +71,9 @@ class PluginConfig(BaseModel):
|
|
|
71
71
|
# 插件调用
|
|
72
72
|
aigfm_invoke_enabled: bool = Field(True, description="是否允许 LLM 调用其它插件")
|
|
73
73
|
aigfm_invoke_timeout: float = Field(30.0, description="插件调用超时时间(秒)")
|
|
74
|
-
aigfm_invoke_dedup_enabled: bool = Field(True, description="
|
|
74
|
+
aigfm_invoke_dedup_enabled: bool = Field(True, description="拒绝调用最近调用过的相同命令(命令+参数+调用身份完全相同)")
|
|
75
|
+
aigfm_invoke_dedup_window: float = Field(1200.0, description="去重时间窗口(秒,默认 1200=20 分钟;0=不限时间,只看最近 N 条台账)")
|
|
76
|
+
aigfm_invoke_dedup_records: int = Field(15, description="去重比对保留的调用台账条数(默认 15;prompt 里只展示其中最近 10 条)")
|
|
75
77
|
aigfm_invoke_energy_cost: float = Field(0.1, description="每次调用插件消耗的社交能量(0 表示不消耗)")
|
|
76
78
|
aigfm_invoke_energy_min: float = Field(0.4, description="社交能量低于此值时拒绝调用插件(0 表示不限制)")
|
|
77
79
|
|
|
@@ -19,10 +19,11 @@ class PeerClient:
|
|
|
19
19
|
|
|
20
20
|
async def invoke(self, peer_name: str, command: str, group_id: int, user_id: int = 0,
|
|
21
21
|
parts: list[dict] | None = None, at_user_id: int = 0,
|
|
22
|
-
timeout: float = 30.0) -> str:
|
|
22
|
+
timeout: float = 30.0, sender_name: str = "") -> str:
|
|
23
23
|
"""远程调用其它 bot 的插件命令,返回确认信息
|
|
24
24
|
|
|
25
25
|
parts 为命令参数段(at 已在本侧解析成数字),at_user_id 取首个 at 供未升级的 peer 兼容。
|
|
26
|
+
sender_name 是对方合成事件的发送者昵称(当前群预设名),未升级的 peer 会忽略该字段。
|
|
26
27
|
插件执行结果由对方 on_calling_api 钩子推送到本 bot 的 /peer/capture,
|
|
27
28
|
因此这里只负责发出调用请求并返回执行确认。
|
|
28
29
|
"""
|
|
@@ -32,7 +33,7 @@ class PeerClient:
|
|
|
32
33
|
url = f"http://127.0.0.1:{cfg['port']}/peer/invoke"
|
|
33
34
|
headers = {"Authorization": f"Bearer {cfg.get('token', '')}"}
|
|
34
35
|
payload = {"command": command, "group_id": group_id, "user_id": user_id,
|
|
35
|
-
"parts": parts or [], "at_user_id": at_user_id}
|
|
36
|
+
"parts": parts or [], "at_user_id": at_user_id, "name": sender_name}
|
|
36
37
|
try:
|
|
37
38
|
async with httpx.AsyncClient(timeout=timeout) as client:
|
|
38
39
|
resp = await client.post(url, json=payload, headers=headers)
|
|
@@ -47,13 +47,15 @@ class PluginInvoker:
|
|
|
47
47
|
return id(event) in self._synthetic or bool(getattr(event, SYNTHETIC_FLAG, False))
|
|
48
48
|
|
|
49
49
|
async def invoke(self, bot, group_id: int, command: str, timeout: float = 30.0,
|
|
50
|
-
user_id: int = 0, parts: list[dict] | None = None
|
|
50
|
+
user_id: int = 0, parts: list[dict] | None = None,
|
|
51
|
+
sender_name: str = "aigf_user") -> InvokeResult:
|
|
51
52
|
"""投递命令并等待分发结束
|
|
52
53
|
|
|
53
54
|
Args:
|
|
54
55
|
user_id: 触发命令的用户 QQ 号,用于需要读取发送者信息的命令
|
|
55
56
|
parts: 命令参数段(与回复的 reply 字段同结构),如 [{"type":"at","target":12345}];
|
|
56
57
|
条目之间会以空格拼在命令之后
|
|
58
|
+
sender_name: 合成事件的发送者昵称,调用方传当前群预设名;空值回落 aigf_user
|
|
57
59
|
|
|
58
60
|
返回投递结果,不代表插件是否回复。超时只取消本次分发,
|
|
59
61
|
插件稍后的输出仍会经钩子进入消息缓冲区。
|
|
@@ -62,7 +64,7 @@ class PluginInvoker:
|
|
|
62
64
|
event = None
|
|
63
65
|
|
|
64
66
|
try:
|
|
65
|
-
event = await self._create_synthetic_event(bot, group_id, command, user_id, parts)
|
|
67
|
+
event = await self._create_synthetic_event(bot, group_id, command, user_id, parts, sender_name)
|
|
66
68
|
self._synthetic[id(event)] = event
|
|
67
69
|
await asyncio.wait_for(handle_event(bot, event), timeout=timeout)
|
|
68
70
|
except asyncio.TimeoutError:
|
|
@@ -79,7 +81,8 @@ class PluginInvoker:
|
|
|
79
81
|
|
|
80
82
|
@staticmethod
|
|
81
83
|
async def _create_synthetic_event(bot, group_id: int, command: str, user_id: int = 0,
|
|
82
|
-
parts: list[dict] | None = None
|
|
84
|
+
parts: list[dict] | None = None,
|
|
85
|
+
sender_name: str = "aigf_user") -> GroupMessageEvent:
|
|
83
86
|
"""创建模拟的群消息事件(消息拼装与回复发送共用 message_builder.compose_messages)"""
|
|
84
87
|
# LLM 传无前缀命令,这里按本 bot 配置的命令前缀补充
|
|
85
88
|
command = _apply_command_prefix(command)
|
|
@@ -101,6 +104,8 @@ class PluginInvoker:
|
|
|
101
104
|
message=message,
|
|
102
105
|
raw_message=command,
|
|
103
106
|
font=0,
|
|
104
|
-
sender={"user_id": user_id,
|
|
107
|
+
sender={"user_id": user_id,
|
|
108
|
+
"nickname": (sender_name or "").strip() or "aigf_user",
|
|
109
|
+
"role": "member"},
|
|
105
110
|
**{SYNTHETIC_FLAG: True},
|
|
106
111
|
)
|
|
@@ -142,6 +142,10 @@ def _parts_key(parts: list[dict] | None) -> str:
|
|
|
142
142
|
return str(parts)
|
|
143
143
|
|
|
144
144
|
|
|
145
|
+
# 调用台账注入 prompt 时最多展示的条数(比对的台账条数由 aigfm_invoke_dedup_records 控制)
|
|
146
|
+
_LEDGER_DISPLAY = 10
|
|
147
|
+
|
|
148
|
+
|
|
145
149
|
class MessageProcessor:
|
|
146
150
|
"""消息处理编排器,协调所有组件"""
|
|
147
151
|
|
|
@@ -207,33 +211,43 @@ class MessageProcessor:
|
|
|
207
211
|
time=datetime.now(), command=command,
|
|
208
212
|
parts_key=_parts_key(parts), user_id=str(user_id), label=label,
|
|
209
213
|
))
|
|
210
|
-
|
|
211
|
-
|
|
214
|
+
keep = max(1, self.config.aigfm_invoke_dedup_records)
|
|
215
|
+
if len(self._invoke_log) > keep:
|
|
216
|
+
self._invoke_log = self._invoke_log[-keep:]
|
|
217
|
+
|
|
218
|
+
def _dedup_window(self) -> float:
|
|
219
|
+
"""去重时间窗口(秒);0 表示不限时间(只看最近 N 条台账)"""
|
|
220
|
+
return max(0.0, self.config.aigfm_invoke_dedup_window)
|
|
212
221
|
|
|
213
222
|
def _recent_invocations(self) -> list[str]:
|
|
214
|
-
"""
|
|
223
|
+
"""渲染台账段:参与拦截的条目里取最近 _LEDGER_DISPLAY 条
|
|
215
224
|
|
|
216
|
-
|
|
225
|
+
- 只展示时间窗口内的记录(窗口为 0 时不按时间过滤),与拦截口径一致,避免"段里看不到却仍被拦"
|
|
226
|
+
- 展示条数固定,prompt 不随 aigfm_invoke_dedup_records 膨胀
|
|
227
|
+
- 带相对时间,便于模型判断"之后有没有新要求"
|
|
217
228
|
"""
|
|
218
229
|
now = datetime.now()
|
|
230
|
+
window = self._dedup_window()
|
|
231
|
+
visible = [rec for rec in self._invoke_log
|
|
232
|
+
if window == 0 or (now - rec.time).total_seconds() <= window]
|
|
219
233
|
lines: list[str] = []
|
|
220
|
-
for rec in
|
|
234
|
+
for rec in visible[-_LEDGER_DISPLAY:]:
|
|
221
235
|
delta = (now - rec.time).total_seconds()
|
|
222
|
-
if delta > 300:
|
|
223
|
-
continue
|
|
224
236
|
rel = "刚刚" if delta < 60 else f"{int(delta // 60)} 分钟前"
|
|
225
237
|
lines.append(f"- {rec.time.strftime('%H:%M:%S')}({rel}){rec.label}")
|
|
226
238
|
return lines
|
|
227
239
|
|
|
228
240
|
def _find_recent_same(self, command: str, parts: list[dict], user_id) -> bool:
|
|
229
|
-
"""
|
|
241
|
+
"""台账中是否已有完全相同的调用(命令 + 参数 + 调用身份;不区分本机/peer)
|
|
230
242
|
|
|
231
|
-
|
|
243
|
+
命中条件:身份全等,且记录在时间窗口内(窗口为 0 时不限时间)。
|
|
244
|
+
拦截范围 = 「时间窗口内」∩「台账保留的最近 N 条」(N 由 aigfm_invoke_dedup_records 控制)。
|
|
232
245
|
"""
|
|
233
246
|
now = datetime.now()
|
|
247
|
+
window = self._dedup_window()
|
|
234
248
|
key, uid = _parts_key(parts), str(user_id)
|
|
235
249
|
return any(
|
|
236
|
-
(now - rec.time).total_seconds() <=
|
|
250
|
+
(window == 0 or (now - rec.time).total_seconds() <= window)
|
|
237
251
|
and rec.command == command and rec.parts_key == key and rec.user_id == uid
|
|
238
252
|
for rec in self._invoke_log
|
|
239
253
|
)
|
|
@@ -577,7 +591,7 @@ class MessageProcessor:
|
|
|
577
591
|
return gate
|
|
578
592
|
outcome = await self.invoker.invoke(
|
|
579
593
|
self._bot, int(self.group_id), command, self.config.aigfm_invoke_timeout,
|
|
580
|
-
user_id=uid, parts=parts,
|
|
594
|
+
user_id=uid, parts=parts, sender_name=self.bot_name,
|
|
581
595
|
)
|
|
582
596
|
self._consume_invoke_energy()
|
|
583
597
|
# 记录 bot 自述,让下一次批处理时 LLM 知道这条命令是自己发起的(含选用身份)
|
|
@@ -614,6 +628,7 @@ class MessageProcessor:
|
|
|
614
628
|
result = await self.peer_client.invoke(
|
|
615
629
|
peer_name, command, int(self.group_id), uid,
|
|
616
630
|
parts=parts, at_user_id=first_at, timeout=self.config.aigfm_invoke_timeout,
|
|
631
|
+
sender_name=self.bot_name,
|
|
617
632
|
)
|
|
618
633
|
self._consume_invoke_energy()
|
|
619
634
|
self.recent_messages.append(ChatMessage(
|
|
@@ -187,7 +187,7 @@ def build_prompt(
|
|
|
187
187
|
invoke_ledger_section = f"""
|
|
188
188
|
## 你最近代为执行过的命令
|
|
189
189
|
{ledger_str}
|
|
190
|
-
|
|
190
|
+
上面这些命令**近期已经替群友执行过了**(时间见每行),**不要再用工具执行同一条命令**。注意:
|
|
191
191
|
- **原来那条请求还在聊天记录里,不构成重做的理由**——它已经处理过了;只有群友在这条记录的时间**之后**又新提出明确要求,才可以重做
|
|
192
192
|
- 调用后没看到插件响应是**正常**的(响应要等下一批才会作为新消息出现,生图类命令更慢),**看不到响应不等于失败**,不要因此重复调用;最多对群友说一句"稍等"
|
|
193
193
|
- 系统层面还会兜底拦一次:**完全相同的命令(命令+参数+调用身份)短时间内再调会被直接拒绝**,**社交能量不足时也会被拒绝**——遇到拒绝(聊天记录里会出现 `已拒绝调用命令「xxx」`)不要重试
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nonebot-plugin-aigf-master
|
|
3
|
-
Version: 1.5.
|
|
3
|
+
Version: 1.5.4
|
|
4
4
|
Summary: 群聊特化LLM聊天机器人(增强版),具有记忆、表情包、跨插件调用和跨bot通信能力
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Requires-Python: <4.0,>=3.10
|
|
@@ -164,7 +164,9 @@ AIGFM_STICKER_CACHE_MAX_FILES=300 # 图片缓存文件(sticker_cache)
|
|
|
164
164
|
# --- 插件调用 ---
|
|
165
165
|
AIGFM_INVOKE_ENABLED=true # 是否允许 LLM 调用其它插件(默认 true)
|
|
166
166
|
AIGFM_INVOKE_TIMEOUT=30.0 # 插件调用超时时间(秒,默认 30.0)
|
|
167
|
-
AIGFM_INVOKE_DEDUP_ENABLED=true # 拒绝调用最近调用过的相同命令(默认 true
|
|
167
|
+
AIGFM_INVOKE_DEDUP_ENABLED=true # 拒绝调用最近调用过的相同命令(默认 true;命令+参数+调用身份完全相同)
|
|
168
|
+
AIGFM_INVOKE_DEDUP_WINDOW=1200.0 # 去重时间窗口(秒,默认 1200 = 20 分钟;0 = 不限时间,只看最近 N 条台账)
|
|
169
|
+
AIGFM_INVOKE_DEDUP_RECORDS=15 # 去重比对保留的调用台账条数(默认 15;prompt 里只展示其中最近 10 条)
|
|
168
170
|
AIGFM_INVOKE_ENERGY_COST=0.1 # 每次调用插件消耗的社交能量(默认 0.1;0 表示不消耗)
|
|
169
171
|
AIGFM_INVOKE_ENERGY_MIN=0.4 # 社交能量低于此值时拒绝调用插件(默认 0.4;0 表示不限制)
|
|
170
172
|
|
|
@@ -305,10 +307,16 @@ LLM 调用:invoke_plugin(command="决斗", parts=[
|
|
|
305
307
|
| 限制 | 默认 | 配置项 |
|
|
306
308
|
|---|---|---|
|
|
307
309
|
| **重复调用去重** | 开启 | `AIGFM_INVOKE_DEDUP_ENABLED` |
|
|
310
|
+
| **去重时间窗口** | 20 分钟 | `AIGFM_INVOKE_DEDUP_WINDOW`(秒;0 = 不限时间) |
|
|
311
|
+
| **去重比对条数** | 15 | `AIGFM_INVOKE_DEDUP_RECORDS` |
|
|
308
312
|
| **每次调用消耗能量** | 0.1 | `AIGFM_INVOKE_ENERGY_COST`(0 = 不消耗) |
|
|
309
313
|
| **能量门槛** | 低于 0.4 拒绝 | `AIGFM_INVOKE_ENERGY_MIN`(0 = 不限制) |
|
|
310
314
|
|
|
311
|
-
- 去重判定为**命令 + 参数 + 调用身份(QQ
|
|
315
|
+
- 去重判定为**命令 + 参数 + 调用身份(QQ 号)三者完全相同**;拦截范围 = **时间窗口内**(`AIGFM_INVOKE_DEDUP_WINDOW`)∩ **调用台账保留的最近 N 条**(`AIGFM_INVOKE_DEDUP_RECORDS`)
|
|
316
|
+
- **不区分本机与其它 bot**:同一命令、同一身份在范围内只执行一次
|
|
317
|
+
- 换个参数(`决斗 @张三` → `决斗 @李四`)或换个身份(不同 QQ 号)视为不同调用,正常放行
|
|
318
|
+
- prompt 里的「你最近代为执行过的命令」段只展示**其中最近 10 条**(防止 prompt 随条数膨胀)
|
|
319
|
+
- 执行 `/reset` 会一并清空调用台账(重置后不再被"刚调用过"挡住)
|
|
312
320
|
- 每次**实际投递**扣 `AIGFM_INVOKE_ENERGY_COST` 点社交能量(被拒绝时不扣);能量会按社交能量机制自然回充,所以能量不足只是暂时无法代为执行命令
|
|
313
321
|
- 被拒绝时:工具结果**当场**告知 LLM 原因,同时在聊天记录里留下 `已拒绝调用命令「xxx」(原因)`,**下一轮** LLM 能看到;拒绝**不写入调用台账**(不会阻止之后真正的再调用)
|
|
314
322
|
|
|
@@ -350,7 +358,7 @@ LLM 只能调用 prompt 里「可用的群功能」/「其它 bot 的命令」
|
|
|
350
358
|
| 需要管理员 / 群主 / 超级用户权限 | `sender.role` 固定为 `"member"`,且传入的 `user_id` 一般不在 `SUPERUSERS` 内,权限检查直接拒绝 |
|
|
351
359
|
| 私聊命令 | 合成事件固定 `message_type="group"`,不会命中只监听私聊的 Matcher |
|
|
352
360
|
| 必须先回复/引用某条消息才能执行 | 合成事件的 `reply` 恒为 `None`,且真实消息里的 `reply` 段会被适配器展开,这里没有 |
|
|
353
|
-
| 依赖群名片 / 头衔 / 等级 / 地区判断身份 | `sender` 只填 `user_id`、`nickname
|
|
361
|
+
| 依赖群名片 / 头衔 / 等级 / 地区判断身份 | `sender` 只填 `user_id`、`nickname`(当前群预设名,默认「小助手」;peer 侧由 Bot A 传入同一名字)、`role`,其余字段为空 |
|
|
354
362
|
| 依赖真实 `message_id` 的后续操作 | `message_id` 是占位值 `0`,插件拿它去 `get_msg` / 撤回 / 引用回复会失败 |
|
|
355
363
|
|
|
356
364
|
两点补充:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|