MZhaovo commited on
Commit
2582c02
1 Parent(s): 77dbcc7

修复历史记录中文编码

Browse files
modules/config.py CHANGED
@@ -43,11 +43,11 @@ hide_history_when_not_logged_in = config.get("hide_history_when_not_logged_in",
43
 
44
  if os.path.exists("api_key.txt"):
45
  logging.info("检测到api_key.txt文件,正在进行迁移...")
46
- with open("api_key.txt", "r") as f:
47
  config["openai_api_key"] = f.read().strip()
48
  os.rename("api_key.txt", "api_key(deprecated).txt")
49
  with open("config.json", "w", encoding='utf-8') as f:
50
- json.dump(config, f, indent=4)
51
 
52
  if os.path.exists("auth.json"):
53
  logging.info("检测到auth.json文件,正在进行迁移...")
@@ -63,7 +63,7 @@ if os.path.exists("auth.json"):
63
  config["users"] = auth_list
64
  os.rename("auth.json", "auth(deprecated).json")
65
  with open("config.json", "w", encoding='utf-8') as f:
66
- json.dump(config, f, indent=4)
67
 
68
  ## 处理docker if we are running in Docker
69
  dockerflag = config.get("dockerflag", False)
 
43
 
44
  if os.path.exists("api_key.txt"):
45
  logging.info("检测到api_key.txt文件,正在进行迁移...")
46
+ with open("api_key.txt", "r", encoding="utf-8") as f:
47
  config["openai_api_key"] = f.read().strip()
48
  os.rename("api_key.txt", "api_key(deprecated).txt")
49
  with open("config.json", "w", encoding='utf-8') as f:
50
+ json.dump(config, f, indent=4, ensure_ascii=False)
51
 
52
  if os.path.exists("auth.json"):
53
  logging.info("检测到auth.json文件,正在进行迁移...")
 
63
  config["users"] = auth_list
64
  os.rename("auth.json", "auth(deprecated).json")
65
  with open("config.json", "w", encoding='utf-8') as f:
66
+ json.dump(config, f, indent=4, ensure_ascii=False)
67
 
68
  ## 处理docker if we are running in Docker
69
  dockerflag = config.get("dockerflag", False)
modules/index_func.py CHANGED
@@ -16,7 +16,7 @@ def get_index_name(file_src):
16
 
17
  md5_hash = hashlib.md5()
18
  for file_path in file_paths:
19
- with open(file_path, "rb") as f:
20
  while chunk := f.read(8192):
21
  md5_hash.update(chunk)
22
 
@@ -47,7 +47,7 @@ def get_documents(file_src):
47
  pdftext = parse_pdf(filepath, two_column).text
48
  except:
49
  pdftext = ""
50
- with open(filepath, "rb") as pdfFileObj:
51
  pdfReader = PyPDF2.PdfReader(pdfFileObj)
52
  for page in tqdm(pdfReader.pages):
53
  pdftext += page.extract_text()
 
16
 
17
  md5_hash = hashlib.md5()
18
  for file_path in file_paths:
19
+ with open(file_path, "rb", encoding="utf-8") as f:
20
  while chunk := f.read(8192):
21
  md5_hash.update(chunk)
22
 
 
47
  pdftext = parse_pdf(filepath, two_column).text
48
  except:
49
  pdftext = ""
50
+ with open(filepath, "rb", encoding="utf-8") as pdfFileObj:
51
  pdfReader = PyPDF2.PdfReader(pdfFileObj)
52
  for page in tqdm(pdfReader.pages):
53
  pdftext += page.extract_text()
modules/models/base_model.py CHANGED
@@ -641,7 +641,7 @@ class BaseLLMModel:
641
  history_file_path = os.path.join(HISTORY_DIR, user_name, filename)
642
  else:
643
  history_file_path = filename
644
- with open(history_file_path, "r") as f:
645
  json_s = json.load(f)
646
  try:
647
  if type(json_s["history"][0]) == str:
 
641
  history_file_path = os.path.join(HISTORY_DIR, user_name, filename)
642
  else:
643
  history_file_path = filename
644
+ with open(history_file_path, "r", encoding="utf-8") as f:
645
  json_s = json.load(f)
646
  try:
647
  if type(json_s["history"][0]) == str:
modules/models/models.py CHANGED
@@ -338,7 +338,7 @@ class LLaMA_Client(BaseLLMModel):
338
  pipeline_args = InferencerArguments(
339
  local_rank=0, random_seed=1, deepspeed='configs/ds_config_chatbot.json', mixed_precision='bf16')
340
 
341
- with open(pipeline_args.deepspeed, "r") as f:
342
  ds_config = json.load(f)
343
  LLAMA_MODEL = AutoModel.get_model(
344
  model_args,
@@ -623,7 +623,7 @@ def get_model(
623
 
624
 
625
  if __name__ == "__main__":
626
- with open("config.json", "r") as f:
627
  openai_api_key = cjson.load(f)["openai_api_key"]
628
  # set logging level to debug
629
  logging.basicConfig(level=logging.DEBUG)
 
338
  pipeline_args = InferencerArguments(
339
  local_rank=0, random_seed=1, deepspeed='configs/ds_config_chatbot.json', mixed_precision='bf16')
340
 
341
+ with open(pipeline_args.deepspeed, "r", encoding="utf-8") as f:
342
  ds_config = json.load(f)
343
  LLAMA_MODEL = AutoModel.get_model(
344
  model_args,
 
623
 
624
 
625
  if __name__ == "__main__":
626
+ with open("config.json", "r", encoding="utf-8") as f:
627
  openai_api_key = cjson.load(f)["openai_api_key"]
628
  # set logging level to debug
629
  logging.basicConfig(level=logging.DEBUG)
modules/utils.py CHANGED
@@ -256,8 +256,8 @@ def save_file(filename, system, history, chatbot, user_name):
256
  history_file_path = filename
257
  else:
258
  history_file_path = os.path.join(HISTORY_DIR, user_name, filename)
259
- with open(history_file_path, "w") as f:
260
- json.dump(json_s, f)
261
  elif filename.endswith(".md"):
262
  md_s = f"system: \n- {system} \n"
263
  for data in history:
@@ -563,7 +563,7 @@ def toggle_like_btn_visibility(selected_model_name):
563
  def new_auto_history_filename(dirname):
564
  latest_file = get_latest_filepath(dirname)
565
  if latest_file:
566
- with open(os.path.join(dirname, latest_file), 'r') as f:
567
  if len(f.read()) == 0:
568
  return latest_file
569
  now = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
 
256
  history_file_path = filename
257
  else:
258
  history_file_path = os.path.join(HISTORY_DIR, user_name, filename)
259
+ with open(history_file_path, "w", encoding='utf-8') as f:
260
+ json.dump(json_s, f, ensure_ascii=False)
261
  elif filename.endswith(".md"):
262
  md_s = f"system: \n- {system} \n"
263
  for data in history:
 
563
  def new_auto_history_filename(dirname):
564
  latest_file = get_latest_filepath(dirname)
565
  if latest_file:
566
+ with open(os.path.join(dirname, latest_file), 'r', encoding="utf-8") as f:
567
  if len(f.read()) == 0:
568
  return latest_file
569
  now = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')