JohnSmith9982 commited on
Commit
102761b
1 Parent(s): 945f2c1

Update modules/index_func.py

Browse files
Files changed (1) hide show
  1. modules/index_func.py +5 -1
modules/index_func.py CHANGED
@@ -116,7 +116,9 @@ def construct_index(
116
  model=os.environ["AZURE_EMBEDDING_MODEL_NAME"], openai_api_base=os.environ["AZURE_OPENAI_API_BASE_URL"], openai_api_type="azure")
117
  if os.path.exists(index_path):
118
  logging.info("找到了缓存的索引文件,加载中……")
119
- return FAISS.load_local(index_path, embeddings)
 
 
120
  else:
121
  try:
122
  documents = get_documents(file_src)
@@ -127,10 +129,12 @@ def construct_index(
127
  os.makedirs("./index", exist_ok=True)
128
  index.save_local(index_path)
129
  logging.debug("索引已保存至本地!")
 
130
  return index
131
 
132
  except Exception as e:
133
  import traceback
134
  logging.error("索引构建失败!%s", e)
135
  traceback.print_exc()
 
136
  return None
 
116
  model=os.environ["AZURE_EMBEDDING_MODEL_NAME"], openai_api_base=os.environ["AZURE_OPENAI_API_BASE_URL"], openai_api_type="azure")
117
  if os.path.exists(index_path):
118
  logging.info("找到了缓存的索引文件,加载中……")
119
+ index = FAISS.load_local(index_path, embeddings)
120
+ os.environ["OPENAI_API_KEY"] = ""
121
+ return index
122
  else:
123
  try:
124
  documents = get_documents(file_src)
 
129
  os.makedirs("./index", exist_ok=True)
130
  index.save_local(index_path)
131
  logging.debug("索引已保存至本地!")
132
+ os.environ["OPENAI_API_KEY"] = ""
133
  return index
134
 
135
  except Exception as e:
136
  import traceback
137
  logging.error("索引构建失败!%s", e)
138
  traceback.print_exc()
139
+ os.environ["OPENAI_API_KEY"] = ""
140
  return None