Spaces:
Sleeping
Sleeping
Update session_manager.py
Browse files- session_manager.py +15 -2
session_manager.py
CHANGED
@@ -26,7 +26,11 @@ class SessionManager:
|
|
26 |
"""Load session data or create new if not found"""
|
27 |
try:
|
28 |
with open(self.sessions_dir / f"{session_id}.json") as f:
|
29 |
-
|
|
|
|
|
|
|
|
|
30 |
except FileNotFoundError:
|
31 |
return self.create_session()
|
32 |
|
@@ -34,5 +38,14 @@ class SessionManager:
|
|
34 |
"""Reset session while keeping ID"""
|
35 |
self.save_session(session_id, {
|
36 |
"created_at": datetime.now().isoformat(),
|
37 |
-
"history": []
|
|
|
38 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
"""Load session data or create new if not found"""
|
27 |
try:
|
28 |
with open(self.sessions_dir / f"{session_id}.json") as f:
|
29 |
+
data = json.load(f)
|
30 |
+
# Ensure history exists for backward compatibility
|
31 |
+
if "history" not in data:
|
32 |
+
data["history"] = []
|
33 |
+
return data
|
34 |
except FileNotFoundError:
|
35 |
return self.create_session()
|
36 |
|
|
|
38 |
"""Reset session while keeping ID"""
|
39 |
self.save_session(session_id, {
|
40 |
"created_at": datetime.now().isoformat(),
|
41 |
+
"history": [],
|
42 |
+
"context": {} # Add context storage
|
43 |
})
|
44 |
+
|
45 |
+
def update_context(self, session_id: str, context: dict):
|
46 |
+
"""Update session context with new data"""
|
47 |
+
session = self.load_session(session_id)
|
48 |
+
if "context" not in session:
|
49 |
+
session["context"] = {}
|
50 |
+
session["context"].update(context)
|
51 |
+
self.save_session(session_id, session)
|