mirror of https://github.com/Mai-with-u/MaiBot.git
ruff
parent
589045ba80
commit
646ca52526
|
|
@ -228,7 +228,8 @@ class ActionPlanner:
|
|||
chat_history_text = await self._build_chat_history_text(observation_info)
|
||||
# 获取 sender_name, relationship_text, current_emotion_text
|
||||
sender_name_str = getattr(observation_info, 'sender_name', '对方') # 从 observation_info 获取
|
||||
if not sender_name_str: sender_name_str = '对方' # 再次确保有默认值
|
||||
if not sender_name_str:
|
||||
sender_name_str = '对方' # 再次确保有默认值
|
||||
|
||||
relationship_text_str = getattr(conversation_info, 'relationship_text', '你们还不熟悉。')
|
||||
current_emotion_text_str = getattr(conversation_info, 'current_emotion_text', '心情平静。')
|
||||
|
|
@ -507,7 +508,7 @@ class ActionPlanner:
|
|||
logger.debug(f"[私聊][{self.private_name}] 向 LLM 追加了 {other_unread_count} 条未读消息。")
|
||||
else:
|
||||
chat_history_text += (
|
||||
f"\n--- 以上均为已读消息,未读消息均已处理完毕 ---\n"
|
||||
"\n--- 以上均为已读消息,未读消息均已处理完毕 ---\n"
|
||||
)
|
||||
except AttributeError as e:
|
||||
logger.warning(f"[私聊][{self.private_name}] 构建聊天记录文本时属性错误: {e}")
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import asyncio
|
|||
import datetime
|
||||
import traceback
|
||||
import json
|
||||
from typing import Dict, Any, Optional, Set, TYPE_CHECKING
|
||||
from typing import Optional, Set, TYPE_CHECKING
|
||||
|
||||
from src.common.logger_manager import get_logger
|
||||
from src.config.config import global_config
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
import time
|
||||
import asyncio
|
||||
import datetime
|
||||
import traceback
|
||||
import json
|
||||
from typing import Dict, Any, Optional, Set, List
|
||||
from dateutil import tz
|
||||
from typing import Dict, Any, Optional
|
||||
|
||||
from src.common.logger_manager import get_logger
|
||||
from src.plugins.utils.chat_message_builder import build_readable_messages # 移除了 get_raw_msg_before_timestamp_with_chat
|
||||
from maim_message import UserInfo
|
||||
from src.plugins.chat.chat_stream import chat_manager, ChatStream
|
||||
from ..chat.message import Message # 假设 Message 类型被 _convert_to_message 使用
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import time
|
||||
import asyncio
|
||||
import traceback
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import time
|
|||
import asyncio
|
||||
import datetime
|
||||
import traceback
|
||||
from typing import Dict, Any, Optional, Set, List, TYPE_CHECKING
|
||||
from typing import Dict, Any, List, TYPE_CHECKING
|
||||
from dateutil import tz
|
||||
|
||||
from src.common.logger_manager import get_logger
|
||||
|
|
@ -176,7 +176,8 @@ async def run_conversation_loop(conversation_instance: 'Conversation'):
|
|||
logger.info(f"[私聊][{conversation_instance.private_name}] (Loop) 中断 '{action}',原因: {interrupt_reason}。重新规划...")
|
||||
cancel_record = { "action": action, "plan_reason": reason, "status": "cancelled_due_to_new_messages", "time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "final_reason": interrupt_reason, }
|
||||
if conversation_instance.conversation_info:
|
||||
if not hasattr(conversation_instance.conversation_info, "done_action") or conversation_instance.conversation_info.done_action is None: conversation_instance.conversation_info.done_action = []
|
||||
if not hasattr(conversation_instance.conversation_info, "done_action") or conversation_instance.conversation_info.done_action is None:
|
||||
conversation_instance.conversation_info.done_action = []
|
||||
conversation_instance.conversation_info.done_action.append(cancel_record)
|
||||
conversation_instance.conversation_info.last_successful_reply_action = None
|
||||
conversation_instance.state = ConversationState.ANALYZING
|
||||
|
|
@ -204,7 +205,8 @@ async def run_conversation_loop(conversation_instance: 'Conversation'):
|
|||
if conversation_instance.conversation_info and hasattr(conversation_instance.conversation_info, "goal_list") and conversation_instance.conversation_info.goal_list:
|
||||
last_goal_item = conversation_instance.conversation_info.goal_list[-1]
|
||||
current_goal = last_goal_item.get("goal") if isinstance(last_goal_item, dict) else (last_goal_item if isinstance(last_goal_item, str) else None)
|
||||
if current_goal == "结束对话": goal_ended = True
|
||||
if current_goal == "结束对话":
|
||||
goal_ended = True
|
||||
|
||||
last_action_record_for_end_check = {}
|
||||
if conversation_instance.conversation_info and conversation_instance.conversation_info.done_action:
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ class GoalAnalyzer:
|
|||
chat_history_text += f"\n--- 以下是 {observation_info.new_messages_count} 条新消息 ---\n{new_messages_str}"
|
||||
else:
|
||||
chat_history_text += (
|
||||
f"\n--- 以上均为已读消息,未读消息均已处理完毕 ---\n"
|
||||
"\n--- 以上均为已读消息,未读消息均已处理完毕 ---\n"
|
||||
)
|
||||
# await observation_info.clear_unprocessed_messages()
|
||||
|
||||
|
|
@ -283,66 +283,4 @@ class GoalAnalyzer:
|
|||
|
||||
except Exception as e:
|
||||
logger.error(f"[私聊][{self.private_name}]分析对话状态时出错: {str(e)}")
|
||||
return False, False, f"分析出错: {str(e)}"
|
||||
|
||||
|
||||
# 先注释掉,万一以后出问题了还能开回来(((
|
||||
# class DirectMessageSender:
|
||||
# """直接发送消息到平台的发送器"""
|
||||
|
||||
# def __init__(self, private_name: str):
|
||||
# self.logger = get_module_logger("direct_sender")
|
||||
# self.storage = MessageStorage()
|
||||
# self.private_name = private_name
|
||||
|
||||
# async def send_via_ws(self, message: MessageSending) -> None:
|
||||
# try:
|
||||
# await global_api.send_message(message)
|
||||
# except Exception as e:
|
||||
# raise ValueError(f"未找到平台:{message.message_info.platform} 的url配置,请检查配置文件") from e
|
||||
|
||||
# async def send_message(
|
||||
# self,
|
||||
# chat_stream: ChatStream,
|
||||
# content: str,
|
||||
# reply_to_message: Optional[Message] = None,
|
||||
# ) -> None:
|
||||
# """直接发送消息到平台
|
||||
|
||||
# Args:
|
||||
# chat_stream: 聊天流
|
||||
# content: 消息内容
|
||||
# reply_to_message: 要回复的消息
|
||||
# """
|
||||
# # 构建消息对象
|
||||
# message_segment = Seg(type="text", data=content)
|
||||
# bot_user_info = UserInfo(
|
||||
# user_id=global_config.BOT_QQ,
|
||||
# user_nickname=global_config.BOT_NICKNAME,
|
||||
# platform=chat_stream.platform,
|
||||
# )
|
||||
|
||||
# message = MessageSending(
|
||||
# message_id=f"dm{round(time.time(), 2)}",
|
||||
# chat_stream=chat_stream,
|
||||
# bot_user_info=bot_user_info,
|
||||
# sender_info=reply_to_message.message_info.user_info if reply_to_message else None,
|
||||
# message_segment=message_segment,
|
||||
# reply=reply_to_message,
|
||||
# is_head=True,
|
||||
# is_emoji=False,
|
||||
# thinking_start_time=time.time(),
|
||||
# )
|
||||
|
||||
# # 处理消息
|
||||
# await message.process()
|
||||
|
||||
# _message_json = message.to_dict()
|
||||
|
||||
# # 发送消息
|
||||
# try:
|
||||
# await self.send_via_ws(message)
|
||||
# await self.storage.store_message(message, chat_stream)
|
||||
# logger.success(f"[私聊][{self.private_name}]PFC消息已发送: {content}")
|
||||
# except Exception as e:
|
||||
# logger.error(f"[私聊][{self.private_name}]PFC消息发送失败: {str(e)}")
|
||||
return False, False, f"分析出错: {str(e)}"
|
||||
|
|
@ -67,7 +67,8 @@ class PfcEmotionUpdater:
|
|||
|
||||
current_mood_text_from_manager = self.mood_mng.current_mood.text # 从 MoodManager 获取当前情绪文本
|
||||
sender_name_for_prompt = getattr(observation_info, 'sender_name', '对方')
|
||||
if not sender_name_for_prompt: sender_name_for_prompt = '对方'
|
||||
if not sender_name_for_prompt:
|
||||
sender_name_for_prompt = '对方'
|
||||
relationship_text_for_prompt = getattr(conversation_info, 'relationship_text', '关系一般。') # 从 ConversationInfo 获取关系文本
|
||||
|
||||
emotion_prompt = f"""你是{self.bot_name}。你现在的心情是【{current_mood_text_from_manager}】。
|
||||
|
|
|
|||
|
|
@ -141,7 +141,8 @@ def get_items_from_json(
|
|||
valid_item = False
|
||||
break # 这个元素无效
|
||||
|
||||
if not valid_item: continue
|
||||
if not valid_item:
|
||||
continue
|
||||
|
||||
# 验证类型
|
||||
if required_types:
|
||||
|
|
@ -152,7 +153,8 @@ def get_items_from_json(
|
|||
valid_item = False
|
||||
break
|
||||
|
||||
if not valid_item: continue
|
||||
if not valid_item:
|
||||
continue
|
||||
|
||||
# 验证字符串不为空 (只检查 items 中要求的字段)
|
||||
for field in items:
|
||||
|
|
|
|||
|
|
@ -1,13 +1,7 @@
|
|||
|
||||
import json
|
||||
from typing import Tuple, List, Dict, Any
|
||||
from src.common.logger import get_module_logger
|
||||
# LLMRequest 和 global_config 不再需要直接在此文件中使用(除非 ReplyChecker 以后有其他功能)
|
||||
# from ..models.utils_model import LLMRequest # <--- 移除
|
||||
# from ...config.config import global_config # <--- 移除,但下面会用到 bot_id
|
||||
from ...config.config import global_config # 为了获取 BOT_QQ
|
||||
from src.config.config import global_config # 为了获取 BOT_QQ
|
||||
from .chat_observer import ChatObserver
|
||||
from maim_message import UserInfo # 保持,可能用于未来扩展,但当前逻辑不直接使用
|
||||
|
||||
logger = get_module_logger("reply_checker")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,6 @@
|
|||
import random
|
||||
from .pfc_utils import retrieve_contextual_info
|
||||
|
||||
# 可能用于旧知识库提取主题 (如果需要回退到旧方法)
|
||||
# import jieba # 如果报错说找不到 jieba,可能需要安装: pip install jieba
|
||||
# import re # 正则表达式库,通常 Python 自带
|
||||
from typing import Tuple, List, Dict, Any
|
||||
|
||||
# from src.common.logger import get_module_logger
|
||||
from src.common.logger_manager import get_logger
|
||||
from ..models.utils_model import LLMRequest
|
||||
from ...config.config import global_config
|
||||
|
|
@ -227,15 +221,16 @@ class ReplyGenerator:
|
|||
chat_history_text = "还没有聊天记录。"
|
||||
else:
|
||||
chat_history_text += (
|
||||
f"\n--- 以上均为已读消息,未读消息均已处理完毕 ---\n"
|
||||
"\n--- 以上均为已读消息,未读消息均已处理完毕 ---\n"
|
||||
)
|
||||
|
||||
sender_name_str = getattr(observation_info, 'sender_name', '对方')
|
||||
if not sender_name_str: sender_name_str = '对方'
|
||||
if not sender_name_str:
|
||||
sender_name_str = '对方'
|
||||
|
||||
relationship_text_str = getattr(conversation_info, 'relationship_text', '你们还不熟悉。')
|
||||
current_emotion_text_str = getattr(conversation_info, 'current_emotion_text', '心情平静。')
|
||||
|
||||
|
||||
persona_text = f"你的名字是{self.name},{self.personality_info}。"
|
||||
retrieval_context = chat_history_text
|
||||
retrieved_memory_str, retrieved_knowledge_str = await retrieve_contextual_info(
|
||||
|
|
|
|||
Loading…
Reference in New Issue