Spaces:
Sleeping
Sleeping
Tuchuanhuhuhu commited on
Commit ·
f90157b
1
Parent(s): bb60438
修复历史记录加载功能
Browse files
utils.py
CHANGED
|
@@ -251,10 +251,16 @@ def save_chat_history(filename, system, history, chatbot):
|
|
| 251 |
|
| 252 |
def load_chat_history(filename, system, history, chatbot):
|
| 253 |
try:
|
| 254 |
-
print("Loading from history...")
|
| 255 |
with open(os.path.join(HISTORY_DIR, filename), "r") as f:
|
| 256 |
json_s = json.load(f)
|
| 257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
return filename, json_s["system"], json_s["history"], json_s["chatbot"]
|
| 259 |
except FileNotFoundError:
|
| 260 |
print("File not found.")
|
|
|
|
| 251 |
|
| 252 |
def load_chat_history(filename, system, history, chatbot):
|
| 253 |
try:
|
|
|
|
| 254 |
with open(os.path.join(HISTORY_DIR, filename), "r") as f:
|
| 255 |
json_s = json.load(f)
|
| 256 |
+
if type(json_s["history"]) == list:
|
| 257 |
+
new_history = []
|
| 258 |
+
for index, item in enumerate(json_s["history"]):
|
| 259 |
+
if index % 2 == 0:
|
| 260 |
+
new_history.append(construct_user(item))
|
| 261 |
+
else:
|
| 262 |
+
new_history.append(construct_assistant(item))
|
| 263 |
+
json_s["history"] = new_history
|
| 264 |
return filename, json_s["system"], json_s["history"], json_s["chatbot"]
|
| 265 |
except FileNotFoundError:
|
| 266 |
print("File not found.")
|