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

This commit is contained in:
github-actions[bot]
2025-04-23 02:29:47 +00:00
parent 9eaf72e4f9
commit 705e876735
2 changed files with 14 additions and 10 deletions

View File

@@ -343,10 +343,15 @@ class Heartflow:
for sub_hf in subflows_snapshot: for sub_hf in subflows_snapshot:
# Double-check if subflow still exists and is in CHAT state # Double-check if subflow still exists and is in CHAT state
if sub_hf.subheartflow_id in self._subheartflows and sub_hf.chat_state.chat_status == ChatState.CHAT: if (
sub_hf.subheartflow_id in self._subheartflows
and sub_hf.chat_state.chat_status == ChatState.CHAT
):
evaluated_count += 1 evaluated_count += 1
if await sub_hf.should_evaluate_reply(): if await sub_hf.should_evaluate_reply():
stream_name = chat_manager.get_stream_name(sub_hf.subheartflow_id) or sub_hf.subheartflow_id stream_name = (
chat_manager.get_stream_name(sub_hf.subheartflow_id) or sub_hf.subheartflow_id
)
log_prefix = f"[{stream_name}]" log_prefix = f"[{stream_name}]"
logger.info(f"{log_prefix} 兴趣概率触发,尝试将状态从 CHAT 提升到 FOCUSED") logger.info(f"{log_prefix} 兴趣概率触发,尝试将状态从 CHAT 提升到 FOCUSED")
# set_chat_state handles limit checks and HeartFChatting creation internally # set_chat_state handles limit checks and HeartFChatting creation internally
@@ -377,7 +382,7 @@ class Heartflow:
"""获取所有活跃子心流的当前兴趣状态""" """获取所有活跃子心流的当前兴趣状态"""
_states = {} _states = {}
# 创建副本以避免在迭代时修改字典 # 创建副本以避免在迭代时修改字典
items_snapshot = list(self._subheartflows.items()) # Make a copy for safe iteration items_snapshot = list(self._subheartflows.items()) # Make a copy for safe iteration
tasks = [] tasks = []
results = {} results = {}
@@ -391,7 +396,7 @@ class Heartflow:
# Wait for all tasks to complete # Wait for all tasks to complete
if tasks: if tasks:
done, pending = await asyncio.wait(tasks, timeout=5.0) # Add a timeout done, pending = await asyncio.wait(tasks, timeout=5.0) # Add a timeout
if pending: if pending:
logger.warning(f"[Heartflow] Getting interest states timed out for {len(pending)} tasks.") logger.warning(f"[Heartflow] Getting interest states timed out for {len(pending)} tasks.")
@@ -399,12 +404,12 @@ class Heartflow:
task.cancel() task.cancel()
for task in done: for task in done:
stream_id = task.get_name().split("_")[-1] # Extract stream_id from task name stream_id = task.get_name().split("_")[-1] # Extract stream_id from task name
try: try:
result = task.result() result = task.result()
results[stream_id] = result results[stream_id] = result
except asyncio.CancelledError: except asyncio.CancelledError:
logger.warning(f"[Heartflow] Task to get interest state for {stream_id} was cancelled (timeout).") logger.warning(f"[Heartflow] Task to get interest state for {stream_id} was cancelled (timeout).")
except Exception as e: except Exception as e:
logger.warning(f"[Heartflow] Error getting interest state for subheartflow {stream_id}: {e}") logger.warning(f"[Heartflow] Error getting interest state for subheartflow {stream_id}: {e}")

View File

@@ -476,7 +476,6 @@ class PromptBuilder:
return related_info return related_info
async def get_prompt_info(self, message: str, threshold: float): async def get_prompt_info(self, message: str, threshold: float):
related_info = "" related_info = ""
start_time = time.time() start_time = time.time()
@@ -486,7 +485,9 @@ class PromptBuilder:
end_time = time.time() end_time = time.time()
if found_knowledge_from_lpmm is not None: if found_knowledge_from_lpmm is not None:
logger.debug(f"从LPMM知识库获取知识相关信息{found_knowledge_from_lpmm[:100]}...,信息长度: {len(found_knowledge_from_lpmm)}") logger.debug(
f"从LPMM知识库获取知识相关信息{found_knowledge_from_lpmm[:100]}...,信息长度: {len(found_knowledge_from_lpmm)}"
)
related_info += found_knowledge_from_lpmm related_info += found_knowledge_from_lpmm
logger.debug(f"获取知识库内容耗时: {(end_time - start_time):.3f}") logger.debug(f"获取知识库内容耗时: {(end_time - start_time):.3f}")
logger.debug(f"获取知识库内容,相关信息:{related_info[:100]}...,信息长度: {len(related_info)}") logger.debug(f"获取知识库内容,相关信息:{related_info[:100]}...,信息长度: {len(related_info)}")
@@ -498,8 +499,6 @@ class PromptBuilder:
logger.debug(f"获取知识库内容,相关信息:{related_info[:100]}...,信息长度: {len(related_info)}") logger.debug(f"获取知识库内容,相关信息:{related_info[:100]}...,信息长度: {len(related_info)}")
return related_info return related_info
@staticmethod @staticmethod
def get_info_from_db( def get_info_from_db(
query_embedding: list, limit: int = 1, threshold: float = 0.5, return_raw: bool = False query_embedding: list, limit: int = 1, threshold: float = 0.5, return_raw: bool = False