Tuchuanhuhuhu commited on
Commit
d759751
·
1 Parent(s): 52bb644

修复加载旧式历史记录出错的问题

Browse files
Files changed (1) hide show
  1. utils.py +14 -9
utils.py CHANGED
@@ -286,15 +286,20 @@ def load_chat_history(filename, system, history, chatbot):
286
  try:
287
  with open(os.path.join(HISTORY_DIR, filename), "r") as f:
288
  json_s = json.load(f)
289
- if type(json_s["history"]) == list:
290
- print("历史记录格式为旧版,正在转换……")
291
- new_history = []
292
- for index, item in enumerate(json_s["history"]):
293
- if index % 2 == 0:
294
- new_history.append(construct_user(item))
295
- else:
296
- new_history.append(construct_assistant(item))
297
- json_s["history"] = new_history
 
 
 
 
 
298
  print("加载对话历史完毕")
299
  return filename, json_s["system"], json_s["history"], json_s["chatbot"]
300
  except FileNotFoundError:
 
286
  try:
287
  with open(os.path.join(HISTORY_DIR, filename), "r") as f:
288
  json_s = json.load(f)
289
+ try:
290
+ if type(json_s["history"][0]) == str:
291
+ print("历史记录格式为旧版,正在转换……")
292
+ new_history = []
293
+ for index, item in enumerate(json_s["history"]):
294
+ if index % 2 == 0:
295
+ new_history.append(construct_user(item))
296
+ else:
297
+ new_history.append(construct_assistant(item))
298
+ json_s["history"] = new_history
299
+ print(new_history)
300
+ except:
301
+ # 没有对话历史
302
+ pass
303
  print("加载对话历史完毕")
304
  return filename, json_s["system"], json_s["history"], json_s["chatbot"]
305
  except FileNotFoundError: