refactor(core): 适配核心数据获取与消息构建函数的异步调用

在数据库交互层异步化后,多个相关的数据获取和消息构建函数(如 `build_readable_messages`)也转为异步实现。本次提交在所有调用点添加了 `await` 关键字,以适应这一变化。

此外,本次提交还包含以下修复:
- 在主动思考模块中增加了对规划器返回无效动作的检查,避免后续流程出错。
- 修正了日志记录中错误的上下文变量引用。
This commit is contained in:
tt-P607
2025-09-20 13:52:37 +08:00
committed by Windpicker-owo
parent 5892ed1452
commit dedd06efdc
11 changed files with 27 additions and 23 deletions

View File

@@ -192,7 +192,7 @@ class CycleProcessor:
await self.action_modifier.modify_actions()
available_actions = self.context.action_manager.get_using_actions()
except Exception as e:
logger.error(f"{self.context.log_prefix} 动作修改失败: {e}")
logger.error(f"{self.log_prefix} 动作修改失败: {e}")
available_actions = {}
# 规划动作

View File

@@ -120,6 +120,10 @@ class ProactiveThinker:
action_result = actions[0] if actions else {}
action_type = action_result.get("action_type")
if action_type is None:
logger.info(f"{self.context.log_prefix} 主动思考决策: 规划器未返回有效动作")
return
if action_type == "proactive_reply":
await self._generate_proactive_content_and_send(action_result, trigger_event)
elif action_type not in ["do_nothing", "no_action"]:
@@ -212,12 +216,12 @@ class ProactiveThinker:
logger.warning(f"{self.context.log_prefix} 主题为空,跳过网络搜索。")
except Exception as e:
logger.error(f"{self.context.log_prefix} 主动思考时网络搜索失败: {e}")
message_list = get_raw_msg_before_timestamp_with_chat(
message_list = await get_raw_msg_before_timestamp_with_chat(
chat_id=self.context.stream_id,
timestamp=time.time(),
limit=int(global_config.chat.max_context_size * 0.3),
)
chat_context_block, _ = build_readable_messages_with_id(messages=message_list)
chat_context_block, _ = await build_readable_messages_with_id(messages=message_list)
from src.llm_models.utils_model import LLMRequest
from src.config.config import model_config