Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
19 changes: 13 additions & 6 deletions astrbot/builtin_stars/astrbot/long_term_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def cfg(self, event: AstrMessageEvent):
image_caption = cfg["provider_ltm_settings"]["image_caption"] and bool(
image_caption_provider_id
)
context_prompt = cfg["provider_ltm_settings"].get(
"context_prompt",
"You are now in a chatroom. The chat history is as follows: \n",
)
active_reply_suffix_prompt = cfg["provider_ltm_settings"].get(
"active_reply_suffix_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.",
)
active_reply = cfg["provider_ltm_settings"]["active_reply"]
enable_active_reply = active_reply.get("enable", False)
ar_method = active_reply["method"]
Expand All @@ -45,6 +53,8 @@ def cfg(self, event: AstrMessageEvent):
ar_whitelist = active_reply.get("whitelist", [])
ret = {
"max_cnt": max_cnt,
"context_prompt": context_prompt,
"active_reply_suffix_prompt": active_reply_suffix_prompt,
"image_caption": image_caption,
"image_caption_prompt": image_caption_prompt,
"image_caption_provider_id": image_caption_provider_id,
Expand Down Expand Up @@ -159,16 +169,13 @@ async def on_req_llm(self, event: AstrMessageEvent, req: ProviderRequest) -> Non
if cfg["enable_active_reply"]:
prompt = req.prompt
req.prompt = (
f"You are now in a chatroom. The chat history is as follows:\n{chats_str}"
f"{cfg['context_prompt']}{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."
f"{cfg['active_reply_suffix_prompt']}"
)
req.contexts = [] # 清空上下文,当使用了主动回复,所有聊天记录都在一个prompt中。
else:
req.system_prompt += (
"You are now in a chatroom. The chat history is as follows: \n"
)
req.system_prompt += cfg["context_prompt"]
req.system_prompt += chats_str

async def after_req_llm(
Expand Down
12 changes: 12 additions & 0 deletions astrbot/core/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@
"provider_ltm_settings": {
"group_icl_enable": False,
"group_message_max_cnt": 300,
"context_prompt": "You are now in a chatroom. The chat history is as follows: \n",
"active_reply_suffix_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.",
"image_caption": False,
"image_caption_provider_id": "",
"active_reply": {
Expand Down Expand Up @@ -3868,6 +3870,10 @@ class ChatProviderTemplate(TypedDict):
"description": "最大消息数量",
"type": "int",
},
"provider_ltm_settings.context_prompt": {
"description": "上下文感知提示词",
"type": "text",
},
"provider_ltm_settings.image_caption": {
"description": "自动理解图片",
"type": "bool",
Expand Down Expand Up @@ -3911,6 +3917,12 @@ class ChatProviderTemplate(TypedDict):
"condition": {
"provider_ltm_settings.active_reply.enable": True,
},
"provider_ltm_settings.active_reply_suffix_prompt": {
"description": "主动回复后缀提示词",
"type": "text",
"condition": {
"provider_ltm_settings.active_reply.enable": True,
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,12 @@
"group_message_max_cnt": {
"description": "Maximum Message Count"
},
"context_prompt": {
"description": "Context Awareness Prompt"
},
"active_reply_suffix_prompt": {
"description": "Active Reply Suffix Prompt"
},
"image_caption": {
"description": "Auto-understand Images",
"hint": "Requires setting a group chat image caption model."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,12 @@
"group_message_max_cnt": {
"description": "最大消息数量"
},
"context_prompt": {
"description": "上下文感知提示词"
},
"active_reply_suffix_prompt": {
"description": "主动回复后缀提示词"
},
"image_caption": {
"description": "自动理解图片",
"hint": "需要设置群聊图片转述模型。"
Expand Down
Loading