fix:优化关系构建的prompt

This commit is contained in:
SengokuCola
2025-07-11 01:24:07 +08:00
parent 81c1e66867
commit 6bfc8b2d8c
2 changed files with 25 additions and 13 deletions

View File

@@ -120,27 +120,39 @@ class RelationshipFetcher:
# 按时间排序forgotten_points
current_points.sort(key=lambda x: x[2])
# 按权重加权随机抽取3个pointspoint[1]的值在1-10之间权重越高被抽到概率越大
# 按权重加权随机抽取最多3个不重复的pointspoint[1]的值在1-10之间权重越高被抽到概率越大
if len(current_points) > 3:
# point[1] 取值范围1-10直接作为权重
weights = [max(1, min(10, int(point[1]))) for point in current_points]
points = random.choices(current_points, weights=weights, k=3)
# 使用加权采样不放回,保证不重复
indices = list(range(len(current_points)))
selected_indices = set()
points = []
for _ in range(3):
if not indices:
break
sub_weights = [weights[i] for i in indices]
chosen_idx = random.choices(indices, weights=sub_weights, k=1)[0]
points.append(current_points[chosen_idx])
indices.remove(chosen_idx)
else:
points = current_points
# 构建points文本
points_text = "\n".join([f"{point[2]}{point[0]}" for point in points])
info_type = await self._build_fetch_query(person_id, target_message, chat_history)
if info_type:
await self._extract_single_info(person_id, info_type, person_name)
# info_type = await self._build_fetch_query(person_id, target_message, chat_history)
# if info_type:
# await self._extract_single_info(person_id, info_type, person_name)
relation_info = self._organize_known_info()
# relation_info = self._organize_known_info()
nickname_str = ""
if person_name != nickname_str:
nickname_str = f"(ta在{platform}上的昵称是{nickname_str})"
relation_info = ""
if short_impression and relation_info:
if points_text:
relation_info = f"你对{person_name}的印象是{nickname_str}{short_impression}。具体来说:{relation_info}。你还记得ta最近做的事{points_text}"