|
|
@@ -167,7 +167,7 @@ def _parse_derived_list(derived_items: list[dict[str, str]]) -> list[tuple[str,
|
|
|
description="获取指定账号人设树中的常量节点(全局常量、局部常量),并检查每个节点与帖子选题点的匹配情况。"
|
|
|
"功能:根据账号名查询该账号人设树中所有常量节点,同时对每个节点判断是否匹配帖子选题点,匹配结果直接包含在返回数据中。"
|
|
|
"参数:account_name 为账号名;post_id 为帖子ID,用于加载帖子选题点并做匹配判断。"
|
|
|
- "返回:ToolResult,output 为可读的节点列表文本,metadata.items 为列表,每项含「节点名称」「概率」「常量类型」「帖子选题点匹配」(超过阈值的匹配列表,每项含帖子选题点与匹配分数;若无匹配则为字符串'无匹配帖子选题点')。"
|
|
|
+ "返回:ToolResult,output 为可读的节点列表文本,metadata.items 为列表,每项含「节点名称」「概率」「常量类型」「帖子选题点匹配」=无/匹配结果(无匹配时为「无」,有匹配时为匹配列表,每项含帖子选题点与匹配分数)。"
|
|
|
)
|
|
|
async def find_tree_constant_nodes(
|
|
|
account_name: str,
|
|
|
@@ -190,7 +190,7 @@ async def find_tree_constant_nodes(
|
|
|
- output: 可读的节点列表文本(每行:节点名称、概率、常量类型、帖子匹配情况)。
|
|
|
- metadata: 含 account_name、count、items;items 为列表,每项为
|
|
|
{"节点名称": str, "概率": 数值或 None, "常量类型": "全局常量"|"局部常量",
|
|
|
- "帖子选题点匹配": list[{"帖子选题点": str, "匹配分数": float}] 或 "无匹配帖子选题点"}。
|
|
|
+ "帖子选题点匹配": 无匹配时为 "无",有匹配时为 list[{"帖子选题点": str, "匹配分数": float}]}。
|
|
|
- 出错时 error 为错误信息。
|
|
|
"""
|
|
|
tree_dir = _tree_dir(account_name)
|
|
|
@@ -214,18 +214,18 @@ async def find_tree_constant_nodes(
|
|
|
})
|
|
|
for item in items:
|
|
|
matches = node_match_map.get(item["节点名称"], [])
|
|
|
- item["帖子选题点匹配"] = matches if matches else "无匹配帖子选题点"
|
|
|
+ item["帖子选题点匹配"] = matches if matches else "无"
|
|
|
if not items:
|
|
|
output = "未找到常量节点"
|
|
|
else:
|
|
|
lines = []
|
|
|
for x in items:
|
|
|
- match_info = x.get("帖子选题点匹配", "未查询")
|
|
|
+ match_info = x.get("帖子选题点匹配", "无")
|
|
|
if isinstance(match_info, list):
|
|
|
match_str = "、".join(f"{m['帖子选题点']}({m['匹配分数']})" for m in match_info)
|
|
|
else:
|
|
|
match_str = str(match_info)
|
|
|
- lines.append(f"- {x['节点名称']}\t概率={x['概率']}\t{x['常量类型']}\t帖子匹配={match_str}")
|
|
|
+ lines.append(f"- {x['节点名称']}\t概率={x['概率']}\t{x['常量类型']}\t帖子选题点匹配={match_str}")
|
|
|
output = "\n".join(lines)
|
|
|
return ToolResult(
|
|
|
title=f"常量节点 ({account_name})",
|
|
|
@@ -244,7 +244,7 @@ async def find_tree_constant_nodes(
|
|
|
description="按条件概率从人设树中筛选节点,返回达到阈值且按条件概率排序的前 topN 条,并检查每个节点与帖子选题点的匹配情况。"
|
|
|
"功能:根据账号与已推导选题点(可选),筛选人设树中条件概率不低于阈值的节点,同时对每个节点判断是否匹配帖子选题点,匹配结果直接包含在返回数据中。"
|
|
|
"参数:account_name 为账号名;post_id 为帖子ID,用于加载帖子选题点并做匹配判断;derived_items 为已推导选题点列表,每项含 topic(或已推导的选题点)与 source_node(或推导来源人设树节点),可为空,为空时条件概率使用节点自身的 _ratio;conditional_ratio_threshold 为条件概率阈值;top_n 为返回条数上限,默认 100。"
|
|
|
- "返回:ToolResult,output 为可读的节点列表文本,metadata.items 为列表,每项含「节点名称」「条件概率」「父节点名称」「帖子选题点匹配」(超过阈值的匹配列表,每项含帖子选题点与匹配分数;若无匹配则为字符串'无匹配帖子选题点')。"
|
|
|
+ "返回:ToolResult,output 为可读的节点列表文本,metadata.items 为列表,每项含「节点名称」「条件概率」「父节点名称」「帖子选题点匹配」=无/匹配结果(无匹配时为「无」,有匹配时为匹配列表,每项含帖子选题点与匹配分数)。"
|
|
|
)
|
|
|
async def find_tree_nodes_by_conditional_ratio(
|
|
|
account_name: str,
|
|
|
@@ -273,7 +273,7 @@ async def find_tree_nodes_by_conditional_ratio(
|
|
|
- output: 可读的节点列表文本(每行:节点名称、条件概率、父节点名称、帖子匹配情况)。
|
|
|
- metadata: 含 account_name、threshold、top_n、count、items;
|
|
|
items 为列表,每项为 {"节点名称": str, "条件概率": float, "父节点名称": str,
|
|
|
- "帖子选题点匹配": list[{"帖子选题点": str, "匹配分数": float}] 或 "无匹配帖子选题点"}。
|
|
|
+ "帖子选题点匹配": 无匹配时为 "无",有匹配时为 list[{"帖子选题点": str, "匹配分数": float}]}。
|
|
|
- 出错时 error 为错误信息。
|
|
|
"""
|
|
|
tree_dir = _tree_dir(account_name)
|
|
|
@@ -300,19 +300,19 @@ async def find_tree_nodes_by_conditional_ratio(
|
|
|
})
|
|
|
for item in items:
|
|
|
matches = node_match_map.get(item["节点名称"], [])
|
|
|
- item["帖子选题点匹配"] = matches if matches else "无匹配帖子选题点"
|
|
|
+ item["帖子选题点匹配"] = matches if matches else "无"
|
|
|
if not items:
|
|
|
output = f"未找到条件概率 >= {conditional_ratio_threshold} 的节点"
|
|
|
else:
|
|
|
lines = []
|
|
|
for x in items:
|
|
|
- match_info = x.get("帖子选题点匹配", "未查询")
|
|
|
+ match_info = x.get("帖子选题点匹配", "无")
|
|
|
if isinstance(match_info, list):
|
|
|
match_str = "、".join(f"{m['帖子选题点']}({m['匹配分数']})" for m in match_info)
|
|
|
else:
|
|
|
match_str = str(match_info)
|
|
|
lines.append(
|
|
|
- f"- {x['节点名称']}\t条件概率={x['条件概率']}\t父节点={x['父节点名称']}\t帖子匹配={match_str}"
|
|
|
+ f"- {x['节点名称']}\t条件概率={x['条件概率']}\t父节点={x['父节点名称']}\t帖子选题点匹配={match_str}"
|
|
|
)
|
|
|
output = "\n".join(lines)
|
|
|
return ToolResult(
|
|
|
@@ -339,29 +339,30 @@ def main() -> None:
|
|
|
|
|
|
account_name = "家有大志"
|
|
|
post_id = "68fb6a5c000000000302e5de"
|
|
|
- derived_items = [
|
|
|
- {"topic": "分享", "source_node": "分享"},
|
|
|
- {"topic": "叙事结构", "source_node": "叙事结构"},
|
|
|
- ]
|
|
|
+ # derived_items = [
|
|
|
+ # {"topic": "分享", "source_node": "分享"},
|
|
|
+ # {"topic": "叙事结构", "source_node": "叙事结构"},
|
|
|
+ # ]
|
|
|
+ derived_items = [{"source_node":"分享","topic":"分享"},{"source_node":"叙事结构","topic":"叙事结构"},{"source_node":"图片文字","topic":"图片文字"},{"source_node":"补充说明式","topic":"补充说明式"},{"source_node":"幽默化标题","topic":"幽默化标题"},{"source_node":"标题","topic":"标题"}]
|
|
|
conditional_ratio_threshold = 0.1
|
|
|
- top_n = 100
|
|
|
-
|
|
|
- # 1)常量节点(核心函数,无匹配)
|
|
|
- constant_nodes = get_constant_nodes(account_name)
|
|
|
- print(f"账号: {account_name} — 常量节点共 {len(constant_nodes)} 个(前 50 个):")
|
|
|
- for x in constant_nodes[:50]:
|
|
|
- print(f" - {x['节点名称']}\t概率={x['概率']}\t{x['常量类型']}")
|
|
|
- print()
|
|
|
-
|
|
|
- # 2)条件概率节点(核心函数)
|
|
|
- derived_list = _parse_derived_list(derived_items)
|
|
|
- ratio_nodes = get_nodes_by_conditional_ratio(
|
|
|
- account_name, derived_list, conditional_ratio_threshold, top_n
|
|
|
- )
|
|
|
- print(f"条件概率节点 阈值={conditional_ratio_threshold}, top_n={top_n}, 共 {len(ratio_nodes)} 个:")
|
|
|
- for x in ratio_nodes:
|
|
|
- print(f" - {x['节点名称']}\t条件概率={x['条件概率']}\t父节点={x['父节点名称']}")
|
|
|
- print()
|
|
|
+ top_n = 1000
|
|
|
+
|
|
|
+ # # 1)常量节点(核心函数,无匹配)
|
|
|
+ # constant_nodes = get_constant_nodes(account_name)
|
|
|
+ # print(f"账号: {account_name} — 常量节点共 {len(constant_nodes)} 个(前 50 个):")
|
|
|
+ # for x in constant_nodes[:50]:
|
|
|
+ # print(f" - {x['节点名称']}\t概率={x['概率']}\t{x['常量类型']}")
|
|
|
+ # print()
|
|
|
+ #
|
|
|
+ # # 2)条件概率节点(核心函数)
|
|
|
+ # derived_list = _parse_derived_list(derived_items)
|
|
|
+ # ratio_nodes = get_nodes_by_conditional_ratio(
|
|
|
+ # account_name, derived_list, conditional_ratio_threshold, top_n
|
|
|
+ # )
|
|
|
+ # print(f"条件概率节点 阈值={conditional_ratio_threshold}, top_n={top_n}, 共 {len(ratio_nodes)} 个:")
|
|
|
+ # for x in ratio_nodes:
|
|
|
+ # print(f" - {x['节点名称']}\t条件概率={x['条件概率']}\t父节点={x['父节点名称']}")
|
|
|
+ # print()
|
|
|
|
|
|
# 3)有 agent 时通过 tool 接口再跑一遍(含帖子选题点匹配)
|
|
|
if ToolResult is not None:
|