feat:回复温度现在会受到:人格-情绪-temp的链条影响;顺便修改了情绪激活度的取值

feat:回复温度现在会受到:人格-情绪-temp的链条影响;顺便修改了情绪激活度的取值
This commit is contained in:
SengokuCola
2025-04-09 22:50:21 +08:00
parent a41d0efe7a
commit f3d6e7cfa5
4 changed files with 79 additions and 30 deletions

View File

@@ -19,7 +19,7 @@ logger = get_module_logger("mood_manager", config=mood_config)
@dataclass
class MoodState:
valence: float # 愉悦度 (-1.0 到 1.0)-1表示极度负面1表示极度正面
arousal: float # 唤醒度 (0.0 到 1.0)0表示完全平静1表示极度兴奋
arousal: float # 唤醒度 (-1.0 到 1.0)-1表示抑制1表示兴奋
text: str # 心情文本描述
@@ -42,7 +42,7 @@ class MoodManager:
self._initialized = True
# 初始化心情状态
self.current_mood = MoodState(valence=0.0, arousal=0.5, text="平静")
self.current_mood = MoodState(valence=0.0, arousal=0.0, text="平静")
# 从配置文件获取衰减率
self.decay_rate_valence = 1 - global_config.mood_decay_rate # 愉悦度衰减率
@@ -71,21 +71,21 @@ class MoodManager:
# 情绪文本映射表
self.mood_text_map = {
# 第一象限:高唤醒,正愉悦
(0.5, 0.7): "兴奋",
(0.3, 0.8): "快乐",
(0.2, 0.65): "满足",
(0.5, 0.4): "兴奋",
(0.3, 0.6): "快乐",
(0.2, 0.3): "满足",
# 第二象限:高唤醒,负愉悦
(-0.5, 0.7): "愤怒",
(-0.3, 0.8): "焦虑",
(-0.2, 0.65): "烦躁",
(-0.5, 0.4): "愤怒",
(-0.3, 0.6): "焦虑",
(-0.2, 0.3): "烦躁",
# 第三象限:低唤醒,负愉悦
(-0.5, 0.3): "悲伤",
(-0.3, 0.35): "疲倦",
(-0.4, 0.15): "疲倦",
(-0.5, -0.4): "悲伤",
(-0.3, -0.3): "疲倦",
(-0.4, -0.7): "疲倦",
# 第四象限:低唤醒,正愉悦
(0.2, 0.45): "平静",
(0.3, 0.4): "安宁",
(0.5, 0.3): "放松",
(0.2, -0.1): "平静",
(0.3, -0.2): "安宁",
(0.5, -0.4): "放松",
}
@classmethod
@@ -164,15 +164,15 @@ class MoodManager:
-decay_rate_negative * time_diff * neuroticism_factor
)
# Arousal 向中性0.5)回归
arousal_target = 0.5
# Arousal 向中性0回归
arousal_target = 0
self.current_mood.arousal = arousal_target + (self.current_mood.arousal - arousal_target) * math.exp(
-self.decay_rate_arousal * time_diff * neuroticism_factor
)
# 确保值在合理范围内
self.current_mood.valence = max(-1.0, min(1.0, self.current_mood.valence))
self.current_mood.arousal = max(0.0, min(1.0, self.current_mood.arousal))
self.current_mood.arousal = max(-1.0, min(1.0, self.current_mood.arousal))
self.last_update = current_time
@@ -184,7 +184,7 @@ class MoodManager:
# 限制范围
self.current_mood.valence = max(-1.0, min(1.0, self.current_mood.valence))
self.current_mood.arousal = max(0.0, min(1.0, self.current_mood.arousal))
self.current_mood.arousal = max(-1.0, min(1.0, self.current_mood.arousal))
self._update_mood_text()
@@ -217,7 +217,7 @@ class MoodManager:
# 限制范围
self.current_mood.valence = max(-1.0, min(1.0, self.current_mood.valence))
self.current_mood.arousal = max(0.0, min(1.0, self.current_mood.arousal))
self.current_mood.arousal = max(-1.0, min(1.0, self.current_mood.arousal))
self._update_mood_text()
@@ -232,12 +232,22 @@ class MoodManager:
elif self.current_mood.valence < -0.5:
base_prompt += "你现在心情不太好,"
if self.current_mood.arousal > 0.7:
if self.current_mood.arousal > 0.4:
base_prompt += "情绪比较激动。"
elif self.current_mood.arousal < 0.3:
elif self.current_mood.arousal < -0.4:
base_prompt += "情绪比较平静。"
return base_prompt
def get_arousal_multiplier(self) -> float:
"""根据当前情绪状态返回唤醒度乘数"""
if self.current_mood.arousal > 0.4:
multiplier = 1 + min(0.15,(self.current_mood.arousal - 0.4)/3)
return multiplier
elif self.current_mood.arousal < -0.4:
multiplier = 1 - min(0.15,((0 - self.current_mood.arousal) - 0.4)/3)
return multiplier
return 1.0
def get_current_mood(self) -> MoodState:
"""获取当前情绪状态"""
@@ -278,7 +288,7 @@ class MoodManager:
# 限制范围
self.current_mood.valence = max(-1.0, min(1.0, self.current_mood.valence))
self.current_mood.arousal = max(0.0, min(1.0, self.current_mood.arousal))
self.current_mood.arousal = max(-1.0, min(1.0, self.current_mood.arousal))
self._update_mood_text()