优化对比测试器,调整最大工作线程数为5,并改用多线程并发处理问题,提升处理效率。

This commit is contained in:
2025-05-28 16:15:42 +08:00
parent 6d9412b244
commit 54f81dfcbc
Regular → Executable
+18 -8
View File
@@ -29,7 +29,7 @@ class DifyComparisonTester:
Dify新旧流程对比测试类,用于比较两个不同流程的问答效果并进行评判
"""
def __init__(self, excel_path:str, baseurl:str, old_workflow_api_key:str, new_workflow_api_key:str,
wiki_excel_path:str=None, output_path:str=None, max_workers:int=10):
wiki_excel_path:str=None, output_path:str=None, max_workers:int=5):
"""
初始化对比测试器
@@ -473,13 +473,23 @@ content: "{content}"
# 选择处理函数
process_func = self.process_question_with_judge if with_judge else self.process_question
# 按顺序处理问题
with tqdm(total=len(questions), desc="处理问题进度") as pbar:
for q in questions:
result = process_func(q)
if result is not None:
results.append(result)
pbar.update(1)
# 使用多线程并发处理问题
with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
# 创建进度条
with tqdm(total=len(questions), desc="处理问题进度") as pbar:
# 提交所有任务
futures = []
for q in questions:
future = executor.submit(process_func, q)
futures.append(future)
# 处理结果
for future in as_completed(futures):
result = future.result()
if result is not None:
with self.results_lock:
results.append(result)
pbar.update(1)
# 生成输出Excel文件
out_path = self.output_path if with_judge else os.path.join(os.path.dirname(self.excel_path), "dify问答_对比结果.xlsx")