From 445b90560a484b07d006057a3af0e12f28a34cd2 Mon Sep 17 00:00:00 2001 From: tt-P607 <68868379+tt-P607@users.noreply.github.com> Date: Tue, 4 Nov 2025 08:20:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(replyer):=20=E7=A7=BB=E9=99=A4=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E8=AE=B0=E5=BD=95=E7=9A=84=E7=A1=AC=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E4=B8=8A=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复了在构建聊天记录上下文时,已读历史消息被硬编码截断为50条的问题。 现在,`build_s4u_chat_history_prompts` 及其回退方法将完全遵循 `max_context_size` 配置,确保模型能获取到完整的上下文信息。 --- src/chat/replyer/default_generator.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/chat/replyer/default_generator.py b/src/chat/replyer/default_generator.py index e4cb04c7a..3582cd157 100644 --- a/src/chat/replyer/default_generator.py +++ b/src/chat/replyer/default_generator.py @@ -982,7 +982,7 @@ class DefaultReplyer: # 按时间排序并限制数量 sorted_messages = sorted(read_messages_dicts, key=lambda x: x.get("time", 0)) - final_history = sorted_messages[-50:] # 限制最多50条 + final_history = sorted_messages[-global_config.chat.max_context_size:] # 使用配置的上下文长度 read_content = await build_readable_messages( final_history, @@ -1087,7 +1087,7 @@ class DefaultReplyer: read_history_prompt = "" if read_messages: read_content = await build_readable_messages( - read_messages[-50:], + read_messages[-global_config.chat.max_context_size:], replace_bot_name=True, timestamp_mode="normal_no_YMD", truncate=True, @@ -1293,7 +1293,7 @@ class DefaultReplyer: # 转换为字典格式 message_list_before_now_long = [msg.flatten() for msg in all_messages[-(global_config.chat.max_context_size * 2):]] - message_list_before_short = [msg.flatten() for msg in all_messages[-int(global_config.chat.max_context_size * 0.33):]] + message_list_before_short = [msg.flatten() for msg in all_messages[-int(global_config.chat.max_context_size):]] logger.debug(f"使用内存中的消息: long={len(message_list_before_now_long)}, short={len(message_list_before_short)}") else: @@ -1307,7 +1307,7 @@ class DefaultReplyer: message_list_before_short = await get_raw_msg_before_timestamp_with_chat( chat_id=chat_id, timestamp=time.time(), - limit=int(global_config.chat.max_context_size * 0.33), + limit=int(global_config.chat.max_context_size), ) chat_talking_prompt_short = await build_readable_messages( @@ -1655,7 +1655,7 @@ class DefaultReplyer: ) # 转换为字典格式,限制数量 - limit = min(int(global_config.chat.max_context_size * 0.33), 15) + limit = int(global_config.chat.max_context_size) message_list_before_now_half = [msg.flatten() for msg in all_messages[-limit:]] logger.debug(f"Rewrite使用内存中的 {len(message_list_before_now_half)} 条消息") @@ -1665,7 +1665,7 @@ class DefaultReplyer: message_list_before_now_half = await get_raw_msg_before_timestamp_with_chat( chat_id=chat_id, timestamp=time.time(), - limit=min(int(global_config.chat.max_context_size * 0.33), 15), + limit=int(global_config.chat.max_context_size), ) chat_talking_prompt_half = await build_readable_messages( @@ -2103,7 +2103,7 @@ class DefaultReplyer: ) # 转换为字典格式,限制数量 - limit = int(global_config.chat.max_context_size * 0.33) + limit = int(global_config.chat.max_context_size) message_list_before_short = [msg.flatten() for msg in all_messages[-limit:]] logger.debug(f"记忆存储使用内存中的 {len(message_list_before_short)} 条消息") @@ -2113,7 +2113,7 @@ class DefaultReplyer: message_list_before_short = await get_raw_msg_before_timestamp_with_chat( chat_id=stream.stream_id, timestamp=time.time(), - limit=int(global_config.chat.max_context_size * 0.33), + limit=int(global_config.chat.max_context_size), ) chat_history = await build_readable_messages( message_list_before_short,