feat(affinity-flow): 调整回复概率参数和评分计算

- 增加最大不回复次数至15次,降低每次不回复的概率提升至1%
- 在最终评分计算中增加1.15倍系数提升
- 被提及时的基础分数从1.0提升至3.0
- 为兴趣标签保存添加数据库验证机制
- 在消息处理流程中增加数据库存储功能
- 修复JSON解析错误处理,增加异常情况下的默认响应
- 优化数据库会话管理和模型转换的健壮性
This commit is contained in:
Windpicker-owo
2025-09-17 13:37:57 +08:00
committed by Windpicker-owo
parent dcdef633e0
commit e1fcdf94ee
8 changed files with 44 additions and 14 deletions

View File

@@ -22,7 +22,12 @@ def _model_to_dict(instance: Base) -> Dict[str, Any]:
"""
将 SQLAlchemy 模型实例转换为字典。
"""
return {col.name: getattr(instance, col.name) for col in instance.__table__.columns}
try:
return {col.name: getattr(instance, col.name) for col in instance.__table__.columns}
except Exception as e:
# 如果对象已经脱离会话尝试从instance.__dict__中获取数据
logger.warning(f"从数据库对象获取属性失败尝试使用__dict__: {e}")
return {col.name: instance.__dict__.get(col.name) for col in instance.__table__.columns}
async def find_messages(
@@ -133,6 +138,7 @@ async def find_messages(
logger.error(f"执行无限制查询失败: {e}")
results = []
# 在会话内将结果转换为字典,避免会话分离错误
return [_model_to_dict(msg) for msg in results]
except Exception as e:
log_message = (