|
@@ -12,8 +12,8 @@ from pathlib import Path
|
|
|
from agents import trace
|
|
from agents import trace
|
|
|
from agents.tracing.create import custom_span
|
|
from agents.tracing.create import custom_span
|
|
|
from lib.my_trace import set_trace_smith as set_trace
|
|
from lib.my_trace import set_trace_smith as set_trace
|
|
|
-from lib.match_analyzer import match_batch
|
|
|
|
|
-from lib.data_loader import load_persona_data, load_inspiration_data, select_inspiration
|
|
|
|
|
|
|
+from lib.match_analyzer import match_single
|
|
|
|
|
+from lib.data_loader import load_persona_data, load_inspiration_list, select_inspiration
|
|
|
|
|
|
|
|
# 模型配置
|
|
# 模型配置
|
|
|
MODEL_NAME = "google/gemini-2.5-pro"
|
|
MODEL_NAME = "google/gemini-2.5-pro"
|
|
@@ -135,19 +135,27 @@ async def process_step2_incremental_match(
|
|
|
},
|
|
},
|
|
|
"灵感": step1_inspiration,
|
|
"灵感": step1_inspiration,
|
|
|
"输入信息": {
|
|
"输入信息": {
|
|
|
- "B": [],
|
|
|
|
|
|
|
+ "B": "", # 空字符串
|
|
|
"A": persona_system_text,
|
|
"A": persona_system_text,
|
|
|
"B_Context": b_context, # 使用统一构造的 context
|
|
"B_Context": b_context, # 使用统一构造的 context
|
|
|
"A_Context": ""
|
|
"A_Context": ""
|
|
|
},
|
|
},
|
|
|
"step1_结果": step1_top1,
|
|
"step1_结果": step1_top1,
|
|
|
- "匹配结果": []
|
|
|
|
|
|
|
+ "匹配结果": {
|
|
|
|
|
+ "score": 0.0,
|
|
|
|
|
+ "score说明": "无增量词",
|
|
|
|
|
+ "相同部分": {},
|
|
|
|
|
+ "增量部分": {}
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
print(f"\n开始增量词匹配分析: {step1_inspiration}")
|
|
print(f"\n开始增量词匹配分析: {step1_inspiration}")
|
|
|
print(f"匹配要素: {matched_element}")
|
|
print(f"匹配要素: {matched_element}")
|
|
|
print(f"增量词数量: {len(incremental_words)}, 模型: {MODEL_NAME}\n")
|
|
print(f"增量词数量: {len(incremental_words)}, 模型: {MODEL_NAME}\n")
|
|
|
|
|
|
|
|
|
|
+ # 将增量词列表拼接成一个字符串(用换行符分隔)
|
|
|
|
|
+ b_content = "\n".join(incremental_words)
|
|
|
|
|
+
|
|
|
# 使用 custom_span 标识整个流程
|
|
# 使用 custom_span 标识整个流程
|
|
|
with custom_span(
|
|
with custom_span(
|
|
|
name=f"Step2: 增量词匹配 - {step1_inspiration}",
|
|
name=f"Step2: 增量词匹配 - {step1_inspiration}",
|
|
@@ -159,18 +167,14 @@ async def process_step2_incremental_match(
|
|
|
"步骤": "增量词在人设中的匹配分析"
|
|
"步骤": "增量词在人设中的匹配分析"
|
|
|
}
|
|
}
|
|
|
):
|
|
):
|
|
|
- # 调用通用批量匹配模块
|
|
|
|
|
- match_results = await match_batch(
|
|
|
|
|
- b_items=incremental_words,
|
|
|
|
|
|
|
+ # 调用通用匹配模块(单次调用)
|
|
|
|
|
+ match_result = await match_single(
|
|
|
|
|
+ b_content=b_content,
|
|
|
a_content=persona_system_text,
|
|
a_content=persona_system_text,
|
|
|
model_name=MODEL_NAME,
|
|
model_name=MODEL_NAME,
|
|
|
b_context=b_context
|
|
b_context=b_context
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- # 按 score 降序排序
|
|
|
|
|
- if isinstance(match_results, list):
|
|
|
|
|
- match_results.sort(key=lambda x: x.get('score', 0), reverse=True)
|
|
|
|
|
-
|
|
|
|
|
# 构建输出(使用统一构造的变量)
|
|
# 构建输出(使用统一构造的变量)
|
|
|
return {
|
|
return {
|
|
|
"元数据": {
|
|
"元数据": {
|
|
@@ -181,12 +185,12 @@ async def process_step2_incremental_match(
|
|
|
},
|
|
},
|
|
|
"灵感": step1_inspiration,
|
|
"灵感": step1_inspiration,
|
|
|
"输入信息": {
|
|
"输入信息": {
|
|
|
- "B": incremental_words,
|
|
|
|
|
|
|
+ "B": b_content, # 拼接后的字符串
|
|
|
"A": persona_system_text,
|
|
"A": persona_system_text,
|
|
|
"B_Context": b_context, # 使用统一构造的 context
|
|
"B_Context": b_context, # 使用统一构造的 context
|
|
|
"A_Context": ""
|
|
"A_Context": ""
|
|
|
},
|
|
},
|
|
|
- "匹配结果": match_results,
|
|
|
|
|
|
|
+ "匹配结果": match_result, # 单个匹配结果对象
|
|
|
"step1_结果": step1_top1,
|
|
"step1_结果": step1_top1,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -205,8 +209,7 @@ async def main(current_time: str, log_url: str):
|
|
|
|
|
|
|
|
# 加载数据
|
|
# 加载数据
|
|
|
persona_data = load_persona_data(persona_dir)
|
|
persona_data = load_persona_data(persona_dir)
|
|
|
- inspiration_data = load_inspiration_data(persona_dir)
|
|
|
|
|
- inspiration_list = [item["灵感点"] for item in inspiration_data]
|
|
|
|
|
|
|
+ inspiration_list = load_inspiration_list(persona_dir)
|
|
|
test_inspiration = select_inspiration(inspiration_arg, inspiration_list)
|
|
test_inspiration = select_inspiration(inspiration_arg, inspiration_list)
|
|
|
|
|
|
|
|
# 查找并加载 step1 结果
|
|
# 查找并加载 step1 结果
|