From 54f81dfcbcd44b82f93a52b9ef5d3afe9ba4a54c Mon Sep 17 00:00:00 2001 From: ouyangyouzhang Date: Wed, 28 May 2025 16:15:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AF=B9=E6=AF=94=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=99=A8=EF=BC=8C=E8=B0=83=E6=95=B4=E6=9C=80=E5=A4=A7?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E7=BA=BF=E7=A8=8B=E6=95=B0=E4=B8=BA5?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E6=94=B9=E7=94=A8=E5=A4=9A=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E5=A4=84=E7=90=86=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E5=8D=87=E5=A4=84=E7=90=86=E6=95=88=E7=8E=87=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag2_0/dify/test_dify_chatapi.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) mode change 100644 => 100755 rag2_0/dify/test_dify_chatapi.py diff --git a/rag2_0/dify/test_dify_chatapi.py b/rag2_0/dify/test_dify_chatapi.py old mode 100644 new mode 100755 index 93ca1f9..7969f37 --- a/rag2_0/dify/test_dify_chatapi.py +++ b/rag2_0/dify/test_dify_chatapi.py @@ -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")