From cdb0912b5a06054de46a5c35fc3bb83beec49f90 Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Wed, 25 Jun 2025 20:39:20 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E6=9D=83=E9=87=8D=E7=88=86=E7=82=B8=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/express/expression_selector.py | 31 ++++++------------- .../info_processors/relationship_processor.py | 3 +- src/person_info/relationship_manager.py | 23 ++++++++------ 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/chat/express/expression_selector.py b/src/chat/express/expression_selector.py index dc2ebb9e1..20211b9de 100644 --- a/src/chat/express/expression_selector.py +++ b/src/chat/express/expression_selector.py @@ -108,13 +108,13 @@ class ExpressionSelector: return selected_style, selected_grammar, selected_personality - def update_expression_count(self, chat_id: str, expression: Dict[str, str], base_multiplier: float = 1.5): + def update_expression_count(self, chat_id: str, expression: Dict[str, str], increment: float = 0.1): """更新表达方式的count值 Args: chat_id: 聊天ID expression: 表达方式字典 - base_multiplier: 基础倍数,当count=1时使用此倍数 + increment: 增量值,默认0.1 """ if expression.get("type") == "style_personality": # personality表达方式存储在全局文件中 @@ -142,27 +142,14 @@ class ExpressionSelector: "style" ): current_count = expr.get("count", 1) - - # 计算动态倍数:count值越高,增加倍数越小 - if current_count <= 1: - # count <= 1时使用基础倍数 - dynamic_multiplier = base_multiplier - else: - # count > 1时,倍数逐渐降低 - # 使用公式:base_multiplier / (1 + (count - 1) * 0.3) - # 这样count=2时倍数约为1.15,count=5时倍数约为1.06 - decay_factor = 0.3 - dynamic_multiplier = base_multiplier / (1 + (current_count - 1) * decay_factor) - - # 确保倍数不低于1.01(至少要有一点增长) - dynamic_multiplier = max(dynamic_multiplier, 1.01) - - new_count = current_count * dynamic_multiplier + + # 简单加0.1,但限制最高为5 + new_count = min(current_count + increment, 5.0) expr["count"] = new_count expr["last_active_time"] = time.time() - logger.debug( - f"表达方式激活: 原count={current_count:.2f}, 倍数={dynamic_multiplier:.3f}, 新count={new_count:.2f}" + logger.info( + f"表达方式激活: 原count={current_count:.2f}, 增量={increment}, 新count={new_count:.2f}" ) break @@ -252,8 +239,8 @@ class ExpressionSelector: expression = all_expressions[idx - 1] # 索引从1开始 valid_expressions.append(expression) - # 对选中的表达方式count数*1.5 - self.update_expression_count(chat_id, expression, 1.5) + # 对选中的表达方式count数+0.1 + self.update_expression_count(chat_id, expression, 0.1) # logger.info(f"LLM从{len(all_expressions)}个情境中选择了{len(valid_expressions)}个") return valid_expressions diff --git a/src/chat/focus_chat/info_processors/relationship_processor.py b/src/chat/focus_chat/info_processors/relationship_processor.py index a3019447c..b6fdda66f 100644 --- a/src/chat/focus_chat/info_processors/relationship_processor.py +++ b/src/chat/focus_chat/info_processors/relationship_processor.py @@ -293,7 +293,7 @@ class PersonImpressionpProcessor(BaseProcessor): } segments.append(new_segment) - person_name = get_person_info_manager().get_value(person_id, "person_name") + person_name = get_person_info_manager().get_value(person_id, "person_name") or person_id logger.info( f"{self.log_prefix} 眼熟用户 {person_name} 在 {time.strftime('%H:%M:%S', time.localtime(potential_start_time))} - {time.strftime('%H:%M:%S', time.localtime(message_time))} 之间有 {new_segment['message_count']} 条消息" ) @@ -341,6 +341,7 @@ class PersonImpressionpProcessor(BaseProcessor): "message_count": self._count_messages_in_timerange(potential_start_time, message_time), } segments.append(new_segment) + person_name = get_person_info_manager().get_value(person_id, "person_name") or person_id logger.info(f"{self.log_prefix} 重新眼熟用户 {person_name} 创建新消息段(超过10条消息间隔): {new_segment}") self._save_cache() diff --git a/src/person_info/relationship_manager.py b/src/person_info/relationship_manager.py index 1af9e7a86..e831060b9 100644 --- a/src/person_info/relationship_manager.py +++ b/src/person_info/relationship_manager.py @@ -500,20 +500,25 @@ class RelationshipManager: new_familiarity_value = int(relation_value_json.get("familiarity_value", 0)) new_liking_value = int(relation_value_json.get("liking_value", 50)) + # 获取当前的关系值 + old_familiarity_value = await person_info_manager.get_value(person_id, "familiarity_value") or 0 + liking_value = await person_info_manager.get_value(person_id, "liking_value") or 50 + + # 更新熟悉度 if new_familiarity_value > 25: - old_familiarity_value = await person_info_manager.get_value(person_id, "familiarity_value") or 0 - old_familiarity_value += new_familiarity_value - 25 / 75 + familiarity_value = old_familiarity_value + (new_familiarity_value - 25) / 75 + else: + familiarity_value = old_familiarity_value + # 更新好感度 if new_liking_value > 50: - liking_value = await person_info_manager.get_value(person_id, "liking_value") or 50 - liking_value += new_liking_value - 50 / 50 - if new_liking_value < 50: - liking_value = await person_info_manager.get_value(person_id, "liking_value") or 50 - liking_value -= (50 - new_liking_value / 50) * 1.5 + liking_value += (new_liking_value - 50) / 50 + elif new_liking_value < 50: + liking_value -= (50 - new_liking_value) / 50 * 1.5 - await person_info_manager.update_one_field(person_id, "familiarity_value", liking_value) + await person_info_manager.update_one_field(person_id, "familiarity_value", familiarity_value) await person_info_manager.update_one_field(person_id, "liking_value", liking_value) - logger.info(f"更新了与 {person_name} 的关系值: 熟悉度={liking_value}, 好感度={liking_value}") + logger.info(f"更新了与 {person_name} 的关系值: 熟悉度={familiarity_value}, 好感度={liking_value}") except (json.JSONDecodeError, ValueError, TypeError) as e: logger.error(f"解析relation_value JSON失败或值无效: {e}, 响应: {relation_value_response}")