fix:微调了关系参
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -315,3 +315,4 @@ run_pet.bat
|
|||||||
!/src/plugins/tts_plugin/
|
!/src/plugins/tts_plugin/
|
||||||
!/src/plugins/vtb_action/
|
!/src/plugins/vtb_action/
|
||||||
!/src/plugins/__init__.py
|
!/src/plugins/__init__.py
|
||||||
|
!/src/plugins/example_commands/
|
||||||
|
|||||||
@@ -146,10 +146,18 @@ class RelationshipProcessor(BaseProcessor):
|
|||||||
time_elapsed = current_time - record["start_time"]
|
time_elapsed = current_time - record["start_time"]
|
||||||
message_count = len(get_raw_msg_by_timestamp_with_chat(self.subheartflow_id, record["start_time"], current_time))
|
message_count = len(get_raw_msg_by_timestamp_with_chat(self.subheartflow_id, record["start_time"], current_time))
|
||||||
|
|
||||||
if (record["rounds"] > 50 or
|
print(record)
|
||||||
time_elapsed > 1800 or # 30分钟
|
|
||||||
message_count > 75):
|
# 根据消息数量和时间设置不同的触发条件
|
||||||
logger.info(f"{self.log_prefix} 用户 {record['person_id']} 满足关系构建条件,开始构建关系。")
|
should_trigger = (
|
||||||
|
message_count >= 50 or # 50条消息必定满足
|
||||||
|
(message_count >= 35 and time_elapsed >= 600) or # 35条且10分钟
|
||||||
|
(message_count >= 25 and time_elapsed >= 1800) or # 25条且30分钟
|
||||||
|
(message_count >= 10 and time_elapsed >= 3600) # 10条且1小时
|
||||||
|
)
|
||||||
|
|
||||||
|
if should_trigger:
|
||||||
|
logger.info(f"{self.log_prefix} 用户 {record['person_id']} 满足关系构建条件,开始构建关系。消息数:{message_count},时长:{time_elapsed:.0f}秒")
|
||||||
asyncio.create_task(
|
asyncio.create_task(
|
||||||
self.update_impression_on_cache_expiry(
|
self.update_impression_on_cache_expiry(
|
||||||
record["person_id"],
|
record["person_id"],
|
||||||
@@ -228,6 +236,9 @@ class RelationshipProcessor(BaseProcessor):
|
|||||||
|
|
||||||
logger.info(f"{self.log_prefix} 调取用户 {person_name} 的 {info_type} 信息。")
|
logger.info(f"{self.log_prefix} 调取用户 {person_name} 的 {info_type} 信息。")
|
||||||
|
|
||||||
|
# 检查person_engaged_cache中是否已存在该person_id
|
||||||
|
person_exists = any(record["person_id"] == person_id for record in self.person_engaged_cache)
|
||||||
|
if not person_exists:
|
||||||
self.person_engaged_cache.append({
|
self.person_engaged_cache.append({
|
||||||
"person_id": person_id,
|
"person_id": person_id,
|
||||||
"start_time": time.time(),
|
"start_time": time.time(),
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ class RelationshipManager:
|
|||||||
prompt = f"""
|
prompt = f"""
|
||||||
你的名字是{global_config.bot.nickname},{global_config.bot.nickname}的别名是{alias_str}。
|
你的名字是{global_config.bot.nickname},{global_config.bot.nickname}的别名是{alias_str}。
|
||||||
请不要混淆你自己和{global_config.bot.nickname}和{person_name}。
|
请不要混淆你自己和{global_config.bot.nickname}和{person_name}。
|
||||||
请你基于用户 {person_name}(昵称:{nickname}) 的最近发言,总结出其中是否有有关{person_name}的内容引起了你的兴趣,或者有什么需要你记忆的点。
|
请你基于用户 {person_name}(昵称:{nickname}) 的最近发言,总结出其中是否有有关{person_name}的内容引起了你的兴趣,或者有什么需要你记忆的点,或者对你友好或者不友好的点。
|
||||||
如果没有,就输出none
|
如果没有,就输出none
|
||||||
|
|
||||||
{current_time}的聊天内容:
|
{current_time}的聊天内容:
|
||||||
@@ -359,7 +359,7 @@ class RelationshipManager:
|
|||||||
else:
|
else:
|
||||||
current_points = points_list
|
current_points = points_list
|
||||||
|
|
||||||
# 如果points超过30条,按权重随机选择多余的条目移动到forgotten_points
|
# 如果points超过10条,按权重随机选择多余的条目移动到forgotten_points
|
||||||
if len(current_points) > 10:
|
if len(current_points) > 10:
|
||||||
# 获取现有forgotten_points
|
# 获取现有forgotten_points
|
||||||
forgotten_points = await person_info_manager.get_value(person_id, "forgotten_points") or []
|
forgotten_points = await person_info_manager.get_value(person_id, "forgotten_points") or []
|
||||||
@@ -394,7 +394,7 @@ class RelationshipManager:
|
|||||||
# 计算保留概率(权重越高越可能保留)
|
# 计算保留概率(权重越高越可能保留)
|
||||||
keep_probability = weight / total_weight
|
keep_probability = weight / total_weight
|
||||||
|
|
||||||
if len(remaining_points) < 30:
|
if len(remaining_points) < 10:
|
||||||
# 如果还没达到30条,直接保留
|
# 如果还没达到30条,直接保留
|
||||||
remaining_points.append(point)
|
remaining_points.append(point)
|
||||||
else:
|
else:
|
||||||
@@ -412,7 +412,7 @@ class RelationshipManager:
|
|||||||
current_points = remaining_points
|
current_points = remaining_points
|
||||||
forgotten_points.extend(points_to_move)
|
forgotten_points.extend(points_to_move)
|
||||||
|
|
||||||
# 检查forgotten_points是否达到100条
|
# 检查forgotten_points是否达到5条
|
||||||
if len(forgotten_points) >= 5:
|
if len(forgotten_points) >= 5:
|
||||||
# 构建压缩总结提示词
|
# 构建压缩总结提示词
|
||||||
alias_str = ", ".join(global_config.bot.alias_names)
|
alias_str = ", ".join(global_config.bot.alias_names)
|
||||||
@@ -433,19 +433,26 @@ class RelationshipManager:
|
|||||||
你的名字是{global_config.bot.nickname},{global_config.bot.nickname}的别名是{alias_str}。
|
你的名字是{global_config.bot.nickname},{global_config.bot.nickname}的别名是{alias_str}。
|
||||||
请不要混淆你自己和{global_config.bot.nickname}和{person_name}。
|
请不要混淆你自己和{global_config.bot.nickname}和{person_name}。
|
||||||
|
|
||||||
请根据以下历史记录,添加,修改,整合,原有的印象和关系,总结出对用户 {person_name}(昵称:{nickname})的信息。
|
请根据你对ta过去的了解,和ta最近的行为,修改,整合,原有的了解,总结出对用户 {person_name}(昵称:{nickname})新的了解。
|
||||||
|
|
||||||
你之前对他的印象和关系是:
|
了解可以包含性格,关系,感受,态度,你推测的ta的性别,年龄,外貌,身份,习惯,爱好,重要事件,重要经历等等内容。也可以包含其他点。
|
||||||
印象impression:{impression}
|
关注友好和不友好的因素,不要忽略。
|
||||||
|
请严格按照以下给出的信息,不要新增额外内容。
|
||||||
|
|
||||||
|
你之前对他的了解是:
|
||||||
|
{impression}
|
||||||
|
|
||||||
你记得ta最近做的事:
|
你记得ta最近做的事:
|
||||||
{points_text}
|
{points_text}
|
||||||
|
|
||||||
请输出:impression:,对这个人的总体印象,你对ta的感觉,你们的交互方式,对方的性格特点,身份,外貌,年龄,性别,习惯,爱好等等内容
|
请输出一段平文本,以陈诉自白的语气,输出你对{person_name}的了解,不要输出任何其他内容。
|
||||||
"""
|
"""
|
||||||
# 调用LLM生成压缩总结
|
# 调用LLM生成压缩总结
|
||||||
compressed_summary, _ = await self.relationship_llm.generate_response_async(prompt=compress_prompt)
|
compressed_summary, _ = await self.relationship_llm.generate_response_async(prompt=compress_prompt)
|
||||||
|
|
||||||
|
current_time = datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
compressed_summary = f"截至{current_time},你对{person_name}的了解:{compressed_summary}"
|
||||||
|
|
||||||
await person_info_manager.update_one_field(person_id, "impression", compressed_summary)
|
await person_info_manager.update_one_field(person_id, "impression", compressed_summary)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
115
src/plugins/example_commands/commands/help_command.py
Normal file
115
src/plugins/example_commands/commands/help_command.py
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
from src.common.logger_manager import get_logger
|
||||||
|
from src.chat.message_receive.command_handler import BaseCommand, register_command, _COMMAND_REGISTRY
|
||||||
|
from typing import Tuple, Optional
|
||||||
|
|
||||||
|
logger = get_logger("help_command")
|
||||||
|
|
||||||
|
@register_command
|
||||||
|
class HelpCommand(BaseCommand):
|
||||||
|
"""帮助命令,显示所有可用命令的帮助信息"""
|
||||||
|
|
||||||
|
command_name = "help"
|
||||||
|
command_description = "显示所有可用命令的帮助信息"
|
||||||
|
command_pattern = r"^/help(?:\s+(?P<command>\w+))?$" # 匹配 /help 或 /help 命令名
|
||||||
|
command_help = "使用方法: /help [命令名] - 显示所有命令或特定命令的帮助信息"
|
||||||
|
command_examples = ["/help", "/help echo"]
|
||||||
|
enable_command = True
|
||||||
|
|
||||||
|
async def execute(self) -> Tuple[bool, Optional[str]]:
|
||||||
|
"""执行帮助命令
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Tuple[bool, Optional[str]]: (是否执行成功, 回复消息)
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# 获取匹配到的命令名(如果有)
|
||||||
|
command_name = self.matched_groups.get("command")
|
||||||
|
|
||||||
|
# 如果指定了命令名,显示该命令的详细帮助
|
||||||
|
if command_name:
|
||||||
|
logger.info(f"{self.log_prefix} 查询命令帮助: {command_name}")
|
||||||
|
return self._show_command_help(command_name)
|
||||||
|
|
||||||
|
# 否则,显示所有命令的简要帮助
|
||||||
|
logger.info(f"{self.log_prefix} 查询所有命令帮助")
|
||||||
|
return self._show_all_commands()
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"{self.log_prefix} 执行帮助命令时出错: {e}")
|
||||||
|
return False, f"执行命令时出错: {str(e)}"
|
||||||
|
|
||||||
|
def _show_command_help(self, command_name: str) -> Tuple[bool, str]:
|
||||||
|
"""显示特定命令的详细帮助信息
|
||||||
|
|
||||||
|
Args:
|
||||||
|
command_name: 命令名称
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Tuple[bool, str]: (是否执行成功, 回复消息)
|
||||||
|
"""
|
||||||
|
# 查找命令
|
||||||
|
command_cls = _COMMAND_REGISTRY.get(command_name)
|
||||||
|
|
||||||
|
if not command_cls:
|
||||||
|
return False, f"未找到命令: {command_name}"
|
||||||
|
|
||||||
|
# 获取命令信息
|
||||||
|
description = getattr(command_cls, "command_description", "无描述")
|
||||||
|
help_text = getattr(command_cls, "command_help", "无帮助信息")
|
||||||
|
examples = getattr(command_cls, "command_examples", [])
|
||||||
|
|
||||||
|
# 构建帮助信息
|
||||||
|
help_info = [
|
||||||
|
f"【命令】: {command_name}",
|
||||||
|
f"【描述】: {description}",
|
||||||
|
f"【用法】: {help_text}"
|
||||||
|
]
|
||||||
|
|
||||||
|
# 添加示例
|
||||||
|
if examples:
|
||||||
|
help_info.append("【示例】:")
|
||||||
|
for example in examples:
|
||||||
|
help_info.append(f" {example}")
|
||||||
|
|
||||||
|
return True, "\n".join(help_info)
|
||||||
|
|
||||||
|
def _show_all_commands(self) -> Tuple[bool, str]:
|
||||||
|
"""显示所有可用命令的简要帮助信息
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Tuple[bool, str]: (是否执行成功, 回复消息)
|
||||||
|
"""
|
||||||
|
# 获取所有已启用的命令
|
||||||
|
enabled_commands = {
|
||||||
|
name: cls for name, cls in _COMMAND_REGISTRY.items()
|
||||||
|
if getattr(cls, "enable_command", True)
|
||||||
|
}
|
||||||
|
|
||||||
|
if not enabled_commands:
|
||||||
|
return True, "当前没有可用的命令"
|
||||||
|
|
||||||
|
# 构建命令列表
|
||||||
|
command_list = ["可用命令列表:"]
|
||||||
|
for name, cls in sorted(enabled_commands.items()):
|
||||||
|
description = getattr(cls, "command_description", "无描述")
|
||||||
|
# 获取命令前缀示例
|
||||||
|
examples = getattr(cls, "command_examples", [])
|
||||||
|
prefix = ""
|
||||||
|
if examples and len(examples) > 0:
|
||||||
|
# 从第一个示例中提取前缀
|
||||||
|
example = examples[0]
|
||||||
|
# 找到第一个空格前的内容作为前缀
|
||||||
|
space_pos = example.find(" ")
|
||||||
|
if space_pos > 0:
|
||||||
|
prefix = example[:space_pos]
|
||||||
|
else:
|
||||||
|
prefix = example
|
||||||
|
else:
|
||||||
|
# 默认使用/name作为前缀
|
||||||
|
prefix = f"/{name}"
|
||||||
|
|
||||||
|
command_list.append(f"{prefix} - {description}")
|
||||||
|
|
||||||
|
command_list.append("\n使用 /help <命令名> 获取特定命令的详细帮助")
|
||||||
|
|
||||||
|
return True, "\n".join(command_list)
|
||||||
Reference in New Issue
Block a user