增加私聊名称参数
This commit is contained in:
@@ -86,7 +86,7 @@ block_and_ignore: 更加极端的结束对话方式,直接结束对话并在
|
|||||||
class ActionPlanner:
|
class ActionPlanner:
|
||||||
"""行动规划器"""
|
"""行动规划器"""
|
||||||
|
|
||||||
def __init__(self, stream_id: str):
|
def __init__(self, stream_id: str, private_name: str):
|
||||||
self.llm = LLMRequest(
|
self.llm = LLMRequest(
|
||||||
model=global_config.llm_PFC_action_planner,
|
model=global_config.llm_PFC_action_planner,
|
||||||
temperature=global_config.llm_PFC_action_planner["temp"],
|
temperature=global_config.llm_PFC_action_planner["temp"],
|
||||||
@@ -96,6 +96,7 @@ class ActionPlanner:
|
|||||||
self.personality_info = Individuality.get_instance().get_prompt(type="personality", x_person=2, level=3)
|
self.personality_info = Individuality.get_instance().get_prompt(type="personality", x_person=2, level=3)
|
||||||
self.identity_detail_info = Individuality.get_instance().get_prompt(type="identity", x_person=2, level=2)
|
self.identity_detail_info = Individuality.get_instance().get_prompt(type="identity", x_person=2, level=2)
|
||||||
self.name = global_config.BOT_NICKNAME
|
self.name = global_config.BOT_NICKNAME
|
||||||
|
self.private_name = private_name
|
||||||
self.chat_observer = ChatObserver.get_instance(stream_id)
|
self.chat_observer = ChatObserver.get_instance(stream_id)
|
||||||
# self.action_planner_info = ActionPlannerInfo() # 移除未使用的变量
|
# self.action_planner_info = ActionPlannerInfo() # 移除未使用的变量
|
||||||
|
|
||||||
|
|||||||
@@ -29,13 +29,14 @@ logger = get_logger("pfc")
|
|||||||
class Conversation:
|
class Conversation:
|
||||||
"""对话类,负责管理单个对话的状态和行为"""
|
"""对话类,负责管理单个对话的状态和行为"""
|
||||||
|
|
||||||
def __init__(self, stream_id: str):
|
def __init__(self, stream_id: str, private_name: str):
|
||||||
"""初始化对话实例
|
"""初始化对话实例
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
stream_id: 聊天流ID
|
stream_id: 聊天流ID
|
||||||
"""
|
"""
|
||||||
self.stream_id = stream_id
|
self.stream_id = stream_id
|
||||||
|
self.private_name = private_name
|
||||||
self.state = ConversationState.INIT
|
self.state = ConversationState.INIT
|
||||||
self.should_continue = False
|
self.should_continue = False
|
||||||
self.ignore_until_timestamp: Optional[float] = None
|
self.ignore_until_timestamp: Optional[float] = None
|
||||||
@@ -47,11 +48,11 @@ class Conversation:
|
|||||||
"""初始化实例,注册所有组件"""
|
"""初始化实例,注册所有组件"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.action_planner = ActionPlanner(self.stream_id)
|
self.action_planner = ActionPlanner(self.stream_id, self.private_name)
|
||||||
self.goal_analyzer = GoalAnalyzer(self.stream_id)
|
self.goal_analyzer = GoalAnalyzer(self.stream_id, self.private_name)
|
||||||
self.reply_generator = ReplyGenerator(self.stream_id)
|
self.reply_generator = ReplyGenerator(self.stream_id, self.private_name)
|
||||||
self.knowledge_fetcher = KnowledgeFetcher()
|
self.knowledge_fetcher = KnowledgeFetcher()
|
||||||
self.waiter = Waiter(self.stream_id)
|
self.waiter = Waiter(self.stream_id, self.private_name)
|
||||||
self.direct_sender = DirectMessageSender()
|
self.direct_sender = DirectMessageSender()
|
||||||
|
|
||||||
# 获取聊天流信息
|
# 获取聊天流信息
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ logger = get_module_logger("pfc")
|
|||||||
class GoalAnalyzer:
|
class GoalAnalyzer:
|
||||||
"""对话目标分析器"""
|
"""对话目标分析器"""
|
||||||
|
|
||||||
def __init__(self, stream_id: str):
|
def __init__(self, stream_id: str, private_name: str):
|
||||||
self.llm = LLMRequest(
|
self.llm = LLMRequest(
|
||||||
model=global_config.llm_normal, temperature=0.7, max_tokens=1000, request_type="conversation_goal"
|
model=global_config.llm_normal, temperature=0.7, max_tokens=1000, request_type="conversation_goal"
|
||||||
)
|
)
|
||||||
@@ -39,6 +39,7 @@ class GoalAnalyzer:
|
|||||||
self.identity_detail_info = Individuality.get_instance().get_prompt(type="identity", x_person=2, level=2)
|
self.identity_detail_info = Individuality.get_instance().get_prompt(type="identity", x_person=2, level=2)
|
||||||
self.name = global_config.BOT_NICKNAME
|
self.name = global_config.BOT_NICKNAME
|
||||||
self.nick_name = global_config.BOT_ALIAS_NAMES
|
self.nick_name = global_config.BOT_ALIAS_NAMES
|
||||||
|
self.private_name = private_name
|
||||||
self.chat_observer = ChatObserver.get_instance(stream_id)
|
self.chat_observer = ChatObserver.get_instance(stream_id)
|
||||||
|
|
||||||
# 多目标存储结构
|
# 多目标存储结构
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class PFCManager:
|
|||||||
cls._instance = PFCManager()
|
cls._instance = PFCManager()
|
||||||
return cls._instance
|
return cls._instance
|
||||||
|
|
||||||
async def get_or_create_conversation(self, stream_id: str) -> Optional[Conversation]:
|
async def get_or_create_conversation(self, stream_id: str, private_name: str) -> Optional[Conversation]:
|
||||||
"""获取或创建对话实例
|
"""获取或创建对话实例
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -67,7 +67,7 @@ class PFCManager:
|
|||||||
logger.info(f"创建新的对话实例: {stream_id}")
|
logger.info(f"创建新的对话实例: {stream_id}")
|
||||||
self._initializing[stream_id] = True
|
self._initializing[stream_id] = True
|
||||||
# 创建实例
|
# 创建实例
|
||||||
conversation_instance = Conversation(stream_id)
|
conversation_instance = Conversation(stream_id, private_name)
|
||||||
self._instances[stream_id] = conversation_instance
|
self._instances[stream_id] = conversation_instance
|
||||||
|
|
||||||
# 启动实例初始化
|
# 启动实例初始化
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ PROMPT_SEND_NEW_MESSAGE = """{persona_text}。现在你在参与一场QQ私聊
|
|||||||
class ReplyGenerator:
|
class ReplyGenerator:
|
||||||
"""回复生成器"""
|
"""回复生成器"""
|
||||||
|
|
||||||
def __init__(self, stream_id: str):
|
def __init__(self, stream_id: str, private_name: str):
|
||||||
self.llm = LLMRequest(
|
self.llm = LLMRequest(
|
||||||
model=global_config.llm_PFC_chat,
|
model=global_config.llm_PFC_chat,
|
||||||
temperature=global_config.llm_PFC_chat["temp"],
|
temperature=global_config.llm_PFC_chat["temp"],
|
||||||
@@ -71,6 +71,7 @@ class ReplyGenerator:
|
|||||||
self.personality_info = Individuality.get_instance().get_prompt(type="personality", x_person=2, level=3)
|
self.personality_info = Individuality.get_instance().get_prompt(type="personality", x_person=2, level=3)
|
||||||
self.identity_detail_info = Individuality.get_instance().get_prompt(type="identity", x_person=2, level=2)
|
self.identity_detail_info = Individuality.get_instance().get_prompt(type="identity", x_person=2, level=2)
|
||||||
self.name = global_config.BOT_NICKNAME
|
self.name = global_config.BOT_NICKNAME
|
||||||
|
self.private_name = private_name
|
||||||
self.chat_observer = ChatObserver.get_instance(stream_id)
|
self.chat_observer = ChatObserver.get_instance(stream_id)
|
||||||
self.reply_checker = ReplyChecker(stream_id)
|
self.reply_checker = ReplyChecker(stream_id)
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ DESIRED_TIMEOUT_SECONDS = 300
|
|||||||
class Waiter:
|
class Waiter:
|
||||||
"""等待处理类"""
|
"""等待处理类"""
|
||||||
|
|
||||||
def __init__(self, stream_id: str):
|
def __init__(self, stream_id: str, private_name: str):
|
||||||
self.chat_observer = ChatObserver.get_instance(stream_id)
|
self.chat_observer = ChatObserver.get_instance(stream_id)
|
||||||
self.name = global_config.BOT_NICKNAME
|
self.name = global_config.BOT_NICKNAME
|
||||||
|
self.private_name = private_name
|
||||||
# self.wait_accumulated_time = 0 # 不再需要累加计时
|
# self.wait_accumulated_time = 0 # 不再需要累加计时
|
||||||
|
|
||||||
async def wait(self, conversation_info: ConversationInfo) -> bool:
|
async def wait(self, conversation_info: ConversationInfo) -> bool:
|
||||||
|
|||||||
@@ -38,9 +38,10 @@ class ChatBot:
|
|||||||
async def _create_pfc_chat(self, message: MessageRecv):
|
async def _create_pfc_chat(self, message: MessageRecv):
|
||||||
try:
|
try:
|
||||||
chat_id = str(message.chat_stream.stream_id)
|
chat_id = str(message.chat_stream.stream_id)
|
||||||
|
private_name = str(message.message_info.user_info.user_nickname)
|
||||||
|
|
||||||
if global_config.enable_pfc_chatting:
|
if global_config.enable_pfc_chatting:
|
||||||
await self.pfc_manager.get_or_create_conversation(chat_id)
|
await self.pfc_manager.get_or_create_conversation(chat_id, private_name)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"创建PFC聊天失败: {e}")
|
logger.error(f"创建PFC聊天失败: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user