fix:优化关系构建的prompt
This commit is contained in:
@@ -120,27 +120,39 @@ class RelationshipFetcher:
|
|||||||
|
|
||||||
# 按时间排序forgotten_points
|
# 按时间排序forgotten_points
|
||||||
current_points.sort(key=lambda x: x[2])
|
current_points.sort(key=lambda x: x[2])
|
||||||
# 按权重加权随机抽取3个points,point[1]的值在1-10之间,权重越高被抽到概率越大
|
# 按权重加权随机抽取最多3个不重复的points,point[1]的值在1-10之间,权重越高被抽到概率越大
|
||||||
if len(current_points) > 3:
|
if len(current_points) > 3:
|
||||||
# point[1] 取值范围1-10,直接作为权重
|
# point[1] 取值范围1-10,直接作为权重
|
||||||
weights = [max(1, min(10, int(point[1]))) for point in current_points]
|
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:
|
else:
|
||||||
points = current_points
|
points = current_points
|
||||||
|
|
||||||
# 构建points文本
|
# 构建points文本
|
||||||
points_text = "\n".join([f"{point[2]}:{point[0]}" for point in 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)
|
# info_type = await self._build_fetch_query(person_id, target_message, chat_history)
|
||||||
if info_type:
|
# if info_type:
|
||||||
await self._extract_single_info(person_id, info_type, person_name)
|
# 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 = ""
|
nickname_str = ""
|
||||||
if person_name != nickname_str:
|
if person_name != nickname_str:
|
||||||
nickname_str = f"(ta在{platform}上的昵称是{nickname_str})"
|
nickname_str = f"(ta在{platform}上的昵称是{nickname_str})"
|
||||||
|
|
||||||
|
relation_info = ""
|
||||||
|
|
||||||
if short_impression and relation_info:
|
if short_impression and relation_info:
|
||||||
if points_text:
|
if points_text:
|
||||||
relation_info = f"你对{person_name}的印象是{nickname_str}:{short_impression}。具体来说:{relation_info}。你还记得ta最近做的事:{points_text}"
|
relation_info = f"你对{person_name}的印象是{nickname_str}:{short_impression}。具体来说:{relation_info}。你还记得ta最近做的事:{points_text}"
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class RelationshipManager:
|
|||||||
short_impression = await person_info_manager.get_value(person_id, "short_impression")
|
short_impression = await person_info_manager.get_value(person_id, "short_impression")
|
||||||
|
|
||||||
current_points = await person_info_manager.get_value(person_id, "points") or []
|
current_points = await person_info_manager.get_value(person_id, "points") or []
|
||||||
print(f"current_points: {current_points}")
|
# print(f"current_points: {current_points}")
|
||||||
if isinstance(current_points, str):
|
if isinstance(current_points, str):
|
||||||
try:
|
try:
|
||||||
current_points = json.loads(current_points)
|
current_points = json.loads(current_points)
|
||||||
@@ -89,7 +89,7 @@ class RelationshipManager:
|
|||||||
points = current_points
|
points = current_points
|
||||||
|
|
||||||
# 构建points文本
|
# 构建points文本
|
||||||
points_text = "\n".join([f"{point[2]}:{point[0]}\n" for point in points])
|
points_text = "\n".join([f"{point[2]}:{point[0]}" for point in points])
|
||||||
|
|
||||||
nickname_str = await person_info_manager.get_value(person_id, "nickname")
|
nickname_str = await person_info_manager.get_value(person_id, "nickname")
|
||||||
platform = await person_info_manager.get_value(person_id, "platform")
|
platform = await person_info_manager.get_value(person_id, "platform")
|
||||||
@@ -360,19 +360,19 @@ class RelationshipManager:
|
|||||||
# 根据熟悉度,调整印象和简短印象的最大长度
|
# 根据熟悉度,调整印象和简短印象的最大长度
|
||||||
if know_times > 300:
|
if know_times > 300:
|
||||||
max_impression_length = 2000
|
max_impression_length = 2000
|
||||||
max_short_impression_length = 800
|
max_short_impression_length = 400
|
||||||
elif know_times > 100:
|
elif know_times > 100:
|
||||||
max_impression_length = 1000
|
max_impression_length = 1000
|
||||||
max_short_impression_length = 500
|
max_short_impression_length = 250
|
||||||
elif know_times > 50:
|
elif know_times > 50:
|
||||||
max_impression_length = 500
|
max_impression_length = 500
|
||||||
max_short_impression_length = 300
|
max_short_impression_length = 150
|
||||||
elif know_times > 10:
|
elif know_times > 10:
|
||||||
max_impression_length = 200
|
max_impression_length = 200
|
||||||
max_short_impression_length = 100
|
max_short_impression_length = 60
|
||||||
else:
|
else:
|
||||||
max_impression_length = 100
|
max_impression_length = 100
|
||||||
max_short_impression_length = 50
|
max_short_impression_length = 30
|
||||||
|
|
||||||
# 根据好感度,调整印象和简短印象的最大长度
|
# 根据好感度,调整印象和简短印象的最大长度
|
||||||
attitude_multiplier = (abs(100 - attitude) / 100) + 1
|
attitude_multiplier = (abs(100 - attitude) / 100) + 1
|
||||||
|
|||||||
Reference in New Issue
Block a user