docs(core): 为核心模块添加日志记录和文档字符串

为 `cycle_processor`, `response_handler`, `generator_api`, 和 `send_api` 等核心代码文件补充了日志记录器和详细的文档字符串(docstrings)。

本次更新旨在提高代码的可读性和可维护性,通过清晰的文档注释和日志输出,使其他开发者能更容易地理解代码逻辑和功能,并为未来的调试和功能扩展提供便利。
This commit is contained in:
minecraft1024a
2025-09-06 15:52:21 +08:00
committed by Windpicker-owo
parent 89fad16e0e
commit 4b6b5d610c
4 changed files with 88 additions and 3 deletions

View File

@@ -20,6 +20,7 @@ from src.plugin_system.base.component_types import ActionInfo
install(extra_lines=3)
# 日志记录器
logger = get_logger("generator_api")
@@ -115,6 +116,11 @@ async def generate_reply(
logger.error("[GeneratorAPI] 无法获取回复器")
return False, [], None
logger.debug("[GeneratorAPI] 开始生成回复")
# 向下兼容从action_data中获取reply_to和extra_info
if not reply_to and action_data:
reply_to = action_data.get("reply_to", "")
if not extra_info and action_data:
extra_info = action_data.get("extra_info", "")
@@ -138,6 +144,7 @@ async def generate_reply(
return False, [], None
assert llm_response_dict is not None, "llm_response_dict不应为None" # 虽然说不会出现llm_response为空的情况
if content := llm_response_dict.get("content", ""):
# 处理为拟人化文本
reply_set = process_human_text(content, enable_splitter, enable_chinese_typo)
else:
reply_set = []
@@ -219,6 +226,7 @@ async def rewrite_reply(
)
reply_set = []
if content:
# 处理为拟人化文本
reply_set = process_human_text(content, enable_splitter, enable_chinese_typo)
if success:
@@ -249,6 +257,7 @@ def process_human_text(
if not isinstance(content, str):
raise ValueError("content 必须是字符串类型")
try:
# 处理LLM响应
processed_response = process_llm_response(content, enable_splitter, enable_chinese_typo)
reply_set = []
@@ -271,6 +280,18 @@ async def generate_response_custom(
request_type: str = "generator_api",
prompt: str = "",
) -> Optional[str]:
"""
使用自定义提示生成回复
Args:
chat_stream: 聊天流对象
chat_id: 聊天ID
request_type: 请求类型
prompt: 自定义提示
Returns:
Optional[str]: 生成的回复内容
"""
replyer = get_replyer(chat_stream, chat_id, request_type=request_type)
if not replyer:
logger.error("[GeneratorAPI] 无法获取回复器")

View File

@@ -43,6 +43,7 @@ from src.chat.message_receive.message import MessageSending, MessageRecv
from maim_message import Seg
from src.config.config import global_config
# 日志记录器
logger = get_logger("send_api")
# 适配器命令响应等待池
@@ -187,6 +188,7 @@ async def _send_to_target(
# 创建消息段
message_segment = Seg(type=message_type, data=content) # type: ignore
# 处理回复消息
if reply_to_message:
anchor_message = message_dict_to_message_recv(message_dict=reply_to_message)
if anchor_message and anchor_message.message_info and anchor_message.message_info.user_info: