feat: 现在使用工具调用来更新关系和心情而不是固定更新
This commit is contained in:
@@ -18,7 +18,6 @@ import random
|
||||
from src.plugins.chat.chat_stream import ChatStream
|
||||
from src.plugins.person_info.relationship_manager import relationship_manager
|
||||
from src.plugins.chat.utils import get_recent_group_speaker
|
||||
from src.do_tool.tool_use import ToolUser
|
||||
from ..plugins.utils.prompt_builder import Prompt, global_prompt_manager
|
||||
|
||||
subheartflow_config = LogConfig(
|
||||
@@ -32,7 +31,7 @@ logger = get_module_logger("subheartflow", config=subheartflow_config)
|
||||
def init_prompt():
|
||||
prompt = ""
|
||||
# prompt += f"麦麦的总体想法是:{self.main_heartflow_info}\n\n"
|
||||
prompt += "{collected_info}\n"
|
||||
prompt += "{extra_info}\n"
|
||||
prompt += "{relation_prompt_all}\n"
|
||||
prompt += "{prompt_personality}\n"
|
||||
prompt += "刚刚你的想法是{current_thinking_info}。如果有新的内容,记得转换话题\n"
|
||||
@@ -47,6 +46,7 @@ def init_prompt():
|
||||
Prompt(prompt, "sub_heartflow_prompt_before")
|
||||
prompt = ""
|
||||
# prompt += f"你现在正在做的事情是:{schedule_info}\n"
|
||||
prompt += "{extra_info}\n"
|
||||
prompt += "{prompt_personality}\n"
|
||||
prompt += "现在你正在上网,和qq群里的网友们聊天,群里正在聊的话题是:{chat_observe_info}\n"
|
||||
prompt += "刚刚你的想法是{current_thinking_info}。"
|
||||
@@ -97,7 +97,7 @@ class SubHeartflow:
|
||||
|
||||
self.bot_name = global_config.BOT_NICKNAME
|
||||
|
||||
self.tool_user = ToolUser()
|
||||
|
||||
|
||||
def add_observation(self, observation: Observation):
|
||||
"""添加一个新的observation对象到列表中,如果已存在相同id的observation则不添加"""
|
||||
@@ -151,25 +151,14 @@ class SubHeartflow:
|
||||
observation = self.observations[0]
|
||||
await observation.observe()
|
||||
|
||||
async def do_thinking_before_reply(self, message_txt: str, sender_name: str, chat_stream: ChatStream):
|
||||
async def do_thinking_before_reply(self, message_txt: str, sender_name: str, chat_stream: ChatStream, extra_info: str):
|
||||
current_thinking_info = self.current_mind
|
||||
mood_info = self.current_state.mood
|
||||
# mood_info = "你很生气,很愤怒"
|
||||
observation = self.observations[0]
|
||||
chat_observe_info = observation.observe_info
|
||||
# print(f"chat_observe_info:{chat_observe_info}")
|
||||
|
||||
# 首先尝试使用工具获取更多信息
|
||||
tool_result = await self.tool_user.use_tool(message_txt, sender_name, chat_stream)
|
||||
|
||||
# 如果工具被使用且获得了结果,将收集到的信息合并到思考中
|
||||
collected_info = ""
|
||||
if tool_result.get("used_tools", False):
|
||||
logger.info("使用工具收集了信息")
|
||||
|
||||
# 如果有收集到的信息,将其添加到当前思考中
|
||||
if "collected_info" in tool_result:
|
||||
collected_info = tool_result["collected_info"]
|
||||
|
||||
# 开始构建prompt
|
||||
prompt_personality = f"你的名字是{self.bot_name},你"
|
||||
@@ -226,7 +215,7 @@ class SubHeartflow:
|
||||
# prompt += f"记得结合上述的消息,生成内心想法,文字不要浮夸,注意你就是{self.bot_name},{self.bot_name}指的就是你。"
|
||||
|
||||
prompt = (await global_prompt_manager.get_prompt_async("sub_heartflow_prompt_before")).format(
|
||||
collected_info,
|
||||
extra_info,
|
||||
relation_prompt_all,
|
||||
prompt_personality,
|
||||
current_thinking_info,
|
||||
@@ -250,7 +239,7 @@ class SubHeartflow:
|
||||
logger.info(f"麦麦的思考前脑内状态:{self.current_mind}")
|
||||
return self.current_mind, self.past_mind
|
||||
|
||||
async def do_thinking_after_reply(self, reply_content, chat_talking_prompt):
|
||||
async def do_thinking_after_reply(self, reply_content, chat_talking_prompt, extra_info):
|
||||
# print("麦麦回复之后脑袋转起来了")
|
||||
|
||||
# 开始构建prompt
|
||||
@@ -277,20 +266,15 @@ class SubHeartflow:
|
||||
|
||||
message_new_info = chat_talking_prompt
|
||||
reply_info = reply_content
|
||||
# schedule_info = bot_schedule.get_current_num_task(num=1, time_info=False)
|
||||
|
||||
# prompt = ""
|
||||
# # prompt += f"你现在正在做的事情是:{schedule_info}\n"
|
||||
# prompt += f"{prompt_personality}\n"
|
||||
# prompt += f"现在你正在上网,和qq群里的网友们聊天,群里正在聊的话题是:{chat_observe_info}\n"
|
||||
# prompt += f"刚刚你的想法是{current_thinking_info}。"
|
||||
# prompt += f"你现在看到了网友们发的新消息:{message_new_info}\n"
|
||||
# prompt += f"你刚刚回复了群友们:{reply_info}"
|
||||
# prompt += f"你现在{mood_info}"
|
||||
# prompt += "现在你接下去继续思考,产生新的想法,记得保留你刚刚的想法,不要分点输出,输出连贯的内心独白"
|
||||
# prompt += "不要太长,但是记得结合上述的消息,要记得你的人设,关注聊天和新内容,关注你回复的内容,不要思考太多:"
|
||||
prompt = (await global_prompt_manager.get_prompt_async("sub_heartflow_prompt_after")).format(
|
||||
prompt_personality, chat_observe_info, current_thinking_info, message_new_info, reply_info, mood_info
|
||||
extra_info,
|
||||
prompt_personality,
|
||||
chat_observe_info,
|
||||
current_thinking_info,
|
||||
message_new_info,
|
||||
reply_info,
|
||||
mood_info,
|
||||
)
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user