feat(expression): 添加表达方式管理API,包括查询、创建、更新和删除功能
This commit is contained in:
@@ -241,7 +241,6 @@ class PersonInfoManager:
|
|||||||
|
|
||||||
return person_id
|
return person_id
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def first_knowing_some_one(platform: str, user_id: str, user_nickname: str, user_cardname: str):
|
async def first_knowing_some_one(platform: str, user_id: str, user_nickname: str, user_cardname: str):
|
||||||
"""判断是否认识某人"""
|
"""判断是否认识某人"""
|
||||||
@@ -697,6 +696,18 @@ class PersonInfoManager:
|
|||||||
try:
|
try:
|
||||||
value = getattr(record, field_name)
|
value = getattr(record, field_name)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
|
# 对 JSON 序列化字段进行反序列化
|
||||||
|
if field_name in JSON_SERIALIZED_FIELDS:
|
||||||
|
try:
|
||||||
|
# 确保 value 是字符串类型
|
||||||
|
if isinstance(value, str):
|
||||||
|
return orjson.loads(value)
|
||||||
|
else:
|
||||||
|
# 如果不是字符串,可能已经是解析后的数据,直接返回
|
||||||
|
return value
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"反序列化字段 {field_name} 失败: {e}, value={value}, 使用默认值")
|
||||||
|
return copy.deepcopy(person_info_default.get(field_name))
|
||||||
return value
|
return value
|
||||||
else:
|
else:
|
||||||
return copy.deepcopy(person_info_default.get(field_name))
|
return copy.deepcopy(person_info_default.get(field_name))
|
||||||
@@ -737,7 +748,20 @@ class PersonInfoManager:
|
|||||||
try:
|
try:
|
||||||
value = getattr(record, field_name)
|
value = getattr(record, field_name)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
result[field_name] = value
|
# 对 JSON 序列化字段进行反序列化
|
||||||
|
if field_name in JSON_SERIALIZED_FIELDS:
|
||||||
|
try:
|
||||||
|
# 确保 value 是字符串类型
|
||||||
|
if isinstance(value, str):
|
||||||
|
result[field_name] = orjson.loads(value)
|
||||||
|
else:
|
||||||
|
# 如果不是字符串,可能已经是解析后的数据,直接使用
|
||||||
|
result[field_name] = value
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"反序列化字段 {field_name} 失败: {e}, value={value}, 使用默认值")
|
||||||
|
result[field_name] = copy.deepcopy(person_info_default.get(field_name))
|
||||||
|
else:
|
||||||
|
result[field_name] = value
|
||||||
else:
|
else:
|
||||||
result[field_name] = copy.deepcopy(person_info_default.get(field_name))
|
result[field_name] = copy.deepcopy(person_info_default.get(field_name))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from src.plugin_system.apis import (
|
|||||||
config_api,
|
config_api,
|
||||||
database_api,
|
database_api,
|
||||||
emoji_api,
|
emoji_api,
|
||||||
|
expression_api,
|
||||||
generator_api,
|
generator_api,
|
||||||
llm_api,
|
llm_api,
|
||||||
message_api,
|
message_api,
|
||||||
@@ -38,6 +39,7 @@ __all__ = [
|
|||||||
"context_api",
|
"context_api",
|
||||||
"database_api",
|
"database_api",
|
||||||
"emoji_api",
|
"emoji_api",
|
||||||
|
"expression_api",
|
||||||
"generator_api",
|
"generator_api",
|
||||||
"get_logger",
|
"get_logger",
|
||||||
"llm_api",
|
"llm_api",
|
||||||
|
|||||||
1026
src/plugin_system/apis/expression_api.py
Normal file
1026
src/plugin_system/apis/expression_api.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -116,8 +116,24 @@ async def get_person_points(person_id: str, limit: int = 5) -> list[tuple]:
|
|||||||
if not points:
|
if not points:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
# 验证 points 是列表类型
|
||||||
|
if not isinstance(points, list):
|
||||||
|
logger.warning(f"[PersonAPI] 用户记忆点数据类型错误: person_id={person_id}, type={type(points)}, value={points}")
|
||||||
|
return []
|
||||||
|
|
||||||
|
# 过滤掉格式不正确的记忆点 (应该是包含至少3个元素的元组或列表)
|
||||||
|
valid_points = []
|
||||||
|
for point in points:
|
||||||
|
if isinstance(point, list | tuple) and len(point) >= 3:
|
||||||
|
valid_points.append(point)
|
||||||
|
else:
|
||||||
|
logger.warning(f"[PersonAPI] 跳过格式错误的记忆点: person_id={person_id}, point={point}")
|
||||||
|
|
||||||
|
if not valid_points:
|
||||||
|
return []
|
||||||
|
|
||||||
# 按权重和时间排序,返回最重要的几个点
|
# 按权重和时间排序,返回最重要的几个点
|
||||||
sorted_points = sorted(points, key=lambda x: (x[1], x[2]), reverse=True)
|
sorted_points = sorted(valid_points, key=lambda x: (x[1], x[2]), reverse=True)
|
||||||
return sorted_points[:limit]
|
return sorted_points[:limit]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"[PersonAPI] 获取用户记忆点失败: person_id={person_id}, error={e}")
|
logger.error(f"[PersonAPI] 获取用户记忆点失败: person_id={person_id}, error={e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user