Spaces:
Sleeping
Sleeping
Update agents/memory.py
#19
by Muthuraja18 - opened
- agents/memory.py +64 -4
agents/memory.py
CHANGED
|
@@ -1,13 +1,73 @@
|
|
| 1 |
class Memory:
|
| 2 |
|
| 3 |
def __init__(self):
|
|
|
|
|
|
|
| 4 |
self.chat_history = []
|
|
|
|
|
|
|
| 5 |
self.uploaded_files = []
|
|
|
|
|
|
|
| 6 |
self.last_used_image = None
|
| 7 |
-
self.image_context = None # 🔥 NEW
|
| 8 |
|
| 9 |
-
|
| 10 |
-
self.image_context =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def get_image_context(self):
|
| 13 |
-
return self.image_context
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
class Memory:
|
| 2 |
|
| 3 |
def __init__(self):
|
| 4 |
+
|
| 5 |
+
# Conversation history
|
| 6 |
self.chat_history = []
|
| 7 |
+
|
| 8 |
+
# Uploaded files
|
| 9 |
self.uploaded_files = []
|
| 10 |
+
|
| 11 |
+
# Current image (original or latest edited)
|
| 12 |
self.last_used_image = None
|
|
|
|
| 13 |
|
| 14 |
+
# Full analysis dictionary
|
| 15 |
+
self.image_context = None
|
| 16 |
+
|
| 17 |
+
# Current analysis
|
| 18 |
+
self.analysis = None
|
| 19 |
+
|
| 20 |
+
# --------------------------
|
| 21 |
+
# Chat History
|
| 22 |
+
# --------------------------
|
| 23 |
+
|
| 24 |
+
def add_message(self, role, content):
|
| 25 |
+
self.chat_history.append({
|
| 26 |
+
"role": role,
|
| 27 |
+
"content": content
|
| 28 |
+
})
|
| 29 |
+
|
| 30 |
+
def get_history(self):
|
| 31 |
+
return self.chat_history
|
| 32 |
+
|
| 33 |
+
# --------------------------
|
| 34 |
+
# Uploaded Files
|
| 35 |
+
# --------------------------
|
| 36 |
+
|
| 37 |
+
def add_files(self, files):
|
| 38 |
+
self.uploaded_files.extend(files)
|
| 39 |
+
|
| 40 |
+
# --------------------------
|
| 41 |
+
# Image Context
|
| 42 |
+
# --------------------------
|
| 43 |
+
|
| 44 |
+
def set_image_context(self, analysis):
|
| 45 |
+
"""
|
| 46 |
+
Store the complete image analysis.
|
| 47 |
+
"""
|
| 48 |
+
self.image_context = analysis
|
| 49 |
+
self.analysis = analysis
|
| 50 |
|
| 51 |
def get_image_context(self):
|
| 52 |
+
return self.image_context
|
| 53 |
+
|
| 54 |
+
# --------------------------
|
| 55 |
+
# Current Image
|
| 56 |
+
# --------------------------
|
| 57 |
+
|
| 58 |
+
def set_last_image(self, image_path):
|
| 59 |
+
self.last_used_image = image_path
|
| 60 |
+
|
| 61 |
+
def get_last_image(self):
|
| 62 |
+
return self.last_used_image
|
| 63 |
+
|
| 64 |
+
# --------------------------
|
| 65 |
+
# Clear Memory
|
| 66 |
+
# --------------------------
|
| 67 |
+
|
| 68 |
+
def clear(self):
|
| 69 |
+
self.chat_history.clear()
|
| 70 |
+
self.uploaded_files.clear()
|
| 71 |
+
self.last_used_image = None
|
| 72 |
+
self.image_context = None
|
| 73 |
+
self.analysis = None
|