refactor(embedding/reranker): 重构模型工具类使用环境变量配置
更新.gitignore文件,添加新的数据库文件 在.env中添加EMBEDDING_MODEL_NAME和XINFERENCE_URL配置 重构SiliconFlowEmbeddings和XinferenceReRankerModel使用环境变量 优化DifyCompareTest异常处理和输入验证 修改测试文件路径和并发工作数
This commit is contained in:
@@ -121,26 +121,38 @@ class DifyCompareTest:
|
||||
time.sleep(10) # 等待1秒后重试
|
||||
|
||||
def get_wiki_list_by_msgid(self,msg_id):
|
||||
if msg_id is None or pd.isna(msg_id):
|
||||
try:
|
||||
if msg_id is None or pd.isna(msg_id):
|
||||
return ""
|
||||
msg_debug_info = self.exporter.dify_tool.get_message_debug_info_by_id(msg_id)
|
||||
if not msg_debug_info:
|
||||
return ""
|
||||
wiki_list = self.exporter.get_wiki_list(msg_debug_info)
|
||||
if len(wiki_list) == 0:
|
||||
return ""
|
||||
else:
|
||||
return "\n".join(list(set(wiki_list)))
|
||||
except Exception as e:
|
||||
logging.error(f"获取词条列表失败: {e}")
|
||||
return ""
|
||||
msg_debug_info = self.exporter.dify_tool.get_message_debug_info_by_id(msg_id)
|
||||
if not msg_debug_info:
|
||||
return ""
|
||||
wiki_list = self.exporter.get_wiki_list(msg_debug_info)
|
||||
if len(wiki_list) == 0:
|
||||
return ""
|
||||
else:
|
||||
return "\n".join(list(set(wiki_list)))
|
||||
|
||||
def process_single_row(self, index, row):
|
||||
"""处理单行数据的方法"""
|
||||
try:
|
||||
query = row["提问"]
|
||||
current_software = row["当前软件"]
|
||||
if pd.isna(query) or len(query) == 0 or pd.isna(current_software) or len(current_software) == 0:
|
||||
result_row = row.copy()
|
||||
result_row["message_id"] = ''
|
||||
result_row["本次回答"] = ''
|
||||
result_row["回答对比"] = ''
|
||||
result_row["检索到的词条"] = ''
|
||||
return index, result_row
|
||||
|
||||
if "回答" in row:
|
||||
old_answer = row["回答"]
|
||||
else:
|
||||
old_answer = ""
|
||||
current_software = row["当前软件"]
|
||||
|
||||
inputs = {
|
||||
"current_softname": current_software,
|
||||
@@ -247,14 +259,14 @@ if __name__ == "__main__":
|
||||
|
||||
# 处理第一个文件
|
||||
excel_files = [
|
||||
("data/excel/300专业提问.xlsx", "data/excel/300专业提问_问答测试.xlsx"),
|
||||
("data/excel/第一轮的专业问题.xlsx", "data/excel/第一轮的专业问题_dify.xlsx"),
|
||||
# ("data/excel/有知识的.xlsx", "data/excel/有知识的_问答测试.xlsx")
|
||||
]
|
||||
|
||||
for excel_path, save_path in excel_files:
|
||||
logging.info(f"开始处理文件: {excel_path}")
|
||||
try:
|
||||
dify_compare_test.run(excel_path=excel_path, save_path=save_path, max_workers=10)
|
||||
dify_compare_test.run(excel_path=excel_path, save_path=save_path, max_workers=5)
|
||||
logging.info(f"文件处理完成: {excel_path}")
|
||||
except Exception as e:
|
||||
logging.error(f"处理文件 {excel_path} 时出错: {e}")
|
||||
|
||||
Reference in New Issue
Block a user