first commit
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
# 艾特机器人对话
|
||||
|
||||
从微信成员列表真正艾特机器人,再附上问题,即可触发回复。只键入看起来像 `@昵称` 的普通文字不会触发;艾特别人也不会触发。
|
||||
|
||||
上下文为发言者在当前群、当天、此前最多十条有效文字,不混入其他人、其他群、控制指令和机器人的输出。回复采用本群当前人格,并真正艾特原发言者。
|
||||
|
||||
显示名字优先使用该成员的本群绑定,未绑定时使用缓存中取得的微信名。功能需要成员记录、有效的模型配置和启用的 `mention_chat` 插件。
|
||||
|
||||
清空、跨天、账号切换或人格变化会取消尚未发出的旧回复。
|
||||
@@ -0,0 +1,42 @@
|
||||
"""真正艾特机器人后,用本群人格回复当前发言者。"""
|
||||
from wxbot_framework.dialogue import Dialogue
|
||||
from wxbot_framework.llm import LLMError
|
||||
from wxbot_framework.members import SnapshotExpired
|
||||
from wxbot_framework.personality import personality_text
|
||||
from wxbot_framework.summary import split_text
|
||||
|
||||
|
||||
class Plugin:
|
||||
def on_load(self, ctx):
|
||||
self.members = ctx.members
|
||||
if not self.members.history_enabled:
|
||||
raise ValueError("艾特上下文对话需要 history_enabled: true")
|
||||
ctx.llm # 启动时核对配置,不请求接口。
|
||||
|
||||
def on_message(self, message, ctx):
|
||||
if (message.type != 1 or not message.is_group or message.chat_id not in self.members.groups or
|
||||
"WXBOT_AT_CHAT_PROBE" in message.text or
|
||||
message.data.get("bot_generated") or not message.data.get("is_at_self") or
|
||||
self.members.account not in message.data.get("at_members", ())):
|
||||
return
|
||||
personality = ctx.personality(message)
|
||||
try:
|
||||
snapshot = self.members.conversation_snapshot(message)
|
||||
guard = lambda: ctx.response_guard(snapshot, personality)
|
||||
reply = personality_text(Dialogue(ctx.llm_for(message, personality=personality)).reply(snapshot),
|
||||
personality.name)
|
||||
display = self.members.display_name(message.sender_id, message.chat_id) or snapshot.speaker_name
|
||||
budget = 1023 - len(("@" + display + "\u2005\n").encode("utf-8"))
|
||||
for part in split_text(reply, byte_limit=budget):
|
||||
if not ctx.reply_at(message, part, display_name=display, delivery_guard=guard):
|
||||
raise RuntimeError("原生艾特发送未成功")
|
||||
ctx.logger.info("艾特对话完成:room=%s persona=%s context=%d", message.chat_id,
|
||||
personality.name, len(snapshot.messages))
|
||||
except SnapshotExpired:
|
||||
ctx.logger.info("艾特对话已取消:记录或人格状态已变更")
|
||||
except LLMError as error:
|
||||
ctx.logger.warning("艾特对话失败:%s", error)
|
||||
try:
|
||||
ctx.reply(message, "暂时无法回复,请稍后再艾特我。", delivery_guard=guard)
|
||||
except SnapshotExpired:
|
||||
pass
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"api": "v1",
|
||||
"description": "真实艾特机器人后,按群人格回复并携带发言者前十条上下文",
|
||||
"requires": ["group.text.receive", "group.text.send", "group.text.mention"]
|
||||
}
|
||||
Reference in New Issue
Block a user