pull/937/head
Bakadax 2025-05-16 23:35:32 +08:00
parent 5e9177e775
commit 0e4ddc5d67
8 changed files with 27 additions and 32 deletions

View File

@ -142,7 +142,7 @@ class ActionHandler(ABC):
) )
# 限制历史记录长度 # 限制历史记录长度
max_history_len = getattr(global_config, "pfc_max_chat_history_for_checker", 50) max_history_len = global_config.pfc.pfc_max_chat_history_for_checker
if len(observation_info.chat_history) > max_history_len: if len(observation_info.chat_history) > max_history_len:
observation_info.chat_history = observation_info.chat_history[-max_history_len:] observation_info.chat_history = observation_info.chat_history[-max_history_len:]
observation_info.chat_history_count = len(observation_info.chat_history) observation_info.chat_history_count = len(observation_info.chat_history)
@ -616,7 +616,7 @@ class DirectReplyHandler(BaseTextReplyHandler):
action_successful = False # 整体动作是否成功 action_successful = False # 整体动作是否成功
final_status = "recall" # 默认最终状态 final_status = "recall" # 默认最终状态
final_reason = "直接回复动作未成功执行" # 默认最终原因 final_reason = "直接回复动作未成功执行" # 默认最终原因
max_reply_attempts: int = getattr(global_config, "pfc_max_reply_attempts", 3) max_reply_attempts: int = global_config.pfc.pfc_max_reply_attempts
( (
sent_text_successfully, sent_text_successfully,
@ -697,7 +697,7 @@ class SendNewMessageHandler(BaseTextReplyHandler):
action_successful = False # 整体动作是否成功 action_successful = False # 整体动作是否成功
final_status = "recall" # 默认最终状态 final_status = "recall" # 默认最终状态
final_reason = "发送新消息动作未成功执行" # 默认最终原因 final_reason = "发送新消息动作未成功执行" # 默认最终原因
max_reply_attempts: int = getattr(global_config, "pfc_max_reply_attempts", 3) max_reply_attempts: int = global_config.pfc.pfc_max_reply_attempts
( (
sent_text_successfully, sent_text_successfully,

View File

@ -159,14 +159,10 @@ class ActionPlanner:
self.private_name = private_name self.private_name = private_name
# 初始化 LLM 请求对象 # 初始化 LLM 请求对象
try: try:
llm_config = global_config.model.pfc_action_planner
if not isinstance(llm_config, dict):
raise TypeError(f"LLM config 'pfc_action_planner' is not a dictionary: {llm_config}")
self.llm = LLMRequest( self.llm = LLMRequest(
model=llm_config, model=global_config.model.pfc_action_planner,
temperature=llm_config.get("temp", 0.7), temperature=global_config.model.pfc_action_planner["temp"],
max_tokens=1500, max_tokens=global_config.model.pfc_action_planner["max_tokens"],
request_type="action_planning", request_type="action_planning",
) )
except TypeError as e: except TypeError as e:

View File

@ -45,10 +45,9 @@ async def run_conversation_loop(conversation_instance: "Conversation"):
try: try:
global TIME_ZONE global TIME_ZONE
if TIME_ZONE is None: if TIME_ZONE is None:
configured_tz_loop = getattr(global_config, "TIME_ZONE", "Asia/Shanghai") TIME_ZONE = global_config.schedule.time_zone
TIME_ZONE = tz.gettz(configured_tz_loop)
if TIME_ZONE is None: if TIME_ZONE is None:
logger.error(f"循环中: 配置的时区 '{configured_tz_loop}' 无效,将使用 'Asia/Shanghai'") logger.error(f"循环中: 配置的时区 '{global_config.schedule.time_zone}' 无效,将使用 'Asia/Shanghai'")
TIME_ZONE = tz.gettz("Asia/Shanghai") TIME_ZONE = tz.gettz("Asia/Shanghai")
current_time_dt = datetime.datetime.now(TIME_ZONE) current_time_dt = datetime.datetime.now(TIME_ZONE)

View File

@ -22,7 +22,7 @@ class PfcEmotionUpdater:
self.mood_mng = mood_manager self.mood_mng = mood_manager
# LLM 实例 (根据 global_config.model.summary 配置) # LLM 实例 (根据 global_config.model.summary 配置)
llm_config_summary = getattr(global_config, "llm_summary", None) llm_config_summary = global_config.model.summary
if llm_config_summary and isinstance(llm_config_summary, dict): if llm_config_summary and isinstance(llm_config_summary, dict):
logger.debug(f"[私聊][{self.private_name}] 使用 llm_summary 配置初始化情绪判断LLM。") logger.debug(f"[私聊][{self.private_name}] 使用 llm_summary 配置初始化情绪判断LLM。")
self.llm = LLMRequest( self.llm = LLMRequest(
@ -37,8 +37,8 @@ class PfcEmotionUpdater:
logger.error(f"[私聊][{self.private_name}] 未找到 llm_summary 配置或配置无效!情绪判断功能将受限。") logger.error(f"[私聊][{self.private_name}] 未找到 llm_summary 配置或配置无效!情绪判断功能将受限。")
self.llm = None # LLM 未初始化 self.llm = None # LLM 未初始化
self.EMOTION_UPDATE_INTENSITY = getattr(global_config, "pfc_emotion_update_intensity", 0.6) self.EMOTION_UPDATE_INTENSITY = global_config.pfc.pfc_emotion_update_intensity
self.EMOTION_HISTORY_COUNT = getattr(global_config, "pfc_emotion_history_count", 5) self.EMOTION_HISTORY_COUNT = global_config.pfc.pfc_emotion_history_count
async def update_emotion_based_on_context( async def update_emotion_based_on_context(
self, self,

View File

@ -30,20 +30,20 @@ class PfcRelationshipUpdater:
# LLM 实例 (为关系评估创建一个新的) # LLM 实例 (为关系评估创建一个新的)
# 尝试读取 llm_PFC_relationship_eval 配置,如果不存在则回退 # 尝试读取 llm_PFC_relationship_eval 配置,如果不存在则回退
llm_config_rel_eval = getattr(global_config, "llm_PFC_relationship_eval", None) llm_config_rel_eval = global_config.model.PFC_relationship_eval
if llm_config_rel_eval and isinstance(llm_config_rel_eval, dict): if llm_config_rel_eval and isinstance(llm_config_rel_eval, dict):
logger.info(f"[私聊][{self.private_name}] 使用 llm_PFC_relationship_eval 配置初始化关系评估LLM。") logger.info(f"[私聊][{self.private_name}] 使用 llm_PFC_relationship_eval 配置初始化关系评估LLM。")
self.llm = LLMRequest( self.llm = LLMRequest(
model=llm_config_rel_eval, model=global_config.model.PFC_relationship_eval,
temperature=llm_config_rel_eval.get("temp", 0.5), # 判断任务通常用较低温度 temperature=global_config.model.PFC_relationship_eval["temp"],
max_tokens=llm_config_rel_eval.get("max_tokens", 512), max_tokens=global_config.model.PFC_relationship_eval["max_tokens"],
request_type="pfc_relationship_evaluation", request_type="pfc_relationship_evaluation",
) )
else: else:
logger.warning( logger.warning(
f"[私聊][{self.private_name}] 未找到 llm_PFC_relationship_eval 配置或配置无效,将回退使用 llm_PFC_action_planner 的配置。" f"[私聊][{self.private_name}] 未找到 llm_PFC_relationship_eval 配置或配置无效,将回退使用 llm_PFC_action_planner 的配置。"
) )
llm_config_action_planner = getattr(global_config, "llm_PFC_action_planner", None) llm_config_action_planner = global_config.model.pfc_action_planner
if llm_config_action_planner and isinstance(llm_config_action_planner, dict): if llm_config_action_planner and isinstance(llm_config_action_planner, dict):
self.llm = LLMRequest( self.llm = LLMRequest(
model=llm_config_action_planner, # 使用 action_planner 的模型配置 model=llm_config_action_planner, # 使用 action_planner 的模型配置
@ -56,14 +56,14 @@ class PfcRelationshipUpdater:
self.llm = None # LLM 未初始化 self.llm = None # LLM 未初始化
# 从 global_config 读取参数,若无则使用默认值 # 从 global_config 读取参数,若无则使用默认值
self.REL_INCREMENTAL_INTERVAL = getattr(global_config, "pfc_relationship_incremental_interval", 10) self.REL_INCREMENTAL_INTERVAL = global_config.pfc.pfc_relationship_incremental_interval
self.REL_INCREMENTAL_MSG_COUNT = getattr(global_config, "pfc_relationship_incremental_msg_count", 10) self.REL_INCREMENTAL_MSG_COUNT = global_config.pfc.pfc_relationship_incremental_msg_count
self.REL_INCREMENTAL_DEFAULT_CHANGE = getattr(global_config, "pfc_relationship_incremental_default_change", 1.0) self.REL_INCREMENTAL_DEFAULT_CHANGE = global_config.pfc.pfc_relationship_incremental_default_change
self.REL_INCREMENTAL_MAX_CHANGE = getattr(global_config, "pfc_relationship_incremental_max_change", 5.0) self.REL_INCREMENTAL_MAX_CHANGE = global_config.pfc.pfc_relationship_incremental_max_change
self.REL_FINAL_MSG_COUNT = getattr(global_config, "pfc_relationship_final_msg_count", 30) self.REL_FINAL_MSG_COUNT = global_config.pfc.pfc_relationship_final_msg_count
self.REL_FINAL_DEFAULT_CHANGE = getattr(global_config, "pfc_relationship_final_default_change", 5.0) self.REL_FINAL_DEFAULT_CHANGE = global_config.pfc.pfc_relationship_final_default_change
self.REL_FINAL_MAX_CHANGE = getattr(global_config, "pfc_relationship_final_max_change", 50.0) self.REL_FINAL_MAX_CHANGE = global_config.pfc.pfc_relationship_final_max_change
async def update_relationship_incremental( async def update_relationship_incremental(
self, self,

View File

@ -53,7 +53,7 @@ async def find_most_relevant_historical_message(
log_source_of_limit = "传入的绝对时间上限" log_source_of_limit = "传入的绝对时间上限"
else: else:
# 如果没有传入绝对时间上限,可以设置一个默认的回退逻辑 # 如果没有传入绝对时间上限,可以设置一个默认的回退逻辑
fallback_exclude_seconds = getattr(global_config, "pfc_historical_fallback_exclude_seconds", 7200) # 默认2小时 fallback_exclude_seconds = global_config.pfc.pfc_historical_fallback_exclude_seconds
effective_search_upper_limit = time.time() - fallback_exclude_seconds effective_search_upper_limit = time.time() - fallback_exclude_seconds
log_source_of_limit = f"回退逻辑 (排除最近 {fallback_exclude_seconds} 秒)" log_source_of_limit = f"回退逻辑 (排除最近 {fallback_exclude_seconds} 秒)"

View File

@ -240,7 +240,7 @@ class ReplyGenerator:
# 我们先做一个合理的假设: “最近聊天记录” 字符串 chat_history_text 是基于 # 我们先做一个合理的假设: “最近聊天记录” 字符串 chat_history_text 是基于
# observation_info.chat_history 的一个有限的尾部片段生成的。 # observation_info.chat_history 的一个有限的尾部片段生成的。
# 假设这个片段的长度由 global_config.pfc.pfc_recent_history_display_count 控制默认为20条。 # 假设这个片段的长度由 global_config.pfc.pfc_recent_history_display_count 控制默认为20条。
recent_history_display_count = getattr(global_config, "pfc_recent_history_display_count", 20) recent_history_display_count = global_config.pfc.pfc_recent_history_display_count
if observation_info and observation_info.chat_history and len(observation_info.chat_history) > 0: if observation_info and observation_info.chat_history and len(observation_info.chat_history) > 0:
# 获取用于生成“最近聊天记录”的实际消息片段 # 获取用于生成“最近聊天记录”的实际消息片段

View File

@ -25,7 +25,7 @@ def select_nicknames_for_prompt(all_nicknames_info: Dict[str, List[Dict[str, int
return [] return []
candidates = [] # 存储 (用户名, 绰号, 次数, 权重) candidates = [] # 存储 (用户名, 绰号, 次数, 权重)
smoothing_factor = getattr(global_config, "nickname_probability_smoothing", 1.0) # 平滑因子避免权重为0 smoothing_factor = global_config.group_nickname.nickname_probability_smoothing
for user_name, nicknames in all_nicknames_info.items(): for user_name, nicknames in all_nicknames_info.items():
if nicknames and isinstance(nicknames, list): if nicknames and isinstance(nicknames, list):
@ -48,7 +48,7 @@ def select_nicknames_for_prompt(all_nicknames_info: Dict[str, List[Dict[str, int
return [] return []
# 确定需要选择的数量 # 确定需要选择的数量
max_nicknames = getattr(global_config, "max_nicknames_in_prompt", 5) max_nicknames = global_config.group_nickname.max_nicknames_in_prompt
num_to_select = min(max_nicknames, len(candidates)) num_to_select = min(max_nicknames, len(candidates))
try: try: