🤖 自动格式化代码 [skip ci]

This commit is contained in:
github-actions[bot]
2025-06-14 13:17:53 +00:00
parent 751a46da7b
commit d9ac3f0bb4
3 changed files with 70 additions and 87 deletions

View File

@@ -678,16 +678,20 @@ class NormalChat:
"last_time": current_time, "last_time": current_time,
"receive_count": 0, "receive_count": 0,
"reply_count": 0, "reply_count": 0,
"relation_built": False "relation_built": False,
} }
if is_reply: if is_reply:
self.engaging_persons[person_id]["reply_count"] += 1 self.engaging_persons[person_id]["reply_count"] += 1
logger.debug(f"[{self.stream_name}] 用户 {person_id} 回复次数更新: {self.engaging_persons[person_id]['reply_count']}") logger.debug(
f"[{self.stream_name}] 用户 {person_id} 回复次数更新: {self.engaging_persons[person_id]['reply_count']}"
)
else: else:
self.engaging_persons[person_id]["receive_count"] += 1 self.engaging_persons[person_id]["receive_count"] += 1
self.engaging_persons[person_id]["last_time"] = current_time self.engaging_persons[person_id]["last_time"] = current_time
logger.debug(f"[{self.stream_name}] 用户 {person_id} 消息次数更新: {self.engaging_persons[person_id]['receive_count']}") logger.debug(
f"[{self.stream_name}] 用户 {person_id} 消息次数更新: {self.engaging_persons[person_id]['receive_count']}"
)
def get_engaging_persons(self) -> dict: def get_engaging_persons(self) -> dict:
"""获取所有engaging_persons统计信息 """获取所有engaging_persons统计信息
@@ -721,11 +725,7 @@ class NormalChat:
if sort_by not in ["receive_count", "reply_count", "last_time"]: if sort_by not in ["receive_count", "reply_count", "last_time"]:
sort_by = "receive_count" sort_by = "receive_count"
sorted_persons = sorted( sorted_persons = sorted(self.engaging_persons.items(), key=lambda x: x[1][sort_by], reverse=True)
self.engaging_persons.items(),
key=lambda x: x[1][sort_by],
reverse=True
)
return sorted_persons[:limit] return sorted_persons[:limit]
@@ -741,17 +741,14 @@ class NormalChat:
dict: 关系构建统计信息 dict: 关系构建统计信息
""" """
total_persons = len(self.engaging_persons) total_persons = len(self.engaging_persons)
relation_built_count = sum(1 for stats in self.engaging_persons.values() relation_built_count = sum(1 for stats in self.engaging_persons.values() if stats.get("relation_built", False))
if stats.get("relation_built", False))
pending_persons = [] pending_persons = []
current_time = time.time() current_time = time.time()
for person_id, stats in self.engaging_persons.items(): for person_id, stats in self.engaging_persons.items():
if not stats.get("relation_built", False): if not stats.get("relation_built", False):
time_elapsed = current_time - stats["first_time"] time_elapsed = current_time - stats["first_time"]
total_messages = self._get_total_messages_in_timerange( total_messages = self._get_total_messages_in_timerange(stats["first_time"], stats["last_time"])
stats["first_time"], stats["last_time"]
)
# 检查是否接近满足条件 # 检查是否接近满足条件
progress_info = { progress_info = {
@@ -764,8 +761,8 @@ class NormalChat:
"50_messages": f"{total_messages}/50 ({total_messages / 50 * 100:.1f}%)", "50_messages": f"{total_messages}/50 ({total_messages / 50 * 100:.1f}%)",
"35_msg_10min": f"{total_messages}/35 + {time_elapsed}/600s", "35_msg_10min": f"{total_messages}/35 + {time_elapsed}/600s",
"25_msg_30min": f"{total_messages}/25 + {time_elapsed}/1800s", "25_msg_30min": f"{total_messages}/25 + {time_elapsed}/1800s",
"10_msg_1hour": f"{total_messages}/10 + {time_elapsed}/3600s" "10_msg_1hour": f"{total_messages}/10 + {time_elapsed}/3600s",
} },
} }
pending_persons.append(progress_info) pending_persons.append(progress_info)
@@ -773,7 +770,7 @@ class NormalChat:
"total_persons": total_persons, "total_persons": total_persons,
"relation_built_count": relation_built_count, "relation_built_count": relation_built_count,
"pending_count": len(pending_persons), "pending_count": len(pending_persons),
"pending_persons": pending_persons "pending_persons": pending_persons,
} }
def get_engaging_persons_summary(self) -> dict: def get_engaging_persons_summary(self) -> dict:
@@ -788,7 +785,7 @@ class NormalChat:
"total_messages": 0, "total_messages": 0,
"total_replies": 0, "total_replies": 0,
"most_active_person": None, "most_active_person": None,
"most_replied_person": None "most_replied_person": None,
} }
total_messages = sum(stats["receive_count"] for stats in self.engaging_persons.values()) total_messages = sum(stats["receive_count"] for stats in self.engaging_persons.values())
@@ -801,14 +798,8 @@ class NormalChat:
"total_persons": len(self.engaging_persons), "total_persons": len(self.engaging_persons),
"total_messages": total_messages, "total_messages": total_messages,
"total_replies": total_replies, "total_replies": total_replies,
"most_active_person": { "most_active_person": {"person_id": most_active[0], "message_count": most_active[1]["receive_count"]},
"person_id": most_active[0], "most_replied_person": {"person_id": most_replied[0], "reply_count": most_replied[1]["reply_count"]},
"message_count": most_active[1]["receive_count"]
},
"most_replied_person": {
"person_id": most_replied[0],
"reply_count": most_replied[1]["reply_count"]
}
} }
async def _check_relation_building_conditions(self): async def _check_relation_building_conditions(self):
@@ -822,9 +813,7 @@ class NormalChat:
# 计算时间差和消息数量 # 计算时间差和消息数量
time_elapsed = current_time - stats["first_time"] time_elapsed = current_time - stats["first_time"]
total_messages = self._get_total_messages_in_timerange( total_messages = self._get_total_messages_in_timerange(stats["first_time"], stats["last_time"])
stats["first_time"], stats["last_time"]
)
# 检查是否满足关系构建条件 # 检查是否满足关系构建条件
should_build_relation = ( should_build_relation = (
@@ -844,7 +833,6 @@ class NormalChat:
# 计算构建概率并决定是否构建 # 计算构建概率并决定是否构建
await self._evaluate_and_build_relation(person_id, stats, total_messages) await self._evaluate_and_build_relation(person_id, stats, total_messages)
def _get_total_messages_in_timerange(self, start_time: float, end_time: float) -> int: def _get_total_messages_in_timerange(self, start_time: float, end_time: float) -> int:
"""获取指定时间范围内的总消息数量""" """获取指定时间范围内的总消息数量"""
try: try:
@@ -903,9 +891,7 @@ class NormalChat:
# 调用关系管理器更新印象 # 调用关系管理器更新印象
relationship_manager = get_relationship_manager() relationship_manager = get_relationship_manager()
await relationship_manager.update_person_impression( await relationship_manager.update_person_impression(
person_id=person_id, person_id=person_id, timestamp=end_time, bot_engaged_messages=messages
timestamp=end_time,
bot_engaged_messages=messages
) )
logger.info(f"[{self.stream_name}] 用户 {person_id} 关系构建完成") logger.info(f"[{self.stream_name}] 用户 {person_id} 关系构建完成")

View File

@@ -382,9 +382,14 @@ class ImageManager:
if existing_image: if existing_image:
# 检查是否缺少必要字段,如果缺少则创建新记录 # 检查是否缺少必要字段,如果缺少则创建新记录
if (not hasattr(existing_image, 'image_id') or not existing_image.image_id or if (
not hasattr(existing_image, 'count') or existing_image.count is None or not hasattr(existing_image, "image_id")
not hasattr(existing_image, 'vlm_processed') or existing_image.vlm_processed is None): or not existing_image.image_id
or not hasattr(existing_image, "count")
or existing_image.count is None
or not hasattr(existing_image, "vlm_processed")
or existing_image.vlm_processed is None
):
logger.debug(f"图片记录缺少必要字段,补全旧记录: {image_hash}") logger.debug(f"图片记录缺少必要字段,补全旧记录: {image_hash}")
image_id = str(uuid.uuid4()) image_id = str(uuid.uuid4())
else: else:

View File

@@ -11,7 +11,6 @@ import json
from json_repair import repair_json from json_repair import repair_json
from datetime import datetime from datetime import datetime
from difflib import SequenceMatcher from difflib import SequenceMatcher
import ast
import jieba import jieba
from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity from sklearn.metrics.pairwise import cosine_similarity
@@ -431,9 +430,6 @@ class RelationshipManager:
await person_info_manager.update_one_field(person_id, "impression", compressed_summary) await person_info_manager.update_one_field(person_id, "impression", compressed_summary)
compress_short_prompt = f""" compress_short_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}
@@ -447,19 +443,15 @@ class RelationshipManager:
3.{person_name}的关键信息 3.{person_name}的关键信息
请输出一段平文本,以陈诉自白的语气,输出你对{person_name}的概括,不要输出任何其他内容。 请输出一段平文本,以陈诉自白的语气,输出你对{person_name}的概括,不要输出任何其他内容。
""" """
compressed_short_summary, _ = await self.relationship_llm.generate_response_async(prompt=compress_short_prompt) compressed_short_summary, _ = await self.relationship_llm.generate_response_async(
prompt=compress_short_prompt
)
# current_time = datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S") # current_time = datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")
# compressed_short_summary = f"截至{current_time},你对{person_name}的了解:{compressed_short_summary}" # compressed_short_summary = f"截至{current_time},你对{person_name}的了解:{compressed_short_summary}"
await person_info_manager.update_one_field(person_id, "short_impression", compressed_short_summary) await person_info_manager.update_one_field(person_id, "short_impression", compressed_short_summary)
forgotten_points = [] forgotten_points = []
# 这句代码的作用是:将更新后的 forgotten_points遗忘的记忆点列表序列化为 JSON 字符串后,写回到数据库中的 forgotten_points 字段 # 这句代码的作用是:将更新后的 forgotten_points遗忘的记忆点列表序列化为 JSON 字符串后,写回到数据库中的 forgotten_points 字段