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

@@ -163,7 +163,7 @@ class ChatAction:
limit=15,
limit_mode="last",
)
chat_talking_prompt = build_readable_messages(
chat_talking_prompt = await build_readable_messages(
message_list_before_now,
replace_bot_name=True,
merge_messages=False,
@@ -227,7 +227,7 @@ class ChatAction:
limit=10,
limit_mode="last",
)
chat_talking_prompt = build_readable_messages(
chat_talking_prompt = await build_readable_messages(
message_list_before_now,
replace_bot_name=True,
merge_messages=False,

View File

@@ -167,7 +167,7 @@ class ChatMood:
limit=10,
limit_mode="last",
)
chat_talking_prompt = build_readable_messages(
chat_talking_prompt = await build_readable_messages(
message_list_before_now,
replace_bot_name=True,
merge_messages=False,
@@ -246,7 +246,7 @@ class ChatMood:
limit=5,
limit_mode="last",
)
chat_talking_prompt = build_readable_messages(
chat_talking_prompt = await build_readable_messages(
message_list_before_now,
replace_bot_name=True,
merge_messages=False,

View File

@@ -173,7 +173,7 @@ class PromptBuilder:
return ""
@staticmethod
def build_chat_history_prompts(chat_stream: ChatStream, message: MessageRecvS4U):
async def build_chat_history_prompts(chat_stream: ChatStream, message: MessageRecvS4U):
message_list_before_now = get_raw_msg_before_timestamp_with_chat(
chat_id=chat_stream.stream_id,
timestamp=time.time(),
@@ -207,7 +207,7 @@ class PromptBuilder:
background_dialogue_prompt = ""
if background_dialogue_list:
context_msgs = background_dialogue_list[-s4u_config.max_context_message_length :]
background_dialogue_prompt_str = build_readable_messages(
background_dialogue_prompt_str = await build_readable_messages(
context_msgs,
timestamp_mode="normal_no_YMD",
show_pic=False,
@@ -256,7 +256,7 @@ class PromptBuilder:
timestamp=time.time(),
limit=20,
)
all_dialogue_prompt_str = build_readable_messages(
all_dialogue_prompt_str = await build_readable_messages(
all_dialogue_prompt,
timestamp_mode="normal_no_YMD",
show_pic=False,
@@ -306,7 +306,7 @@ class PromptBuilder:
self.build_expression_habits(chat_stream, message_txt, sender_name),
)
core_dialogue_prompt, background_dialogue_prompt, all_dialogue_prompt = self.build_chat_history_prompts(
core_dialogue_prompt, background_dialogue_prompt, all_dialogue_prompt = await self.build_chat_history_prompts(
chat_stream, message
)