关系计算函数迁移

This commit is contained in:
meng_xi_pan
2025-03-14 16:38:52 +08:00
parent aa5bc85e31
commit 6a5316bcf8
2 changed files with 71 additions and 12 deletions

View File

@@ -342,18 +342,22 @@ class ChatBot:
emotion = await self.gpt._get_emotion_tags(raw_content)
logger.debug(f"'{response}' 获取到的情感标签为:{emotion}")
valuedict = {
"happy": 0.5,
"angry": -1,
"sad": -0.5,
"surprised": 0.2,
"disgusted": -1.5,
"fearful": -0.7,
"neutral": 0.1,
}
await relationship_manager.update_relationship_value(
chat_stream=chat, relationship_value=valuedict[emotion[0]]
)
await relationship_manager.calculate_update_relationship_value(chat_stream=chat,label=emotion[0])
# emotion = await self.gpt._get_emotion_tags(raw_content)
# logger.debug(f"为 '{response}' 获取到的情感标签为:{emotion}")
# valuedict = {
# "happy": 0.5,
# "angry": -1,
# "sad": -0.5,
# "surprised": 0.2,
# "disgusted": -1.5,
# "fearful": -0.7,
# "neutral": 0.1,
# }
# await relationship_manager.update_relationship_value(
# chat_stream=chat, relationship_value=valuedict[emotion[0]]
# )
# 使用情绪管理器更新情绪
self.mood_manager.update_mood_from_emotion(emotion[0], global_config.mood_intensity_factor)

View File

@@ -5,6 +5,7 @@ from loguru import logger
from ...common.database import db
from .message_base import UserInfo
from .chat_stream import ChatStream
import math
class Impression:
traits: str = None
@@ -248,6 +249,60 @@ class RelationshipManager:
return user_info.user_nickname or user_info.user_cardname or "某人"
else:
return "某人"
async def calculate_update_relationship_value(self,
chat_stream: ChatStream,
label) -> None:
"""计算变更关系值
新的关系值变更计算方式:
将关系值限定在-1000到1000
对于关系值的变更,期望:
1.向两端逼近时会逐渐减缓
2.关系越差,改善越难,关系越好,恶化越容易
3.人维护关系的精力往往有限,所以当高关系值用户越多,对于中高关系值用户增长越慢
"""
valuedict = {
"happy": 1.0,
"angry": -2.0,
"sad": -1.0,
"surprised": 0.4,
"disgusted": -3,
"fearful": -1.4,
"neutral": 0.2,
}
if self.get_relationship(chat_stream):
old_value = self.get_relationship(chat_stream).relationship_value
else:
return
if old_value > 1000:
old_value = 1000
elif old_value < -1000:
old_value = -1000
value = valuedict[label]
if old_value >= 0:
if valuedict[label] >= 0:
value = value*math.cos(math.pi*old_value/2000)
if old_value > 500:
high_value_count = 0
for key, relationship in self.relationships.items():
if relationship.relationship_value >= 900:
high_value_count += 1
value *= 3/(high_value_count + 3)
elif valuedict[label] < 0:
value = value*math.exp(old_value/1000)
elif old_value < 0:
if valuedict[label] >= 0:
value = value*math.exp(old_value/1000)
elif valuedict[label] < 0:
value = -value*math.cos(math.pi*old_value/2000)
logger.info(f"[zyf调试] 标签:{label} 关系值:{value} 原值:{old_value}")
await self.update_relationship_value(
chat_stream=chat_stream, relationship_value=value
)
relationship_manager = RelationshipManager()