diff --git a/astrbot/builtin_stars/astrbot/long_term_memory.py b/astrbot/builtin_stars/astrbot/long_term_memory.py index e08cdc5157..d71710b60b 100644 --- a/astrbot/builtin_stars/astrbot/long_term_memory.py +++ b/astrbot/builtin_stars/astrbot/long_term_memory.py @@ -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"] @@ -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, @@ -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( diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 846b1a350e..f9dff5bf38 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -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": { @@ -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", @@ -3912,6 +3918,13 @@ class ChatProviderTemplate(TypedDict): "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, + }, + }, }, }, }, diff --git a/dashboard/src/i18n/locales/en-US/features/config-metadata.json b/dashboard/src/i18n/locales/en-US/features/config-metadata.json index 9ae8672826..515d060bec 100644 --- a/dashboard/src/i18n/locales/en-US/features/config-metadata.json +++ b/dashboard/src/i18n/locales/en-US/features/config-metadata.json @@ -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." diff --git a/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json b/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json index c04138402e..e7c3807288 100644 --- a/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json +++ b/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json @@ -938,6 +938,12 @@ "group_message_max_cnt": { "description": "最大消息数量" }, + "context_prompt": { + "description": "上下文感知提示词" + }, + "active_reply_suffix_prompt": { + "description": "主动回复后缀提示词" + }, "image_caption": { "description": "自动理解图片", "hint": "需要设置群聊图片转述模型。"