优化对比测试器,调整最大工作线程数为5,并改用多线程并发处理问题,提升处理效率。
This commit is contained in:
Regular → Executable
+13
-3
@@ -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,11 +473,21 @@ content: "{content}"
|
||||
# 选择处理函数
|
||||
process_func = self.process_question_with_judge if with_judge else self.process_question
|
||||
|
||||
# 按顺序处理问题
|
||||
# 使用多线程并发处理问题
|
||||
with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
|
||||
# 创建进度条
|
||||
with tqdm(total=len(questions), desc="处理问题进度") as pbar:
|
||||
# 提交所有任务
|
||||
futures = []
|
||||
for q in questions:
|
||||
result = process_func(q)
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user