From 0e31276bdec55f1b1fa4c302d63c0249fc0ca8a4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Apr 2025 12:39:04 +0000 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=A4=96=20=E8=87=AA=E5=8A=A8=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/remove_chong.py | 13 ++++++++----- src/config/config.py | 3 ++- src/heart_flow/subheartflow_manager.py | 4 ++-- src/plugins/person_info/relationship_manager.py | 2 +- src/plugins/utils/chat_message_builder.py | 5 ++++- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/scripts/remove_chong.py b/scripts/remove_chong.py index 40ba7428b..95c01389c 100644 --- a/scripts/remove_chong.py +++ b/scripts/remove_chong.py @@ -1,6 +1,7 @@ import difflib import random + def ji_suan_xiang_si_du(wen_ben_yi: str, wen_ben_er: str) -> float: """ 计算两个文本字符串的相似度。 @@ -17,6 +18,7 @@ def ji_suan_xiang_si_du(wen_ben_yi: str, wen_ben_er: str) -> float: xiang_si_bi_lv = xu_lie_pi_pei_qi.ratio() return xiang_si_bi_lv + def ji_suan_ti_huan_gai_lv(xiang_si_du: float) -> float: """ 根据相似度计算替换的概率。 @@ -33,11 +35,12 @@ def ji_suan_ti_huan_gai_lv(xiang_si_du: float) -> float: elif 0.4 < xiang_si_du <= 0.6: # p = 2.5 * s - 1.0 (线性方程 y - 0 = (0.5-0)/(0.6-0.4) * (x - 0.4)) gai_lv = 2.5 * xiang_si_du - 1.0 - return max(0.0, gai_lv) # 确保概率不小于0 + return max(0.0, gai_lv) # 确保概率不小于0 elif 0.6 < xiang_si_du < 0.9: # p = (5/3) * s - 0.5 (线性方程 y - 0.5 = (1-0.5)/(0.9-0.6) * (x - 0.6)) gai_lv = (5 / 3) * xiang_si_du - 0.5 - return min(1.0, max(0.0, gai_lv)) # 确保概率在 0 和 1 之间 + return min(1.0, max(0.0, gai_lv)) # 确保概率在 0 和 1 之间 + # 获取用户输入 shu_ru_yi = "豆豆刚刚回复了我的问候 现在可以等待对方的回应 不需要再主动发言 目前情绪满足 不需要使用工具" @@ -66,7 +69,7 @@ if random.random() < ti_huan_gai_lv: # 更新下一个非匹配部分的起始位置 last_match_end_in_b = j + n - jie_guo = "".join(qu_chong_hou_de_er).strip() # 去除首尾空白 + jie_guo = "".join(qu_chong_hou_de_er).strip() # 去除首尾空白 if jie_guo: # 定义词语列表 @@ -77,9 +80,9 @@ if random.random() < ti_huan_gai_lv: # 根据概率决定是否添加词语 qian_zhui_str = "" - if random.random() < 0.3: # 30% 概率添加语气词 + if random.random() < 0.3: # 30% 概率添加语气词 qian_zhui_str += random.choice(yu_qi_ci_liebiao) - if random.random() < 0.7: # 70% 概率添加转折/承接词 + if random.random() < 0.7: # 70% 概率添加转折/承接词 qian_zhui_str += random.choice(zhuan_jie_ci_liebiao) # 组合最终结果 diff --git a/src/config/config.py b/src/config/config.py index d9d5ce162..f09da9a7e 100644 --- a/src/config/config.py +++ b/src/config/config.py @@ -185,7 +185,7 @@ class BotConfig: reply_trigger_threshold: float = 3.0 # 心流聊天触发阈值,越低越容易触发 probability_decay_factor_per_second: float = 0.2 # 概率衰减因子,越大衰减越快 default_decay_rate_per_second: float = 0.98 # 默认衰减率,越大衰减越慢 - allow_focus_mode: bool = True # 是否允许子心流进入 FOCUSED 状态 + allow_focus_mode: bool = True # 是否允许子心流进入 FOCUSED 状态 # sub_heart_flow_update_interval: int = 60 # 子心流更新频率,间隔 单位秒 # sub_heart_flow_freeze_time: int = 120 # 子心流冻结时间,超过这个时间没有回复,子心流会冻结,间隔 单位秒 @@ -417,6 +417,7 @@ class BotConfig: config.model_normal_probability = response_config.get( "model_normal_probability", config.model_normal_probability ) + def heartflow(parent: dict): heartflow_config = parent["heartflow"] config.sub_heart_flow_stop_time = heartflow_config.get( diff --git a/src/heart_flow/subheartflow_manager.py b/src/heart_flow/subheartflow_manager.py index c355867c5..afa0328e6 100644 --- a/src/heart_flow/subheartflow_manager.py +++ b/src/heart_flow/subheartflow_manager.py @@ -266,9 +266,9 @@ class SubHeartflowManager: # --- 新增:检查是否允许进入 FOCUS 模式 --- # if not global_config.allow_focus_mode: - if int(time.time()) % 60 == 0: # 每60秒输出一次日志避免刷屏 + if int(time.time()) % 60 == 0: # 每60秒输出一次日志避免刷屏 logger.debug(f"{log_prefix} 配置不允许进入 FOCUSED 状态 (allow_focus_mode=False)") - return # 如果不允许,直接返回 + return # 如果不允许,直接返回 # --- 结束新增 --- logger.debug(f"{log_prefix} 当前状态 ({current_state.value}) 开始尝试提升到FOCUSED状态") diff --git a/src/plugins/person_info/relationship_manager.py b/src/plugins/person_info/relationship_manager.py index b66d74d5c..47caaea01 100644 --- a/src/plugins/person_info/relationship_manager.py +++ b/src/plugins/person_info/relationship_manager.py @@ -283,7 +283,7 @@ class RelationshipManager: person_name = await person_info_manager.get_value(person_id, "person_name") relationship_value = await person_info_manager.get_value(person_id, "relationship_value") level_num = self.calculate_level_num(relationship_value) - + if level_num == 0 or level_num == 5: relationship_level = ["厌恶", "冷漠以对", "认识", "友好对待", "喜欢", "暧昧"] relation_prompt2_list = [ diff --git a/src/plugins/utils/chat_message_builder.py b/src/plugins/utils/chat_message_builder.py index 4e807ffaf..a49f4ffa3 100644 --- a/src/plugins/utils/chat_message_builder.py +++ b/src/plugins/utils/chat_message_builder.py @@ -348,7 +348,10 @@ async def build_readable_messages( messages_before_mark, replace_bot_name, merge_messages, timestamp_mode, truncate ) formatted_after, _ = await _build_readable_messages_internal( - messages_after_mark, replace_bot_name, merge_messages, timestamp_mode, + messages_after_mark, + replace_bot_name, + merge_messages, + timestamp_mode, ) readable_read_mark = translate_timestamp_to_human_readable(read_mark, mode=timestamp_mode) From 894fe8463c154a8efd6432c490df67ccc6be3a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com> Date: Tue, 29 Apr 2025 23:35:41 +0800 Subject: [PATCH 2/3] logger add init style --- src/common/logger.py | 18 +++++++++++++++++- src/common/logger_manager.py | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/common/logger.py b/src/common/logger.py index 5b909744b..be272eb38 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -793,6 +793,22 @@ LPMM_GET_KNOWLEDGE_TOOL_STYLE_CONFIG = { }, } +INIT_STYLE_CONFIG = { + "advanced": { + "console_format": ( + "{time:YYYY-MM-DD HH:mm:ss} | " + "{level: <8} | " + "初始化 | " + "{message}" + ), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 初始化 | {message}", + }, + "simple": { + "console_format": "{time:MM-DD HH:mm} | 初始化 | {message}", + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 初始化 | {message}", + }, +} + # 根据SIMPLE_OUTPUT选择配置 MAIN_STYLE_CONFIG = MAIN_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else MAIN_STYLE_CONFIG["advanced"] @@ -862,7 +878,7 @@ CHAT_MESSAGE_STYLE_CONFIG = ( CHAT_MESSAGE_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else CHAT_MESSAGE_STYLE_CONFIG["advanced"] ) CHAT_IMAGE_STYLE_CONFIG = CHAT_IMAGE_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else CHAT_IMAGE_STYLE_CONFIG["advanced"] - +INIT_STYLE_CONFIG = INIT_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else INIT_STYLE_CONFIG["advanced"] def is_registered_module(record: dict) -> bool: """检查是否为已注册的模块""" diff --git a/src/common/logger_manager.py b/src/common/logger_manager.py index b93f56d7e..ab1861e2b 100644 --- a/src/common/logger_manager.py +++ b/src/common/logger_manager.py @@ -40,6 +40,7 @@ from src.common.logger import ( MESSAGE_BUFFER_STYLE_CONFIG, CHAT_MESSAGE_STYLE_CONFIG, CHAT_IMAGE_STYLE_CONFIG, + INIT_STYLE_CONFIG, ) # 可根据实际需要补充更多模块配置 @@ -84,6 +85,7 @@ MODULE_LOGGER_CONFIGS = { "message_buffer": MESSAGE_BUFFER_STYLE_CONFIG, # 消息缓冲 "chat_message": CHAT_MESSAGE_STYLE_CONFIG, # 聊天消息 "chat_image": CHAT_IMAGE_STYLE_CONFIG, # 聊天图片 + "init": INIT_STYLE_CONFIG, # 初始化 # ...如有更多模块,继续添加... } From 46efe44d58ca535236886ef51e63d084db6da030 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Apr 2025 15:35:57 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=A4=96=20=E8=87=AA=E5=8A=A8=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/logger.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/logger.py b/src/common/logger.py index be272eb38..43972e1f2 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -880,6 +880,7 @@ CHAT_MESSAGE_STYLE_CONFIG = ( CHAT_IMAGE_STYLE_CONFIG = CHAT_IMAGE_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else CHAT_IMAGE_STYLE_CONFIG["advanced"] INIT_STYLE_CONFIG = INIT_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else INIT_STYLE_CONFIG["advanced"] + def is_registered_module(record: dict) -> bool: """检查是否为已注册的模块""" return record["extra"].get("module") in _handler_registry