**我撞到dict了
This commit is contained in:
committed by
Windpicker-owo
parent
159ff11524
commit
2ed9e44242
@@ -26,7 +26,6 @@ from src.chat.utils.memory_mappings import get_memory_type_chinese_label
|
|||||||
from src.chat.utils.prompt import Prompt, PromptParameters, global_prompt_manager
|
from src.chat.utils.prompt import Prompt, PromptParameters, global_prompt_manager
|
||||||
from src.chat.utils.timer_calculator import Timer
|
from src.chat.utils.timer_calculator import Timer
|
||||||
from src.chat.utils.utils import get_chat_type_and_target_info
|
from src.chat.utils.utils import get_chat_type_and_target_info
|
||||||
from src.common.data_models.database_data_model import DatabaseMessages
|
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger
|
||||||
from src.config.config import global_config, model_config
|
from src.config.config import global_config, model_config
|
||||||
from src.individuality.individuality import get_individuality
|
from src.individuality.individuality import get_individuality
|
||||||
@@ -265,7 +264,7 @@ class DefaultReplyer:
|
|||||||
enable_tool: bool = True,
|
enable_tool: bool = True,
|
||||||
from_plugin: bool = True,
|
from_plugin: bool = True,
|
||||||
stream_id: str | None = None,
|
stream_id: str | None = None,
|
||||||
reply_message: DatabaseMessages | None = None,
|
reply_message: dict[str, Any] | None = None,
|
||||||
) -> tuple[bool, dict[str, Any] | None, str | None]:
|
) -> tuple[bool, dict[str, Any] | None, str | None]:
|
||||||
# sourcery skip: merge-nested-ifs
|
# sourcery skip: merge-nested-ifs
|
||||||
"""
|
"""
|
||||||
@@ -1150,7 +1149,7 @@ class DefaultReplyer:
|
|||||||
extra_info: str = "",
|
extra_info: str = "",
|
||||||
available_actions: dict[str, ActionInfo] | None = None,
|
available_actions: dict[str, ActionInfo] | None = None,
|
||||||
enable_tool: bool = True,
|
enable_tool: bool = True,
|
||||||
reply_message: DatabaseMessages | dict[str, Any] | None = None,
|
reply_message: dict[str, Any] | None = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""
|
"""
|
||||||
构建回复器上下文
|
构建回复器上下文
|
||||||
@@ -1169,11 +1168,6 @@ class DefaultReplyer:
|
|||||||
"""
|
"""
|
||||||
if available_actions is None:
|
if available_actions is None:
|
||||||
available_actions = {}
|
available_actions = {}
|
||||||
|
|
||||||
# 确保 reply_message 是 DatabaseMessages 对象
|
|
||||||
if isinstance(reply_message, dict):
|
|
||||||
reply_message = DatabaseMessages(**reply_message)
|
|
||||||
|
|
||||||
chat_stream = self.chat_stream
|
chat_stream = self.chat_stream
|
||||||
chat_id = chat_stream.stream_id
|
chat_id = chat_stream.stream_id
|
||||||
person_info_manager = get_person_info_manager()
|
person_info_manager = get_person_info_manager()
|
||||||
@@ -1198,10 +1192,10 @@ class DefaultReplyer:
|
|||||||
if reply_message is None:
|
if reply_message is None:
|
||||||
logger.warning("reply_message 为 None,无法构建prompt")
|
logger.warning("reply_message 为 None,无法构建prompt")
|
||||||
return ""
|
return ""
|
||||||
platform = reply_message.chat_info.platform
|
platform = reply_message.get("chat_info_platform")
|
||||||
person_id = person_info_manager.get_person_id(
|
person_id = person_info_manager.get_person_id(
|
||||||
platform, # type: ignore
|
platform, # type: ignore
|
||||||
reply_message.user_info.user_id, # type: ignore
|
reply_message.get("user_id"), # type: ignore
|
||||||
)
|
)
|
||||||
person_name = await person_info_manager.get_value(person_id, "person_name")
|
person_name = await person_info_manager.get_value(person_id, "person_name")
|
||||||
|
|
||||||
@@ -1210,22 +1204,22 @@ class DefaultReplyer:
|
|||||||
# 尝试从reply_message获取用户名
|
# 尝试从reply_message获取用户名
|
||||||
await person_info_manager.first_knowing_some_one(
|
await person_info_manager.first_knowing_some_one(
|
||||||
platform, # type: ignore
|
platform, # type: ignore
|
||||||
reply_message.user_info.user_id, # type: ignore
|
reply_message.get("user_id"), # type: ignore
|
||||||
reply_message.user_info.user_nickname or "",
|
reply_message.get("user_nickname") or "",
|
||||||
reply_message.user_info.user_cardname or "",
|
reply_message.get("user_cardname") or "",
|
||||||
)
|
)
|
||||||
|
|
||||||
# 检查是否是bot自己的名字,如果是则替换为"(你)"
|
# 检查是否是bot自己的名字,如果是则替换为"(你)"
|
||||||
bot_user_id = str(global_config.bot.qq_account)
|
bot_user_id = str(global_config.bot.qq_account)
|
||||||
current_user_id = await person_info_manager.get_value(person_id, "user_id")
|
current_user_id = await person_info_manager.get_value(person_id, "user_id")
|
||||||
current_platform = reply_message.chat_info.platform
|
current_platform = reply_message.get("chat_info_platform")
|
||||||
|
|
||||||
if current_user_id == bot_user_id and current_platform == global_config.bot.platform:
|
if current_user_id == bot_user_id and current_platform == global_config.bot.platform:
|
||||||
sender = f"{person_name}(你)"
|
sender = f"{person_name}(你)"
|
||||||
else:
|
else:
|
||||||
# 如果不是bot自己,直接使用person_name
|
# 如果不是bot自己,直接使用person_name
|
||||||
sender = person_name
|
sender = person_name
|
||||||
target = reply_message.processed_plain_text
|
target = reply_message.get("processed_plain_text")
|
||||||
|
|
||||||
# 最终的空值检查,确保sender和target不为None
|
# 最终的空值检查,确保sender和target不为None
|
||||||
if sender is None:
|
if sender is None:
|
||||||
@@ -1572,7 +1566,7 @@ class DefaultReplyer:
|
|||||||
raw_reply: str,
|
raw_reply: str,
|
||||||
reason: str,
|
reason: str,
|
||||||
reply_to: str,
|
reply_to: str,
|
||||||
reply_message: DatabaseMessages | None = None,
|
reply_message: dict[str, Any] | None = None,
|
||||||
) -> str: # sourcery skip: merge-else-if-into-elif, remove-redundant-if
|
) -> str: # sourcery skip: merge-else-if-into-elif, remove-redundant-if
|
||||||
await self._async_init()
|
await self._async_init()
|
||||||
chat_stream = self.chat_stream
|
chat_stream = self.chat_stream
|
||||||
@@ -1580,8 +1574,8 @@ class DefaultReplyer:
|
|||||||
is_group_chat = self.is_group_chat
|
is_group_chat = self.is_group_chat
|
||||||
|
|
||||||
if reply_message:
|
if reply_message:
|
||||||
sender = reply_message.user_info.user_nickname or reply_message.user_info.user_cardname
|
sender = reply_message.get("sender")
|
||||||
target = reply_message.processed_plain_text
|
target = reply_message.get("target")
|
||||||
else:
|
else:
|
||||||
sender, target = self._parse_reply_target(reply_to)
|
sender, target = self._parse_reply_target(reply_to)
|
||||||
|
|
||||||
|
|||||||
@@ -279,9 +279,6 @@ class ChatterPlanFilter:
|
|||||||
is_group_chat = plan.chat_type == ChatType.GROUP
|
is_group_chat = plan.chat_type == ChatType.GROUP
|
||||||
chat_context_description = "你现在正在一个群聊中"
|
chat_context_description = "你现在正在一个群聊中"
|
||||||
if not is_group_chat and plan.target_info:
|
if not is_group_chat and plan.target_info:
|
||||||
if isinstance(plan.target_info, dict):
|
|
||||||
chat_target_name = plan.target_info.get("person_name") or plan.target_info.get("user_nickname") or "对方"
|
|
||||||
else:
|
|
||||||
chat_target_name = plan.target_info.person_name or plan.target_info.user_nickname or "对方"
|
chat_target_name = plan.target_info.person_name or plan.target_info.user_nickname or "对方"
|
||||||
chat_context_description = f"你正在和 {chat_target_name} 私聊"
|
chat_context_description = f"你正在和 {chat_target_name} 私聊"
|
||||||
|
|
||||||
@@ -557,21 +554,21 @@ class ChatterPlanFilter:
|
|||||||
):
|
):
|
||||||
reasoning = f"LLM 返回了当前不可用的动作 '{action}'。原始理由: {reasoning}"
|
reasoning = f"LLM 返回了当前不可用的动作 '{action}'。原始理由: {reasoning}"
|
||||||
action = "no_action"
|
action = "no_action"
|
||||||
from src.common.data_models.database_data_model import DatabaseMessages
|
#from src.common.data_models.database_data_model import DatabaseMessages
|
||||||
|
|
||||||
action_message_obj = None
|
#action_message_obj = None
|
||||||
if target_message_obj:
|
#if target_message_obj:
|
||||||
try:
|
#try:
|
||||||
action_message_obj = DatabaseMessages(**target_message_obj)
|
#action_message_obj = DatabaseMessages(**target_message_obj)
|
||||||
except Exception:
|
#except Exception:
|
||||||
logger.warning("无法将目标消息转换为DatabaseMessages对象")
|
#logger.warning("无法将目标消息转换为DatabaseMessages对象")
|
||||||
|
|
||||||
parsed_actions.append(
|
parsed_actions.append(
|
||||||
ActionPlannerInfo(
|
ActionPlannerInfo(
|
||||||
action_type=action,
|
action_type=action,
|
||||||
reasoning=reasoning,
|
reasoning=reasoning,
|
||||||
action_data=action_data,
|
action_data=action_data,
|
||||||
action_message=action_message_obj,
|
action_message=target_message_obj,
|
||||||
available_actions=plan.available_actions,
|
available_actions=plan.available_actions,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -458,7 +458,7 @@ class QZoneService:
|
|||||||
raise RuntimeError(f"获取 cookie 失败: {data}")
|
raise RuntimeError(f"获取 cookie 失败: {data}")
|
||||||
return data["data"]
|
return data["data"]
|
||||||
|
|
||||||
except aiohttp.ClientError as e: # noqa: PERF203
|
except aiohttp.ClientError as e:
|
||||||
if attempt < max_retries - 1:
|
if attempt < max_retries - 1:
|
||||||
logger.warning(f"无法连接到Napcat服务(尝试 {attempt + 1}/{max_retries}): {url},错误: {e!s}")
|
logger.warning(f"无法连接到Napcat服务(尝试 {attempt + 1}/{max_retries}): {url},错误: {e!s}")
|
||||||
await asyncio.sleep(retry_delay)
|
await asyncio.sleep(retry_delay)
|
||||||
|
|||||||
Reference in New Issue
Block a user