优化对比测试器,调整最大工作线程数为5,并改用多线程并发处理问题,提升处理效率。
This commit is contained in:
Regular → Executable
+18
-8
@@ -29,7 +29,7 @@ class DifyComparisonTester:
|
|||||||
Dify新旧流程对比测试类,用于比较两个不同流程的问答效果并进行评判
|
Dify新旧流程对比测试类,用于比较两个不同流程的问答效果并进行评判
|
||||||
"""
|
"""
|
||||||
def __init__(self, excel_path:str, baseurl:str, old_workflow_api_key:str, new_workflow_api_key:str,
|
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
|
process_func = self.process_question_with_judge if with_judge else self.process_question
|
||||||
|
|
||||||
# 按顺序处理问题
|
# 使用多线程并发处理问题
|
||||||
with tqdm(total=len(questions), desc="处理问题进度") as pbar:
|
with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
|
||||||
for q in questions:
|
# 创建进度条
|
||||||
result = process_func(q)
|
with tqdm(total=len(questions), desc="处理问题进度") as pbar:
|
||||||
if result is not None:
|
# 提交所有任务
|
||||||
results.append(result)
|
futures = []
|
||||||
pbar.update(1)
|
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文件
|
# 生成输出Excel文件
|
||||||
out_path = self.output_path if with_judge else os.path.join(os.path.dirname(self.excel_path), "dify问答_对比结果.xlsx")
|
out_path = self.output_path if with_judge else os.path.join(os.path.dirname(self.excel_path), "dify问答_对比结果.xlsx")
|
||||||
|
|||||||
Reference in New Issue
Block a user