Merge branch 'dev' of https://github.com/MaiM-with-u/MaiBot into dev
This commit is contained in:
@@ -5,8 +5,6 @@ from src.chat.focus_chat.info.info_base import InfoBase
|
||||
from .base_processor import BaseProcessor
|
||||
from src.common.logger import get_logger
|
||||
from src.chat.heart_flow.observation.chatting_observation import ChattingObservation
|
||||
from src.chat.heart_flow.observation.hfcloop_observation import HFCloopObservation
|
||||
from src.chat.focus_chat.info.cycle_info import CycleInfo
|
||||
from datetime import datetime
|
||||
from src.llm_models.utils_model import LLMRequest
|
||||
from src.config.config import global_config
|
||||
@@ -55,13 +53,8 @@ class ChattingInfoProcessor(BaseProcessor):
|
||||
for obs in observations:
|
||||
# print(f"obs: {obs}")
|
||||
if isinstance(obs, ChattingObservation):
|
||||
# print("1111111111111111111111读取111111111111111")
|
||||
|
||||
obs_info = ObsInfo()
|
||||
|
||||
# 改为异步任务,不阻塞主流程
|
||||
# asyncio.create_task(self.chat_compress(obs))
|
||||
|
||||
# 设置聊天ID
|
||||
if hasattr(obs, "chat_id"):
|
||||
obs_info.set_chat_id(obs.chat_id)
|
||||
@@ -101,10 +94,6 @@ class ChattingInfoProcessor(BaseProcessor):
|
||||
# logger.debug(f"聊天信息处理器处理后的信息: {obs_info}")
|
||||
|
||||
processed_infos.append(obs_info)
|
||||
if isinstance(obs, HFCloopObservation):
|
||||
obs_info = CycleInfo()
|
||||
obs_info.set_observe_info(obs.observe_info)
|
||||
processed_infos.append(obs_info)
|
||||
|
||||
return processed_infos
|
||||
|
||||
|
||||
@@ -131,11 +131,15 @@ def init_prompt():
|
||||
1.你需要提供用户名和你想要提取的信息名称类型来进行调取
|
||||
2.请注意,提取的信息类型一定要和用户有关,不要提取无关的信息
|
||||
3.你也可以调取有关自己({bot_name})的信息
|
||||
4.如果当前聊天记录中没有需要查询的信息,或者现有信息已经足够回复,请返回{{"none": "不需要查询"}}
|
||||
|
||||
请以json格式输出,例如:
|
||||
|
||||
{example_json}
|
||||
|
||||
如果不需要查询任何信息,请输出:
|
||||
{{"none": "不需要查询"}}
|
||||
|
||||
请严格按照json输出格式,不要输出多余内容,可以同时查询多个人的信息:
|
||||
|
||||
"""
|
||||
@@ -649,48 +653,55 @@ class PersonImpressionpProcessor(BaseProcessor):
|
||||
# print(f"content: {content}")
|
||||
content_json = json.loads(repair_json(content))
|
||||
|
||||
# 收集即时提取任务
|
||||
instant_tasks = []
|
||||
async_tasks = []
|
||||
|
||||
person_info_manager = get_person_info_manager()
|
||||
for person_name, info_type in content_json.items():
|
||||
is_bot = person_name == global_config.bot.nickname or person_name in global_config.bot.alias_names
|
||||
if is_bot:
|
||||
person_id = person_info_manager.get_person_id("system", "bot_id")
|
||||
logger.info(f"{self.log_prefix} 检测到对bot自身({person_name})的信息查询,使用特殊ID。")
|
||||
else:
|
||||
person_id = person_info_manager.get_person_id_by_person_name(person_name)
|
||||
|
||||
if not person_id:
|
||||
logger.warning(f"{self.log_prefix} 未找到用户 {person_name} 的ID,跳过调取信息。")
|
||||
continue
|
||||
|
||||
self.info_fetching_cache.append(
|
||||
{
|
||||
"person_id": person_id,
|
||||
"person_name": person_name,
|
||||
"info_type": info_type,
|
||||
"start_time": time.time(),
|
||||
"forget": False,
|
||||
}
|
||||
)
|
||||
if len(self.info_fetching_cache) > 20:
|
||||
self.info_fetching_cache.pop(0)
|
||||
|
||||
logger.info(f"{self.log_prefix} 调取用户 {person_name} 的 {info_type} 信息。")
|
||||
|
||||
# 检查是否返回了不需要查询的标志
|
||||
if "none" in content_json:
|
||||
logger.info(f"{self.log_prefix} LLM判断当前不需要查询任何信息:{content_json.get('none', '')}")
|
||||
# 跳过新的信息提取,但仍会处理已有缓存
|
||||
else:
|
||||
# 收集即时提取任务
|
||||
instant_tasks.append((person_id, info_type, time.time()))
|
||||
instant_tasks = []
|
||||
async_tasks = []
|
||||
|
||||
# 执行即时提取任务
|
||||
if instant_tasks:
|
||||
await self._execute_instant_extraction_batch(instant_tasks)
|
||||
person_info_manager = get_person_info_manager()
|
||||
for person_name, info_type in content_json.items():
|
||||
is_bot = (
|
||||
person_name == global_config.bot.nickname or person_name in global_config.bot.alias_names
|
||||
)
|
||||
if is_bot:
|
||||
person_id = person_info_manager.get_person_id("system", "bot_id")
|
||||
logger.info(f"{self.log_prefix} 检测到对bot自身({person_name})的信息查询,使用特殊ID。")
|
||||
else:
|
||||
person_id = person_info_manager.get_person_id_by_person_name(person_name)
|
||||
|
||||
# 启动异步任务(如果不是即时模式)
|
||||
if async_tasks:
|
||||
# 异步任务不需要等待完成
|
||||
pass
|
||||
if not person_id:
|
||||
logger.warning(f"{self.log_prefix} 未找到用户 {person_name} 的ID,跳过调取信息。")
|
||||
continue
|
||||
|
||||
self.info_fetching_cache.append(
|
||||
{
|
||||
"person_id": person_id,
|
||||
"person_name": person_name,
|
||||
"info_type": info_type,
|
||||
"start_time": time.time(),
|
||||
"forget": False,
|
||||
}
|
||||
)
|
||||
if len(self.info_fetching_cache) > 20:
|
||||
self.info_fetching_cache.pop(0)
|
||||
|
||||
logger.info(f"{self.log_prefix} 调取用户 {person_name} 的 {info_type} 信息。")
|
||||
|
||||
# 收集即时提取任务
|
||||
instant_tasks.append((person_id, info_type, time.time()))
|
||||
|
||||
# 执行即时提取任务
|
||||
if instant_tasks:
|
||||
await self._execute_instant_extraction_batch(instant_tasks)
|
||||
|
||||
# 启动异步任务(如果不是即时模式)
|
||||
if async_tasks:
|
||||
# 异步任务不需要等待完成
|
||||
pass
|
||||
|
||||
else:
|
||||
logger.warning(f"{self.log_prefix} LLM返回空结果,关系识别失败。")
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from src.chat.heart_flow.observation.chatting_observation import ChattingObservation
|
||||
from src.chat.heart_flow.observation.structure_observation import StructureObservation
|
||||
from src.chat.heart_flow.observation.hfcloop_observation import HFCloopObservation
|
||||
from src.llm_models.utils_model import LLMRequest
|
||||
from src.config.config import global_config
|
||||
from src.common.logger import get_logger
|
||||
@@ -99,10 +98,8 @@ class MemoryActivator:
|
||||
working_info = observation.get_observe_info()
|
||||
for working_info_item in working_info:
|
||||
obs_info_text += f"{working_info_item['type']}: {working_info_item['content']}\n"
|
||||
elif isinstance(observation, HFCloopObservation):
|
||||
obs_info_text += observation.get_observe_info()
|
||||
|
||||
# logger.debug(f"回忆待检索内容:obs_info_text: {obs_info_text}")
|
||||
logger.info(f"回忆待检索内容:obs_info_text: {obs_info_text}")
|
||||
|
||||
# 将缓存的关键词转换为字符串,用于prompt
|
||||
cached_keywords_str = ", ".join(self.cached_keywords) if self.cached_keywords else "暂无历史关键词"
|
||||
@@ -129,7 +126,7 @@ class MemoryActivator:
|
||||
|
||||
# 添加新的关键词到缓存
|
||||
self.cached_keywords.update(keywords)
|
||||
logger.debug(f"当前激活的记忆关键词: {self.cached_keywords}")
|
||||
logger.info(f"当前激活的记忆关键词: {self.cached_keywords}")
|
||||
|
||||
# 调用记忆系统获取相关记忆
|
||||
related_memory = await hippocampus_manager.get_memory_from_topic(
|
||||
@@ -139,7 +136,7 @@ class MemoryActivator:
|
||||
# text=obs_info_text, max_memory_num=5, max_memory_length=2, max_depth=3, fast_retrieval=False
|
||||
# )
|
||||
|
||||
# logger.debug(f"获取到的记忆: {related_memory}")
|
||||
logger.info(f"获取到的记忆: {related_memory}")
|
||||
|
||||
# 激活时,所有已有记忆的duration+1,达到3则移除
|
||||
for m in self.running_memory[:]:
|
||||
|
||||
@@ -79,9 +79,6 @@ class ActionModifier:
|
||||
obs = hfc_obs
|
||||
# 获取适用于FOCUS模式的动作
|
||||
all_actions = self.action_manager.get_using_actions_for_mode("focus")
|
||||
# print("=======================")
|
||||
# print(all_actions)
|
||||
# print("=======================")
|
||||
action_changes = await self.analyze_loop_actions(obs)
|
||||
if action_changes["add"] or action_changes["remove"]:
|
||||
# 合并动作变更
|
||||
|
||||
@@ -6,7 +6,6 @@ from src.llm_models.utils_model import LLMRequest
|
||||
from src.config.config import global_config
|
||||
from src.chat.focus_chat.info.info_base import InfoBase
|
||||
from src.chat.focus_chat.info.obs_info import ObsInfo
|
||||
from src.chat.focus_chat.info.cycle_info import CycleInfo
|
||||
from src.chat.focus_chat.info.action_info import ActionInfo
|
||||
from src.chat.focus_chat.info.structured_info import StructuredInfo
|
||||
from src.chat.focus_chat.info.relation_info import RelationInfo
|
||||
@@ -32,7 +31,6 @@ def init_prompt():
|
||||
你现在需要根据聊天内容,选择的合适的action来参与聊天。
|
||||
{chat_context_description},以下是具体的聊天内容:
|
||||
{chat_content_block}
|
||||
{cycle_info_block}
|
||||
{moderation_prompt}
|
||||
现在请你根据聊天内容选择合适的action:
|
||||
|
||||
@@ -51,7 +49,6 @@ def init_prompt():
|
||||
{chat_context_description},以下是具体的聊天内容:
|
||||
{chat_content_block}
|
||||
{relation_info_block}
|
||||
{cycle_info_block}
|
||||
{moderation_prompt}
|
||||
现在请你选择合适的action:
|
||||
|
||||
@@ -62,19 +59,6 @@ def init_prompt():
|
||||
"simple_planner_prompt_private",
|
||||
)
|
||||
|
||||
# Prompt(
|
||||
# """
|
||||
# 动作:{action_name}
|
||||
# 该动作的描述:{action_description}
|
||||
# 使用该动作的场景:
|
||||
# {action_require}
|
||||
# 输出要求:
|
||||
# {{
|
||||
# "action": "{action_name}",{action_parameters}
|
||||
# }}
|
||||
# """,
|
||||
# "action_prompt",
|
||||
# )
|
||||
Prompt(
|
||||
"""
|
||||
{action_require}
|
||||
@@ -130,7 +114,6 @@ class ActionPlanner(BasePlanner):
|
||||
# 获取观察信息
|
||||
extra_info: list[str] = []
|
||||
|
||||
cycle_info = ""
|
||||
structured_info = ""
|
||||
extra_info = []
|
||||
observed_messages = []
|
||||
@@ -149,8 +132,8 @@ class ActionPlanner(BasePlanner):
|
||||
is_group_chat = chat_type == "group"
|
||||
# 从ObsInfo中获取chat_id
|
||||
chat_id = info.get_chat_id()
|
||||
elif isinstance(info, CycleInfo):
|
||||
cycle_info = info.get_observe_info()
|
||||
# elif isinstance(info, CycleInfo):
|
||||
# cycle_info = info.get_observe_info()
|
||||
elif isinstance(info, RelationInfo):
|
||||
relation_info = info.get_processed_info()
|
||||
elif isinstance(info, StructuredInfo):
|
||||
@@ -214,7 +197,7 @@ class ActionPlanner(BasePlanner):
|
||||
observed_messages_str=observed_messages_str, # <-- Pass local variable
|
||||
structured_info=structured_info, # <-- Pass SubMind info
|
||||
current_available_actions=current_available_actions, # <-- Pass determined actions
|
||||
cycle_info=cycle_info, # <-- Pass cycle info
|
||||
# cycle_info=cycle_info, # <-- Pass cycle info
|
||||
extra_info=extra_info,
|
||||
running_memorys=running_memorys,
|
||||
)
|
||||
@@ -290,6 +273,14 @@ class ActionPlanner(BasePlanner):
|
||||
|
||||
action_data["loop_start_time"] = loop_start_time
|
||||
|
||||
memory_str = ""
|
||||
if running_memorys:
|
||||
memory_str = "以下是当前在聊天中,你回忆起的记忆:\n"
|
||||
for running_memory in running_memorys:
|
||||
memory_str += f"{running_memory['content']}\n"
|
||||
if memory_str:
|
||||
action_data["memory_block"] = memory_str
|
||||
|
||||
# 对于reply动作不需要额外处理,因为相关字段已经在上面的循环中添加到action_data
|
||||
|
||||
if extracted_action not in current_available_actions:
|
||||
@@ -339,7 +330,7 @@ class ActionPlanner(BasePlanner):
|
||||
observed_messages_str: str,
|
||||
structured_info: Optional[str],
|
||||
current_available_actions: Dict[str, ActionInfo],
|
||||
cycle_info: Optional[str],
|
||||
# cycle_info: Optional[str],
|
||||
extra_info: list[str],
|
||||
running_memorys: List[Dict[str, Any]],
|
||||
) -> str:
|
||||
@@ -350,12 +341,6 @@ class ActionPlanner(BasePlanner):
|
||||
else:
|
||||
relation_info_block = ""
|
||||
|
||||
memory_str = ""
|
||||
if running_memorys:
|
||||
memory_str = "以下是当前在聊天中,你回忆起的记忆:\n"
|
||||
for running_memory in running_memorys:
|
||||
memory_str += f"{running_memory['content']}\n"
|
||||
|
||||
chat_context_description = "你现在正在一个群聊中"
|
||||
chat_target_name = None # Only relevant for private
|
||||
if not is_group_chat and chat_target_info:
|
||||
@@ -438,7 +423,6 @@ class ActionPlanner(BasePlanner):
|
||||
time_block=time_block,
|
||||
chat_context_description=chat_context_description,
|
||||
chat_content_block=chat_content_block,
|
||||
cycle_info_block=cycle_info,
|
||||
action_options_text=action_options_block,
|
||||
moderation_prompt=moderation_prompt_block,
|
||||
indentify_block=indentify_block,
|
||||
|
||||
@@ -29,11 +29,9 @@ def init_prompt():
|
||||
Prompt(
|
||||
"""
|
||||
{expression_habits_block}
|
||||
|
||||
{extra_info_block}
|
||||
|
||||
{memory_block}
|
||||
{relation_info_block}
|
||||
|
||||
{time_block}
|
||||
{chat_target}
|
||||
{chat_info}
|
||||
@@ -53,6 +51,7 @@ def init_prompt():
|
||||
"""
|
||||
{expression_habits_block}
|
||||
{extra_info_block}
|
||||
{memory_block}
|
||||
{time_block}
|
||||
{chat_target}
|
||||
{chat_info}
|
||||
@@ -281,6 +280,7 @@ class DefaultReplyer:
|
||||
extra_info_block = reply_data.get("extra_info_block", "")
|
||||
relation_info_block = reply_data.get("relation_info_block", "")
|
||||
reply_to = reply_data.get("reply_to", "none")
|
||||
memory_block = reply_data.get("memory_block", "")
|
||||
|
||||
sender = ""
|
||||
target = ""
|
||||
@@ -394,6 +394,7 @@ class DefaultReplyer:
|
||||
expression_habits_block=expression_habits_block,
|
||||
chat_target=chat_target_1,
|
||||
chat_info=chat_talking_prompt,
|
||||
memory_block=memory_block,
|
||||
extra_info_block=extra_info_block,
|
||||
relation_info_block=relation_info_block,
|
||||
self_info_block=self_info_block,
|
||||
@@ -419,6 +420,7 @@ class DefaultReplyer:
|
||||
expression_habits_block=expression_habits_block,
|
||||
chat_target=chat_target_1,
|
||||
chat_info=chat_talking_prompt,
|
||||
memory_block=memory_block,
|
||||
extra_info_block=extra_info_block,
|
||||
time_block=time_block,
|
||||
keywords_reaction_prompt=keywords_reaction_prompt,
|
||||
|
||||
Reference in New Issue
Block a user