Spaces:
Running
Running
Update utils.py
Browse files
utils.py
CHANGED
@@ -44,25 +44,20 @@ def save_chat_history(history, filename=None):
|
|
44 |
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
45 |
filename = f"chat_history_{timestamp}.json"
|
46 |
with open(os.path.join("history", filename), "w") as f:
|
47 |
-
json.dump(history, f, indent=4)
|
48 |
return filename
|
49 |
|
50 |
-
def
|
51 |
"""
|
52 |
-
|
53 |
"""
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
return json.load(f)
|
58 |
-
else:
|
59 |
-
st.warning("No chat history found with that filename.")
|
60 |
-
return []
|
61 |
|
62 |
-
def
|
63 |
"""
|
64 |
-
|
65 |
"""
|
66 |
-
|
67 |
-
|
68 |
-
return sorted([f for f in os.listdir(history_dir) if f.endswith(".json")])
|
|
|
44 |
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
45 |
filename = f"chat_history_{timestamp}.json"
|
46 |
with open(os.path.join("history", filename), "w") as f:
|
47 |
+
json.dump(history, f, indent=4, ensure_ascii=False)
|
48 |
return filename
|
49 |
|
50 |
+
def list_chat_histories():
|
51 |
"""
|
52 |
+
List all chat history filenames.
|
53 |
"""
|
54 |
+
folder = "history"
|
55 |
+
os.makedirs(folder, exist_ok=True)
|
56 |
+
return [f for f in os.listdir(folder) if f.endswith(".json")]
|
|
|
|
|
|
|
|
|
57 |
|
58 |
+
def load_chat_history(filename):
|
59 |
"""
|
60 |
+
Load a specific chat history file.
|
61 |
"""
|
62 |
+
with open(os.path.join("history", filename), "r") as f:
|
63 |
+
return json.load(f)
|
|