dev:修复记忆构建文本名称问题
This commit is contained in:
@@ -8,7 +8,7 @@ from src.individuality.individuality import Individuality
|
||||
import random
|
||||
from ..plugins.utils.prompt_builder import Prompt, global_prompt_manager
|
||||
from src.do_tool.tool_use import ToolUser
|
||||
from src.plugins.utils.json_utils import safe_json_dumps, normalize_llm_response, process_llm_tool_calls
|
||||
from src.plugins.utils.json_utils import safe_json_dumps, process_llm_tool_calls
|
||||
from src.heart_flow.chat_state_info import ChatStateInfo
|
||||
from src.plugins.chat.chat_stream import chat_manager
|
||||
from src.plugins.heartFC_chat.heartFC_Cycleinfo import CycleInfo
|
||||
@@ -20,14 +20,12 @@ logger = get_logger("sub_heartflow")
|
||||
def init_prompt():
|
||||
prompt = ""
|
||||
prompt += "{extra_info}\n"
|
||||
prompt += "{prompt_personality}\n"
|
||||
prompt += "你的名字是{bot_name},{prompt_personality}\n"
|
||||
prompt += "{last_loop_prompt}\n"
|
||||
prompt += "{cycle_info_block}\n"
|
||||
prompt += "现在是{time_now},你正在上网,和qq群里的网友们聊天,以下是正在进行的聊天内容:\n{chat_observe_info}\n"
|
||||
prompt += "\n你现在{mood_info}\n"
|
||||
prompt += (
|
||||
"请仔细阅读当前群聊内容,分析讨论话题和群成员关系,分析你刚刚发言和别人对你的发言的反应,思考你要不要回复。"
|
||||
)
|
||||
prompt += "请仔细阅读当前群聊内容,分析讨论话题和群成员关系,分析你刚刚发言和别人对你的发言的反应,思考你要不要回复。然后思考你是否需要使用函数工具。"
|
||||
prompt += "思考并输出你的内心想法\n"
|
||||
prompt += "输出要求:\n"
|
||||
prompt += "1. 根据聊天内容生成你的想法,{hf_do_next}\n"
|
||||
@@ -66,7 +64,7 @@ class SubMind:
|
||||
self.current_mind = ""
|
||||
self.past_mind = []
|
||||
self.structured_info = {}
|
||||
|
||||
|
||||
name = chat_manager.get_stream_name(self.subheartflow_id)
|
||||
self.log_prefix = f"[{name}] "
|
||||
|
||||
@@ -80,8 +78,6 @@ class SubMind:
|
||||
# 更新活跃时间
|
||||
self.last_active_time = time.time()
|
||||
|
||||
|
||||
|
||||
# ---------- 1. 准备基础数据 ----------
|
||||
# 获取现有想法和情绪状态
|
||||
current_thinking_info = self.current_mind
|
||||
@@ -106,18 +102,7 @@ class SubMind:
|
||||
individuality = Individuality.get_instance()
|
||||
|
||||
# 构建个性部分
|
||||
prompt_personality = f"你正在扮演名为{individuality.personality.bot_nickname}的人类,你"
|
||||
prompt_personality += individuality.personality.personality_core
|
||||
|
||||
# 随机添加个性侧面
|
||||
if individuality.personality.personality_sides:
|
||||
random_side = random.choice(individuality.personality.personality_sides)
|
||||
prompt_personality += f",{random_side}"
|
||||
|
||||
# 随机添加身份细节
|
||||
if individuality.identity.identity_detail:
|
||||
random_detail = random.choice(individuality.identity.identity_detail)
|
||||
prompt_personality += f",{random_detail}"
|
||||
prompt_personality = individuality.get_prompt(x_person=2, level=2)
|
||||
|
||||
# 获取当前时间
|
||||
time_now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||
@@ -211,7 +196,7 @@ class SubMind:
|
||||
prompt = (await global_prompt_manager.get_prompt_async("sub_heartflow_prompt_before")).format(
|
||||
extra_info="", # 可以在这里添加额外信息
|
||||
prompt_personality=prompt_personality,
|
||||
bot_name=individuality.personality.bot_nickname,
|
||||
bot_name=individuality.name,
|
||||
time_now=time_now,
|
||||
chat_observe_info=chat_observe_info,
|
||||
mood_info=mood_info,
|
||||
@@ -228,34 +213,34 @@ class SubMind:
|
||||
|
||||
try:
|
||||
# 调用LLM生成响应
|
||||
response, _reasoning_content, tool_calls = await self.llm_model.generate_response_tool_async(prompt=prompt, tools=tools)
|
||||
response, _reasoning_content, tool_calls = await self.llm_model.generate_response_tool_async(
|
||||
prompt=prompt, tools=tools
|
||||
)
|
||||
|
||||
logger.debug(f"{self.log_prefix} 子心流输出的原始LLM响应: {response}")
|
||||
|
||||
|
||||
# 直接使用LLM返回的文本响应作为 content
|
||||
content = response if response else ""
|
||||
|
||||
if tool_calls:
|
||||
# 直接将 tool_calls 传递给处理函数
|
||||
success, valid_tool_calls, error_msg = process_llm_tool_calls(
|
||||
tool_calls, log_prefix=f"{self.log_prefix} "
|
||||
tool_calls, log_prefix=f"{self.log_prefix} "
|
||||
)
|
||||
|
||||
|
||||
if success and valid_tool_calls:
|
||||
# 记录工具调用信息
|
||||
tool_calls_str = ", ".join(
|
||||
[call.get("function", {}).get("name", "未知工具") for call in valid_tool_calls]
|
||||
)
|
||||
logger.info(
|
||||
f"{self.log_prefix} 模型请求调用{len(valid_tool_calls)}个工具: {tool_calls_str}"
|
||||
)
|
||||
logger.info(f"{self.log_prefix} 模型请求调用{len(valid_tool_calls)}个工具: {tool_calls_str}")
|
||||
|
||||
# 收集工具执行结果
|
||||
await self._execute_tool_calls(valid_tool_calls, tool_instance)
|
||||
elif not success:
|
||||
logger.warning(f"{self.log_prefix} 处理工具调用时出错: {error_msg}")
|
||||
else:
|
||||
logger.info(f"{self.log_prefix} 心流未使用工具") # 修改日志信息,明确是未使用工具而不是未处理
|
||||
logger.info(f"{self.log_prefix} 心流未使用工具") # 修改日志信息,明确是未使用工具而不是未处理
|
||||
|
||||
except Exception as e:
|
||||
# 处理总体异常
|
||||
|
||||
Reference in New Issue
Block a user