better:优化表达方式选择

This commit is contained in:
SengokuCola
2025-11-16 11:35:36 +08:00
parent bdb69dba83
commit 68916d1fcb
4 changed files with 32 additions and 14 deletions

View File

@@ -227,13 +227,14 @@ class DefaultReplyer:
traceback.print_exc()
return False, llm_response
async def build_expression_habits(self, chat_history: str, target: str) -> Tuple[str, List[int]]:
async def build_expression_habits(self, chat_history: str, target: str, reply_reason: str = "") -> Tuple[str, List[int]]:
# sourcery skip: for-append-to-extend
"""构建表达习惯块
Args:
chat_history: 聊天历史记录
target: 目标消息内容
reply_reason: planner给出的回复理由
Returns:
str: 表达习惯信息字符串
@@ -246,7 +247,7 @@ class DefaultReplyer:
# 使用从处理器传来的选中表达方式
# 使用模型预测选择表达方式
selected_expressions, selected_ids = await expression_selector.select_suitable_expressions(
self.chat_stream.stream_id, chat_history, max_num=8, target_message=target
self.chat_stream.stream_id, chat_history, max_num=8, target_message=target, reply_reason=reply_reason
)
if selected_expressions:
@@ -787,7 +788,7 @@ class DefaultReplyer:
# 并行执行七个构建任务
task_results = await asyncio.gather(
self._time_and_run_task(
self.build_expression_habits(chat_talking_prompt_short, target), "expression_habits"
self.build_expression_habits(chat_talking_prompt_short, target, reply_reason), "expression_habits"
),
self._time_and_run_task(
self.build_tool_info(chat_talking_prompt_short, sender, target, enable_tool=enable_tool), "tool_info"

View File

@@ -241,13 +241,14 @@ class PrivateReplyer:
return f"{sender_relation}"
async def build_expression_habits(self, chat_history: str, target: str) -> Tuple[str, List[int]]:
async def build_expression_habits(self, chat_history: str, target: str, reply_reason: str = "") -> Tuple[str, List[int]]:
# sourcery skip: for-append-to-extend
"""构建表达习惯块
Args:
chat_history: 聊天历史记录
target: 目标消息内容
reply_reason: planner给出的回复理由
Returns:
str: 表达习惯信息字符串
@@ -260,7 +261,7 @@ class PrivateReplyer:
# 使用从处理器传来的选中表达方式
# 使用模型预测选择表达方式
selected_expressions, selected_ids = await expression_selector.select_suitable_expressions(
self.chat_stream.stream_id, chat_history, max_num=8, target_message=target
self.chat_stream.stream_id, chat_history, max_num=8, target_message=target, reply_reason=reply_reason
)
if selected_expressions:
@@ -706,7 +707,7 @@ class PrivateReplyer:
# 并行执行八个构建任务
task_results = await asyncio.gather(
self._time_and_run_task(
self.build_expression_habits(chat_talking_prompt_short, target), "expression_habits"
self.build_expression_habits(chat_talking_prompt_short, target, reply_reason), "expression_habits"
),
self._time_and_run_task(self.build_relation_info(chat_talking_prompt_short, sender), "relation_info"),
self._time_and_run_task(

View File

@@ -89,9 +89,6 @@ class ChatHistorySummarizer:
current_time = time.time()
try:
logger.info(
f"{self.log_prefix} 开始处理聊天概括,时间窗口: {self.last_check_time:.2f} -> {current_time:.2f}"
)
# 获取从上次检查时间到当前时间的新消息
new_messages = message_api.get_messages_by_time_in_chat(
chat_id=self.chat_id,
@@ -109,6 +106,10 @@ class ChatHistorySummarizer:
await self._check_and_package(current_time)
self.last_check_time = current_time
return
logger.info(
f"{self.log_prefix} 开始处理聊天概括,时间窗口: {self.last_check_time:.2f} -> {current_time:.2f}"
)
# 有新消息,更新最后检查时间
self.last_check_time = current_time