Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions astrbot/builtin_stars/astrbot/long_term_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,16 @@ async def on_req_llm(self, event: AstrMessageEvent, req: ProviderRequest) -> Non
chats_str = "\n---\n".join(self.session_chats[event.unified_msg_origin])

cfg = self.cfg(event)
if cfg["enable_active_reply"]:
is_active_reply = getattr(req, "_ltm_active_reply_trigger", False)
if cfg["enable_active_reply"] and is_active_reply:
prompt = req.prompt
req.prompt = (
f"You are now in a chatroom. The chat history is as follows:\n{chats_str}"
f"\nNow, a new message is coming: `{prompt}`. "
"Please react to it. Only output your response and do not output any other information. "
"You MUST use the SAME language as the chatroom is using."
)
req.contexts = [] # 清空上下文,当使用了主动回复,所有聊天记录都在一个prompt中。
req.contexts = [] # Only clear contexts for proactive replies; chat history is embedded in the prompt.
else:
req.system_prompt += (
"You are now in a chatroom. The chat history is as follows: \n"
Expand Down
6 changes: 4 additions & 2 deletions astrbot/builtin_stars/astrbot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ async def on_message(self, event: AstrMessageEvent):
logger.error("未找到对话,无法主动回复")
return

yield event.request_llm(
req = event.request_llm(
prompt=prompt,
session_id=event.session_id,
conversation=conv,
conversation=None, # Proactive replies should not overwrite conversation history with chatroom context.
)
setattr(req, "_ltm_active_reply_trigger", True)
yield req
except BaseException as e:
logger.error(traceback.format_exc())
logger.error(f"主动回复失败: {e}")
Expand Down