🤖 自动格式化代码 [skip ci]

This commit is contained in:
github-actions[bot]
2025-06-21 10:01:17 +00:00
parent 3146bcbcf1
commit 611e47c14d
7 changed files with 26 additions and 39 deletions

View File

@@ -566,15 +566,11 @@ class HeartFChatting:
# 创建三个并行任务为LLM调用添加超时保护
action_modify_task = asyncio.create_task(
asyncio.wait_for(
modify_actions_task(),
timeout=ACTION_MODIFICATION_TIMEOUT
)
asyncio.wait_for(modify_actions_task(), timeout=ACTION_MODIFICATION_TIMEOUT)
)
memory_task = asyncio.create_task(
asyncio.wait_for(
self.memory_activator.activate_memory(self.observations),
timeout=MEMORY_ACTIVATION_TIMEOUT
self.memory_activator.activate_memory(self.observations), timeout=MEMORY_ACTIVATION_TIMEOUT
)
)
processor_task = asyncio.create_task(self._process_processors(self.observations))
@@ -584,27 +580,26 @@ class HeartFChatting:
running_memorys = []
all_plan_info = []
processor_time_costs = {}
try:
action_modify_result, running_memorys, (all_plan_info, processor_time_costs) = await asyncio.gather(
action_modify_task, memory_task, processor_task,
return_exceptions=True
action_modify_task, memory_task, processor_task, return_exceptions=True
)
# 检查各个任务的结果
if isinstance(action_modify_result, Exception):
if isinstance(action_modify_result, asyncio.TimeoutError):
logger.error(f"{self.log_prefix} 动作修改任务超时")
else:
logger.error(f"{self.log_prefix} 动作修改任务失败: {action_modify_result}")
if isinstance(running_memorys, Exception):
if isinstance(running_memorys, asyncio.TimeoutError):
logger.error(f"{self.log_prefix} 记忆激活任务超时")
else:
logger.error(f"{self.log_prefix} 记忆激活任务失败: {running_memorys}")
running_memorys = []
processor_result = (all_plan_info, processor_time_costs)
if isinstance(processor_result, Exception):
if isinstance(processor_result, asyncio.TimeoutError):
@@ -615,7 +610,7 @@ class HeartFChatting:
processor_time_costs = {}
else:
all_plan_info, processor_time_costs = processor_result
except Exception as e:
logger.error(f"{self.log_prefix} 并行任务gather失败: {e}")
# 设置默认值以继续执行
@@ -628,7 +623,9 @@ class HeartFChatting:
"processor_time_costs": processor_time_costs,
}
logger.debug(f"{self.log_prefix} 并行阶段完成准备进入规划器plan_info数量: {len(all_plan_info)}, running_memorys数量: {len(running_memorys)}")
logger.debug(
f"{self.log_prefix} 并行阶段完成准备进入规划器plan_info数量: {len(all_plan_info)}, running_memorys数量: {len(running_memorys)}"
)
with Timer("规划器", cycle_timers):
plan_result = await self.action_planner.plan(all_plan_info, running_memorys, loop_start_time)

View File

@@ -163,7 +163,6 @@ class ExpressionSelectorProcessor(BaseProcessor):
cache_size = len(selected_expressions) if selected_expressions else 0
mode_desc = f"LLM模式已缓存{cache_size}个)"
if selected_expressions:
# 缓存选择的表达方式
self.cached_expressions = selected_expressions

View File

@@ -706,7 +706,7 @@ class PersonImpressionpProcessor(BaseProcessor):
if self.info_fetched_cache:
persons_with_known_info = [] # 有已知信息的人员
persons_with_unknown_info = [] # 有未知信息的人员
for person_id in self.info_fetched_cache:
person_known_infos = []
person_unknown_infos = []
@@ -739,9 +739,11 @@ class PersonImpressionpProcessor(BaseProcessor):
for person_name, unknown_types in persons_with_unknown_info:
unknown_types_str = "".join(unknown_types)
unknown_persons_details.append(f"{person_name}的[{unknown_types_str}]")
if len(unknown_persons_details) == 1:
persons_infos_str += f"你不了解{unknown_persons_details[0]}信息,不要胡乱回答,可以直接说不知道或忘记了;\n"
persons_infos_str += (
f"你不了解{unknown_persons_details[0]}信息,不要胡乱回答,可以直接说不知道或忘记了;\n"
)
else:
unknown_all_str = "".join(unknown_persons_details)
persons_infos_str += f"你不了解{unknown_all_str}等信息,不要胡乱回答,可以直接说不知道或忘记了;\n"

View File

@@ -30,7 +30,6 @@ from src.chat.utils.chat_message_builder import (
get_raw_msg_before_timestamp_with_chat,
num_new_messages_since,
)
from src.person_info.relationship_manager import get_relationship_manager
willing_manager = get_willing_manager()
@@ -779,17 +778,11 @@ class NormalChat:
logger.debug(f"[{self.stream_name}] 额外动作处理完成: {self.action_type}")
if not response_set or (
self.enable_planner
and self.action_type not in ["no_action"]
and not self.is_parallel_action
self.enable_planner and self.action_type not in ["no_action"] and not self.is_parallel_action
):
if not response_set:
logger.info(f"[{self.stream_name}] 模型未生成回复内容")
elif (
self.enable_planner
and self.action_type not in ["no_action"]
and not self.is_parallel_action
):
elif self.enable_planner and self.action_type not in ["no_action"] and not self.is_parallel_action:
logger.info(f"[{self.stream_name}] 模型选择其他动作(非并行动作)")
# 如果模型未生成回复,移除思考消息
container = await message_manager.get_container(self.stream_id) # 使用 self.stream_id
@@ -836,8 +829,6 @@ class NormalChat:
if len(self.recent_replies) > self.max_replies_history:
self.recent_replies = self.recent_replies[-self.max_replies_history :]
# 回复后处理
await willing_manager.after_generate_reply_handle(message.message_info.message_id)

View File

@@ -5,8 +5,6 @@ from src.chat.utils.chat_message_builder import build_readable_messages, get_raw
from src.config.config import global_config
import random
import time
from src.chat.message_receive.message_sender import message_manager
from src.chat.message_receive.message import MessageThinking
logger = get_logger("normal_chat_action_modifier")
@@ -280,8 +278,6 @@ class NormalChatActionModifier:
logger.debug(f"{self.log_prefix}动作 {action_name} 未匹配到任何关键词: {activation_keywords}")
return False
def get_available_actions_count(self) -> int:
"""获取当前可用动作数量排除默认的no_action"""
current_actions = self.action_manager.get_using_actions_for_mode("normal")

View File

@@ -193,8 +193,6 @@ class ExpressionConfig(ConfigBase):
enable_expression_learning: bool = True
"""是否启用表达学习"""
expression_groups: list[list[str]] = field(default_factory=list)
"""
表达学习互通组

View File

@@ -492,9 +492,11 @@ class RelationshipManager:
}}
"""
try:
relation_value_response, _ = await self.relationship_llm.generate_response_async(prompt=relation_value_prompt)
relation_value_response, _ = await self.relationship_llm.generate_response_async(
prompt=relation_value_prompt
)
relation_value_json = json.loads(repair_json(relation_value_response))
# 从LLM获取新生成的值
new_familiarity_value = int(relation_value_json.get("familiarity_value", 0))
new_liking_value = int(relation_value_json.get("liking_value", 50))
@@ -502,14 +504,16 @@ class RelationshipManager:
# 获取数据库中的旧值,如果不存在则使用默认值
old_familiarity_value = await person_info_manager.get_value(person_id, "familiarity_value") or 0
old_liking_value = await person_info_manager.get_value(person_id, "liking_value") or 50
# 计算平均值
final_familiarity_value = (old_familiarity_value + new_familiarity_value) // 2
final_liking_value = (old_liking_value + new_liking_value) // 2
await person_info_manager.update_one_field(person_id, "familiarity_value", final_familiarity_value)
await person_info_manager.update_one_field(person_id, "liking_value", final_liking_value)
logger.info(f"更新了与 {person_name} 的关系值: 熟悉度={final_familiarity_value}, 好感度={final_liking_value}")
logger.info(
f"更新了与 {person_name} 的关系值: 熟悉度={final_familiarity_value}, 好感度={final_liking_value}"
)
except (json.JSONDecodeError, ValueError, TypeError) as e:
logger.error(f"解析relation_value JSON失败或值无效: {e}, 响应: {relation_value_response}")