🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -19,7 +19,6 @@ async def forced_change_subheartflow_status(subheartflow_id: str, status: ChatSt
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def get_all_states():
|
async def get_all_states():
|
||||||
"""获取所有状态"""
|
"""获取所有状态"""
|
||||||
all_states = await heartflow.api_get_all_states()
|
all_states = await heartflow.api_get_all_states()
|
||||||
|
|||||||
@@ -76,7 +76,6 @@ class FocusLoopInfo:
|
|||||||
else:
|
else:
|
||||||
cycle_info_block = "\n"
|
cycle_info_block = "\n"
|
||||||
|
|
||||||
|
|
||||||
# 获取history_loop中最新添加的
|
# 获取history_loop中最新添加的
|
||||||
if self.history_loop:
|
if self.history_loop:
|
||||||
last_loop = self.history_loop[0]
|
last_loop = self.history_loop[0]
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ install(extra_lines=3)
|
|||||||
|
|
||||||
logger = get_logger("hfc") # Logger Name Changed
|
logger = get_logger("hfc") # Logger Name Changed
|
||||||
|
|
||||||
|
|
||||||
class HeartFChatting:
|
class HeartFChatting:
|
||||||
"""
|
"""
|
||||||
管理一个连续的Focus Chat循环
|
管理一个连续的Focus Chat循环
|
||||||
@@ -63,10 +64,7 @@ class HeartFChatting:
|
|||||||
self.loop_info: FocusLoopInfo = FocusLoopInfo(observe_id=self.stream_id)
|
self.loop_info: FocusLoopInfo = FocusLoopInfo(observe_id=self.stream_id)
|
||||||
|
|
||||||
self.action_manager = ActionManager()
|
self.action_manager = ActionManager()
|
||||||
self.action_planner = ActionPlanner(
|
self.action_planner = ActionPlanner(chat_id=self.stream_id, action_manager=self.action_manager)
|
||||||
chat_id = self.stream_id,
|
|
||||||
action_manager=self.action_manager
|
|
||||||
)
|
|
||||||
self.action_modifier = ActionModifier(action_manager=self.action_manager, chat_id=self.stream_id)
|
self.action_modifier = ActionModifier(action_manager=self.action_manager, chat_id=self.stream_id)
|
||||||
|
|
||||||
self._processing_lock = asyncio.Lock()
|
self._processing_lock = asyncio.Lock()
|
||||||
@@ -238,7 +236,6 @@ class HeartFChatting:
|
|||||||
|
|
||||||
self._current_cycle_detail.set_loop_info(loop_info)
|
self._current_cycle_detail.set_loop_info(loop_info)
|
||||||
|
|
||||||
|
|
||||||
self.loop_info.add_loop_info(self._current_cycle_detail)
|
self.loop_info.add_loop_info(self._current_cycle_detail)
|
||||||
|
|
||||||
self._current_cycle_detail.timers = cycle_timers
|
self._current_cycle_detail.timers = cycle_timers
|
||||||
@@ -253,7 +250,6 @@ class HeartFChatting:
|
|||||||
formatted_time = f"{elapsed * 1000:.2f}毫秒" if elapsed < 1 else f"{elapsed:.2f}秒"
|
formatted_time = f"{elapsed * 1000:.2f}毫秒" if elapsed < 1 else f"{elapsed:.2f}秒"
|
||||||
timer_strings.append(f"{name}: {formatted_time}")
|
timer_strings.append(f"{name}: {formatted_time}")
|
||||||
|
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"{self.log_prefix} 第{self._current_cycle_detail.cycle_id}次思考,"
|
f"{self.log_prefix} 第{self._current_cycle_detail.cycle_id}次思考,"
|
||||||
f"耗时: {self._current_cycle_detail.end_time - self._current_cycle_detail.start_time:.1f}秒, "
|
f"耗时: {self._current_cycle_detail.end_time - self._current_cycle_detail.start_time:.1f}秒, "
|
||||||
@@ -352,7 +348,7 @@ class HeartFChatting:
|
|||||||
try:
|
try:
|
||||||
# 调用完整的动作修改流程
|
# 调用完整的动作修改流程
|
||||||
await self.action_modifier.modify_actions(
|
await self.action_modifier.modify_actions(
|
||||||
loop_info = self.loop_info,
|
loop_info=self.loop_info,
|
||||||
mode="focus",
|
mode="focus",
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ class CycleDetail:
|
|||||||
self.loop_action_info = loop_info["loop_action_info"]
|
self.loop_action_info = loop_info["loop_action_info"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def create_empty_anchor_message(
|
async def create_empty_anchor_message(
|
||||||
platform: str, group_info: dict, chat_stream: ChatStream
|
platform: str, group_info: dict, chat_stream: ChatStream
|
||||||
) -> Optional[MessageRecv]:
|
) -> Optional[MessageRecv]:
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class ChatState(enum.Enum):
|
|||||||
NORMAL = "随便水群"
|
NORMAL = "随便水群"
|
||||||
FOCUSED = "认真水群"
|
FOCUSED = "认真水群"
|
||||||
|
|
||||||
|
|
||||||
class ChatStateInfo:
|
class ChatStateInfo:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.chat_status: ChatState = ChatState.NORMAL
|
self.chat_status: ChatState = ChatState.NORMAL
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from src.common.logger import get_logger
|
|||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from src.chat.message_receive.chat_stream import get_chat_manager
|
from src.chat.message_receive.chat_stream import get_chat_manager
|
||||||
|
|
||||||
logger = get_logger("heartflow")
|
logger = get_logger("heartflow")
|
||||||
|
|
||||||
|
|
||||||
@@ -36,7 +37,6 @@ class Heartflow:
|
|||||||
logger.error(f"创建子心流 {subheartflow_id} 失败: {e}", exc_info=True)
|
logger.error(f"创建子心流 {subheartflow_id} 失败: {e}", exc_info=True)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
async def force_change_subheartflow_status(self, subheartflow_id: str, status: ChatState) -> None:
|
async def force_change_subheartflow_status(self, subheartflow_id: str, status: ChatState) -> None:
|
||||||
"""强制改变子心流的状态"""
|
"""强制改变子心流的状态"""
|
||||||
# 这里的 message 是可选的,可能是一个消息对象,也可能是其他类型的数据
|
# 这里的 message 是可选的,可能是一个消息对象,也可能是其他类型的数据
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ from src.person_info.relationship_manager import get_relationship_manager
|
|||||||
|
|
||||||
logger = get_logger("chat")
|
logger = get_logger("chat")
|
||||||
|
|
||||||
|
|
||||||
async def _process_relationship(message: MessageRecv) -> None:
|
async def _process_relationship(message: MessageRecv) -> None:
|
||||||
"""处理用户关系逻辑
|
"""处理用户关系逻辑
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class ActionModifier:
|
|||||||
|
|
||||||
async def modify_actions(
|
async def modify_actions(
|
||||||
self,
|
self,
|
||||||
loop_info = None,
|
loop_info=None,
|
||||||
mode: str = "focus",
|
mode: str = "focus",
|
||||||
message_content: str = "",
|
message_content: str = "",
|
||||||
):
|
):
|
||||||
@@ -99,7 +99,6 @@ class ActionModifier:
|
|||||||
self.action_manager.remove_action_from_using(action_name)
|
self.action_manager.remove_action_from_using(action_name)
|
||||||
logger.debug(f"{self.log_prefix}阶段一移除动作: {action_name},原因: {reason}")
|
logger.debug(f"{self.log_prefix}阶段一移除动作: {action_name},原因: {reason}")
|
||||||
|
|
||||||
|
|
||||||
# === 第二阶段:激活类型判定 ===
|
# === 第二阶段:激活类型判定 ===
|
||||||
if chat_content is not None:
|
if chat_content is not None:
|
||||||
logger.debug(f"{self.log_prefix}开始激活类型判定阶段")
|
logger.debug(f"{self.log_prefix}开始激活类型判定阶段")
|
||||||
@@ -136,9 +135,7 @@ class ActionModifier:
|
|||||||
associated_types_str = ", ".join(data["associated_types"])
|
associated_types_str = ", ".join(data["associated_types"])
|
||||||
reason = f"适配器不支持(需要: {associated_types_str})"
|
reason = f"适配器不支持(需要: {associated_types_str})"
|
||||||
type_mismatched_actions.append((action_name, reason))
|
type_mismatched_actions.append((action_name, reason))
|
||||||
logger.debug(
|
logger.debug(f"{self.log_prefix}决定移除动作: {action_name},原因: {reason}")
|
||||||
f"{self.log_prefix}决定移除动作: {action_name},原因: {reason}"
|
|
||||||
)
|
|
||||||
return type_mismatched_actions
|
return type_mismatched_actions
|
||||||
|
|
||||||
async def _get_deactivated_actions_by_type(
|
async def _get_deactivated_actions_by_type(
|
||||||
@@ -512,21 +509,23 @@ class ActionModifier:
|
|||||||
# 如果最近sec_thres_reply_num次都是reply,40%概率移除
|
# 如果最近sec_thres_reply_num次都是reply,40%概率移除
|
||||||
removal_probability = 0.4 / global_config.focus_chat.consecutive_replies
|
removal_probability = 0.4 / global_config.focus_chat.consecutive_replies
|
||||||
if random.random() < removal_probability:
|
if random.random() < removal_probability:
|
||||||
reason = f"连续回复较多(最近{sec_thres_reply_num}次全是reply,{removal_probability:.2f}概率移除,触发移除)"
|
reason = (
|
||||||
|
f"连续回复较多(最近{sec_thres_reply_num}次全是reply,{removal_probability:.2f}概率移除,触发移除)"
|
||||||
|
)
|
||||||
removals.append(("reply", reason))
|
removals.append(("reply", reason))
|
||||||
elif len(last_max_reply_num) >= one_thres_reply_num and all(last_max_reply_num[-one_thres_reply_num:]):
|
elif len(last_max_reply_num) >= one_thres_reply_num and all(last_max_reply_num[-one_thres_reply_num:]):
|
||||||
# 如果最近one_thres_reply_num次都是reply,20%概率移除
|
# 如果最近one_thres_reply_num次都是reply,20%概率移除
|
||||||
removal_probability = 0.2 / global_config.focus_chat.consecutive_replies
|
removal_probability = 0.2 / global_config.focus_chat.consecutive_replies
|
||||||
if random.random() < removal_probability:
|
if random.random() < removal_probability:
|
||||||
reason = f"连续回复检测(最近{one_thres_reply_num}次全是reply,{removal_probability:.2f}概率移除,触发移除)"
|
reason = (
|
||||||
|
f"连续回复检测(最近{one_thres_reply_num}次全是reply,{removal_probability:.2f}概率移除,触发移除)"
|
||||||
|
)
|
||||||
removals.append(("reply", reason))
|
removals.append(("reply", reason))
|
||||||
else:
|
else:
|
||||||
logger.debug(f"{self.log_prefix}连续回复检测:无需移除reply动作,最近回复模式正常")
|
logger.debug(f"{self.log_prefix}连续回复检测:无需移除reply动作,最近回复模式正常")
|
||||||
|
|
||||||
return removals
|
return removals
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_available_actions_count(self) -> int:
|
def get_available_actions_count(self) -> int:
|
||||||
"""获取当前可用动作数量(排除默认的no_action)"""
|
"""获取当前可用动作数量(排除默认的no_action)"""
|
||||||
current_actions = self.action_manager.get_using_actions_for_mode("normal")
|
current_actions = self.action_manager.get_using_actions_for_mode("normal")
|
||||||
|
|||||||
@@ -104,9 +104,7 @@ class ActionPlanner:
|
|||||||
try:
|
try:
|
||||||
# 重新获取更准确的聊天信息
|
# 重新获取更准确的聊天信息
|
||||||
is_group_chat, chat_target_info = get_chat_type_and_target_info(self.chat_id)
|
is_group_chat, chat_target_info = get_chat_type_and_target_info(self.chat_id)
|
||||||
logger.debug(
|
logger.debug(f"{self.log_prefix}获取到聊天信息 - 群聊: {is_group_chat}, 目标信息: {chat_target_info}")
|
||||||
f"{self.log_prefix}获取到聊天信息 - 群聊: {is_group_chat}, 目标信息: {chat_target_info}"
|
|
||||||
)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"{self.log_prefix}获取聊天目标信息失败: {e}")
|
logger.warning(f"{self.log_prefix}获取聊天目标信息失败: {e}")
|
||||||
chat_target_info = None
|
chat_target_info = None
|
||||||
@@ -201,7 +199,6 @@ class ActionPlanner:
|
|||||||
if key not in ["action", "reasoning"]:
|
if key not in ["action", "reasoning"]:
|
||||||
action_data[key] = value
|
action_data[key] = value
|
||||||
|
|
||||||
|
|
||||||
if extracted_action not in current_available_actions:
|
if extracted_action not in current_available_actions:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"{self.log_prefix}LLM 返回了当前不可用或无效的动作: '{extracted_action}' (可用: {list(current_available_actions.keys())}),将强制使用 'no_reply'"
|
f"{self.log_prefix}LLM 返回了当前不可用或无效的动作: '{extracted_action}' (可用: {list(current_available_actions.keys())}),将强制使用 'no_reply'"
|
||||||
@@ -266,8 +263,6 @@ class ActionPlanner:
|
|||||||
action_options_block = ""
|
action_options_block = ""
|
||||||
|
|
||||||
for using_actions_name, using_actions_info in current_available_actions.items():
|
for using_actions_name, using_actions_info in current_available_actions.items():
|
||||||
|
|
||||||
|
|
||||||
if using_actions_info["parameters"]:
|
if using_actions_info["parameters"]:
|
||||||
param_text = "\n"
|
param_text = "\n"
|
||||||
for param_name, param_description in using_actions_info["parameters"].items():
|
for param_name, param_description in using_actions_info["parameters"].items():
|
||||||
|
|||||||
@@ -642,6 +642,7 @@ def translate_timestamp_to_human_readable(timestamp: float, mode: str = "normal"
|
|||||||
# 只返回时分秒格式,喵~
|
# 只返回时分秒格式,喵~
|
||||||
return time.strftime("%H:%M:%S", time.localtime(timestamp))
|
return time.strftime("%H:%M:%S", time.localtime(timestamp))
|
||||||
|
|
||||||
|
|
||||||
def get_chat_type_and_target_info(chat_id: str) -> Tuple[bool, Optional[Dict]]:
|
def get_chat_type_and_target_info(chat_id: str) -> Tuple[bool, Optional[Dict]]:
|
||||||
"""
|
"""
|
||||||
获取聊天类型(是否群聊)和私聊对象信息。
|
获取聊天类型(是否群聊)和私聊对象信息。
|
||||||
|
|||||||
@@ -300,7 +300,6 @@ class FocusChatConfig(ConfigBase):
|
|||||||
"""连续回复能力,值越高,麦麦连续回复的概率越高"""
|
"""连续回复能力,值越高,麦麦连续回复的概率越高"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ExpressionConfig(ConfigBase):
|
class ExpressionConfig(ConfigBase):
|
||||||
"""表达配置类"""
|
"""表达配置类"""
|
||||||
|
|||||||
Reference in New Issue
Block a user