fix:心情收到人格影响,
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,6 +6,7 @@ log/
|
|||||||
logs/
|
logs/
|
||||||
run_ad.bat
|
run_ad.bat
|
||||||
MaiBot-Napcat-Adapter-main
|
MaiBot-Napcat-Adapter-main
|
||||||
|
MaiBot-Napcat-Adapter
|
||||||
/test
|
/test
|
||||||
/src/test
|
/src/test
|
||||||
nonebot-maibot-adapter/
|
nonebot-maibot-adapter/
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class Heartflow:
|
|||||||
while True:
|
while True:
|
||||||
# 检查是否存在子心流
|
# 检查是否存在子心流
|
||||||
if not self._subheartflows:
|
if not self._subheartflows:
|
||||||
logger.info("当前没有子心流,等待新的子心流创建...")
|
# logger.info("当前没有子心流,等待新的子心流创建...")
|
||||||
await asyncio.sleep(30) # 每分钟检查一次是否有新的子心流
|
await asyncio.sleep(30) # 每分钟检查一次是否有新的子心流
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -132,17 +132,19 @@ class MainSystem:
|
|||||||
async def build_memory_task(self):
|
async def build_memory_task(self):
|
||||||
"""记忆构建任务"""
|
"""记忆构建任务"""
|
||||||
while True:
|
while True:
|
||||||
|
await asyncio.sleep(global_config.build_memory_interval)
|
||||||
logger.info("正在进行记忆构建")
|
logger.info("正在进行记忆构建")
|
||||||
await HippocampusManager.get_instance().build_memory()
|
await HippocampusManager.get_instance().build_memory()
|
||||||
await asyncio.sleep(global_config.build_memory_interval)
|
|
||||||
|
|
||||||
async def forget_memory_task(self):
|
async def forget_memory_task(self):
|
||||||
"""记忆遗忘任务"""
|
"""记忆遗忘任务"""
|
||||||
while True:
|
while True:
|
||||||
|
await asyncio.sleep(global_config.forget_memory_interval)
|
||||||
print("\033[1;32m[记忆遗忘]\033[0m 开始遗忘记忆...")
|
print("\033[1;32m[记忆遗忘]\033[0m 开始遗忘记忆...")
|
||||||
await HippocampusManager.get_instance().forget_memory(percentage=global_config.memory_forget_percentage)
|
await HippocampusManager.get_instance().forget_memory(percentage=global_config.memory_forget_percentage)
|
||||||
print("\033[1;32m[记忆遗忘]\033[0m 记忆遗忘完成")
|
print("\033[1;32m[记忆遗忘]\033[0m 记忆遗忘完成")
|
||||||
await asyncio.sleep(global_config.forget_memory_interval)
|
|
||||||
|
|
||||||
async def print_mood_task(self):
|
async def print_mood_task(self):
|
||||||
"""打印情绪状态"""
|
"""打印情绪状态"""
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from src.common.logger import get_module_logger, CHAT_STYLE_CONFIG, LogConfig
|
|||||||
from ..chat_module.think_flow_chat.think_flow_chat import ThinkFlowChat
|
from ..chat_module.think_flow_chat.think_flow_chat import ThinkFlowChat
|
||||||
from ..chat_module.reasoning_chat.reasoning_chat import ReasoningChat
|
from ..chat_module.reasoning_chat.reasoning_chat import ReasoningChat
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import traceback
|
||||||
|
|
||||||
# 定义日志配置
|
# 定义日志配置
|
||||||
chat_config = LogConfig(
|
chat_config = LogConfig(
|
||||||
@@ -144,6 +145,7 @@ class ChatBot:
|
|||||||
logger.error(f"未知的回复模式,请检查配置文件!!: {global_config.response_mode}")
|
logger.error(f"未知的回复模式,请检查配置文件!!: {global_config.response_mode}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"预处理消息失败: {e}")
|
logger.error(f"预处理消息失败: {e}")
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
# 创建全局ChatBot实例
|
# 创建全局ChatBot实例
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ logger = get_module_logger("mood_manager", config=mood_config)
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MoodState:
|
class MoodState:
|
||||||
valence: float # 愉悦度 (-1 到 1)
|
valence: float # 愉悦度 (-1.0 到 1.0),-1表示极度负面,1表示极度正面
|
||||||
arousal: float # 唤醒度 (0 到 1)
|
arousal: float # 唤醒度 (0.0 到 1.0),0表示完全平静,1表示极度兴奋
|
||||||
text: str # 心情文本描述
|
text: str # 心情文本描述
|
||||||
|
|
||||||
|
|
||||||
@@ -126,28 +126,43 @@ class MoodManager:
|
|||||||
time.sleep(update_interval)
|
time.sleep(update_interval)
|
||||||
|
|
||||||
def _apply_decay(self) -> None:
|
def _apply_decay(self) -> None:
|
||||||
"""应用情绪衰减"""
|
"""应用情绪衰减,正向和负向情绪分开计算"""
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
time_diff = current_time - self.last_update
|
time_diff = current_time - self.last_update
|
||||||
|
agreeableness_factor = 1
|
||||||
|
agreeableness_bias = 0
|
||||||
|
neuroticism_factor = 0.5
|
||||||
|
|
||||||
# 获取人格特质
|
# 获取人格特质
|
||||||
personality = Individuality.get_instance().personality
|
personality = Individuality.get_instance().personality
|
||||||
if personality:
|
if personality:
|
||||||
# 神经质:0.5为默认值,0为极低,1为极高
|
# 神经质:影响情绪变化速度
|
||||||
# 神经质越高,情绪变化越快(衰减率越高)
|
neuroticism_factor = 1 + (personality.neuroticism - 0.5) * 0.5
|
||||||
neuroticism_factor = 0.5 + (personality.neuroticism - 0.5) * 0.5 # 范围在0.25-0.75之间
|
agreeableness_factor = 1 + (personality.agreeableness - 0.5) * 0.5
|
||||||
# 宜人性:0.5为默认值,0为极低,1为极高
|
|
||||||
# 宜人性越低,越容易走向负面情绪(向负值偏移)
|
# 宜人性:影响情绪基准线
|
||||||
agreeableness_bias = (0.5 - personality.agreeableness) * 0.2 # 范围在-0.1到0.1之间
|
if personality.agreeableness < 0.2:
|
||||||
else:
|
agreeableness_bias = (personality.agreeableness - 0.2) * 2
|
||||||
neuroticism_factor = 0.5 # 默认值
|
elif personality.agreeableness > 0.8:
|
||||||
agreeableness_bias = 0.0
|
agreeableness_bias = (personality.agreeableness - 0.8) * 2
|
||||||
|
else:
|
||||||
|
agreeableness_bias = 0
|
||||||
|
|
||||||
# Valence 向中性(0)回归,考虑宜人性偏差
|
# 分别计算正向和负向的衰减率
|
||||||
valence_target = agreeableness_bias
|
if self.current_mood.valence >= 0:
|
||||||
self.current_mood.valence = valence_target + (self.current_mood.valence - valence_target) * math.exp(
|
# 正向情绪衰减
|
||||||
-self.decay_rate_valence * time_diff * neuroticism_factor
|
decay_rate_positive = self.decay_rate_valence * (1/agreeableness_factor)
|
||||||
)
|
valence_target = 0 + agreeableness_bias
|
||||||
|
self.current_mood.valence = valence_target + (self.current_mood.valence - valence_target) * math.exp(
|
||||||
|
-decay_rate_positive * time_diff * neuroticism_factor
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# 负向情绪衰减
|
||||||
|
decay_rate_negative = self.decay_rate_valence * agreeableness_factor
|
||||||
|
valence_target = 0 + agreeableness_bias
|
||||||
|
self.current_mood.valence = valence_target + (self.current_mood.valence - valence_target) * math.exp(
|
||||||
|
-decay_rate_negative * time_diff * neuroticism_factor
|
||||||
|
)
|
||||||
|
|
||||||
# Arousal 向中性(0.5)回归
|
# Arousal 向中性(0.5)回归
|
||||||
arousal_target = 0.5
|
arousal_target = 0.5
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ talk_allowed = [
|
|||||||
talk_frequency_down = [] #降低回复频率的群号码
|
talk_frequency_down = [] #降低回复频率的群号码
|
||||||
ban_user_id = [] #禁止回复和读取消息的QQ号
|
ban_user_id = [] #禁止回复和读取消息的QQ号
|
||||||
|
|
||||||
[personality]
|
[personality] #未完善
|
||||||
personality_core = "用一句话或几句话描述人格的核心特点" # 建议20字以内,谁再写3000字小作文敲谁脑袋
|
personality_core = "用一句话或几句话描述人格的核心特点" # 建议20字以内,谁再写3000字小作文敲谁脑袋
|
||||||
personality_sides = [
|
personality_sides = [
|
||||||
"用一句话或几句话描述人格的一些细节",
|
"用一句话或几句话描述人格的一些细节",
|
||||||
@@ -44,7 +44,7 @@ personality_sides = [
|
|||||||
]# 条数任意
|
]# 条数任意
|
||||||
|
|
||||||
[identity] #アイデンティティがない 生まれないらららら
|
[identity] #アイデンティティがない 生まれないらららら
|
||||||
# 兴趣爱好
|
# 兴趣爱好 未完善,有些条目未使用
|
||||||
identity_detail = [
|
identity_detail = [
|
||||||
"身份特点",
|
"身份特点",
|
||||||
"身份特点",
|
"身份特点",
|
||||||
@@ -73,7 +73,7 @@ response_mode = "heart_flow" # 回复策略,可选值:heart_flow(心流)
|
|||||||
model_r1_probability = 0.7 # 麦麦回答时选择主要回复模型1 模型的概率
|
model_r1_probability = 0.7 # 麦麦回答时选择主要回复模型1 模型的概率
|
||||||
model_v3_probability = 0.3 # 麦麦回答时选择次要回复模型2 模型的概率
|
model_v3_probability = 0.3 # 麦麦回答时选择次要回复模型2 模型的概率
|
||||||
|
|
||||||
[heartflow] # 注意:可能会消耗大量token,请谨慎开启
|
[heartflow] # 注意:可能会消耗大量token,请谨慎开启,仅会使用v3模型
|
||||||
sub_heart_flow_update_interval = 60 # 子心流更新频率,间隔 单位秒
|
sub_heart_flow_update_interval = 60 # 子心流更新频率,间隔 单位秒
|
||||||
sub_heart_flow_freeze_time = 120 # 子心流冻结时间,超过这个时间没有回复,子心流会冻结,间隔 单位秒
|
sub_heart_flow_freeze_time = 120 # 子心流冻结时间,超过这个时间没有回复,子心流会冻结,间隔 单位秒
|
||||||
sub_heart_flow_stop_time = 600 # 子心流停止时间,超过这个时间没有回复,子心流会停止,间隔 单位秒
|
sub_heart_flow_stop_time = 600 # 子心流停止时间,超过这个时间没有回复,子心流会停止,间隔 单位秒
|
||||||
@@ -99,7 +99,7 @@ ban_msgs_regex = [
|
|||||||
|
|
||||||
[willing]
|
[willing]
|
||||||
willing_mode = "classical" # 回复意愿模式 经典模式
|
willing_mode = "classical" # 回复意愿模式 经典模式
|
||||||
# willing_mode = "dynamic" # 动态模式(可能不兼容)
|
# willing_mode = "dynamic" # 动态模式(不兼容,需要维护)
|
||||||
# willing_mode = "custom" # 自定义模式(可自行调整
|
# willing_mode = "custom" # 自定义模式(可自行调整
|
||||||
response_willing_amplifier = 1 # 麦麦回复意愿放大系数,一般为1
|
response_willing_amplifier = 1 # 麦麦回复意愿放大系数,一般为1
|
||||||
response_interested_rate_amplifier = 1 # 麦麦回复兴趣度放大系数,听到记忆里的内容时放大系数
|
response_interested_rate_amplifier = 1 # 麦麦回复兴趣度放大系数,听到记忆里的内容时放大系数
|
||||||
@@ -165,7 +165,7 @@ enable = true
|
|||||||
|
|
||||||
[experimental]
|
[experimental]
|
||||||
enable_friend_chat = false # 是否启用好友聊天
|
enable_friend_chat = false # 是否启用好友聊天
|
||||||
pfc_chatting = false # 是否启用PFC聊天
|
pfc_chatting = false # 是否启用PFC聊天,该功能仅作用于私聊,与回复模式独立
|
||||||
|
|
||||||
#下面的模型若使用硅基流动则不需要更改,使用ds官方则改成.env自定义的宏,使用自定义模型则选择定位相似的模型自己填写
|
#下面的模型若使用硅基流动则不需要更改,使用ds官方则改成.env自定义的宏,使用自定义模型则选择定位相似的模型自己填写
|
||||||
#推理模型
|
#推理模型
|
||||||
|
|||||||
Reference in New Issue
Block a user