refactor: 移除硬编码配置,使用环境变量管理API密钥和路径
重构XinferenceEmbeddings和XinferenceReRankerModel类,移除硬编码的API密钥和路径 统一使用环境变量管理配置,提高安全性和灵活性 修改数据库路径为相对路径,增强可移植性
This commit is contained in:
@@ -462,10 +462,10 @@ class ExcelToSQLiteProcessor:
|
||||
print("数据库事务已提交,连接已关闭")
|
||||
|
||||
class CreateEmbedingData():
|
||||
def __init__(self, db_path, api_key="aa"):
|
||||
def __init__(self, db_path):
|
||||
self.db_path = db_path
|
||||
self.conn = sqlite3.connect(db_path)
|
||||
self.embedding_function = XinferenceEmbeddings(api_key=api_key)
|
||||
self.embedding_function = XinferenceEmbeddings()
|
||||
|
||||
def create_ding_e_zimu_embedding(self):
|
||||
"""创建定额子目名称的向量索引"""
|
||||
@@ -535,22 +535,24 @@ def main():
|
||||
print("开始处理定额库和清单库Excel文件...")
|
||||
|
||||
# 配置参数
|
||||
ding_e_base_dir = "/data/QueryRewrite/data/excel/Excel版 清单定额库/定额库"
|
||||
qing_dan_base_dir = "/data/QueryRewrite/data/excel/Excel版 清单定额库/清单库"
|
||||
db_path = "/data/QueryRewrite/data/db/qingdan_ding_e_ku copy.db"
|
||||
|
||||
ding_e_base_dir = f"{os.getcwd()}/data/excel/Excel版 清单定额库/定额库"
|
||||
qing_dan_base_dir = f"{os.getcwd()}/data/excel/Excel版 清单定额库/清单库"
|
||||
db_path = f"{os.getcwd()}/data/db/qingdan_ding_e_ku.db"
|
||||
if os.path.exists(db_path):
|
||||
print("数据库文件已存在, 任务结束...")
|
||||
return
|
||||
# 创建处理器实例
|
||||
# processor = ExcelToSQLiteProcessor(db_path)
|
||||
processor = ExcelToSQLiteProcessor(db_path)
|
||||
|
||||
try:
|
||||
# 处理定额库文件
|
||||
# processor.process_ding_e_files(ding_e_base_dir)
|
||||
processor.process_ding_e_files(ding_e_base_dir)
|
||||
|
||||
# # 处理清单库文件
|
||||
# processor.process_qing_dan_files(qing_dan_base_dir)
|
||||
processor.process_qing_dan_files(qing_dan_base_dir)
|
||||
|
||||
# # 提交并关闭
|
||||
# processor.commit_and_close()
|
||||
processor.commit_and_close()
|
||||
|
||||
print("=" * 50)
|
||||
print("所有Excel文件处理完成!数据已成功导入SQLite数据库")
|
||||
|
||||
Reference in New Issue
Block a user