1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import time
- from tqdm import tqdm
- from module.qa_chain import QAChain
- from utils.logger_config import setup_logger
- logger = setup_logger(__name__)
- # def auto_runtest(test_file, save_file):
- # custom_config = "config/qa_config.json"
- # custom_chain = QAChain(config_path=custom_config)
- # test_case = []
- # with open(test_file, 'r', encoding='utf-8') as file:
- # for line in file:
- # if "客户" in line:
- # test_case.append(line.strip())
- # with open(save_file, 'w', encoding='utf-8') as file:
- # for case in tqdm(test_case):
- # file.write(f"用户:{case}\n")
- # result = custom_chain.invoke({"question":case})
- # file.write(f"回答:{result['answer']}\n")
- # file.write("\n")
- def auto_runtest(test_file, save_file):
- try:
- custom_config = "config/qa_config.json"
- custom_chain = QAChain(config_path=custom_config)
- test_case = []
- with open(test_file, 'r', encoding='utf-8') as file:
- for line in file:
- if "客户" in line:
- test_case.append(line.strip())
- with open(save_file, 'w', encoding='utf-8') as file:
- for case in tqdm(test_case):
- try:
- file.write(f"{case}\n")
- result = custom_chain.invoke({"question": case})
- answer = result.get('answer', '系统无响应')
- file.write(f"回答:{answer}\n")
- except Exception as e:
- logger.error(f"处理案例失败: {case}, 错误: {str(e)}")
- file.write(f"回答:系统处理失败,请稍后重试\n")
- finally:
- file.write("\n")
-
- except Exception as e:
- logger.error(f"测试执行失败: {str(e)}")
- with open(save_file, 'w', encoding='utf-8') as file:
- file.write(f"测试执行错误: {str(e)}")
- if __name__ == "__main__":
- # 使用自定义配置文件
- label = input("请输入标签: ")
- test_file = f"./test_case/{label}_测试用例.txt"
- save_file = f"./test_result/{label}_deepseek0324.txt"
- auto_runtest(test_file, save_file)
|