Spaces:
Paused
Paused
Update memory.py
Browse files
memory.py
CHANGED
|
@@ -12,6 +12,7 @@ CREATE TABLE IF NOT EXISTS conversations (
|
|
| 12 |
""")
|
| 13 |
conn.commit()
|
| 14 |
|
|
|
|
| 15 |
def save_message(user_id, role, content):
|
| 16 |
cursor.execute(
|
| 17 |
"INSERT INTO conversations VALUES (?, ?, ?)",
|
|
@@ -19,6 +20,7 @@ def save_message(user_id, role, content):
|
|
| 19 |
)
|
| 20 |
conn.commit()
|
| 21 |
|
|
|
|
| 22 |
def load_memory(user_id, limit=6):
|
| 23 |
cursor.execute("""
|
| 24 |
SELECT role, content FROM conversations
|
|
@@ -28,5 +30,11 @@ def load_memory(user_id, limit=6):
|
|
| 28 |
""", (user_id, limit))
|
| 29 |
|
| 30 |
rows = cursor.fetchall()
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
""")
|
| 13 |
conn.commit()
|
| 14 |
|
| 15 |
+
|
| 16 |
def save_message(user_id, role, content):
|
| 17 |
cursor.execute(
|
| 18 |
"INSERT INTO conversations VALUES (?, ?, ?)",
|
|
|
|
| 20 |
)
|
| 21 |
conn.commit()
|
| 22 |
|
| 23 |
+
|
| 24 |
def load_memory(user_id, limit=6):
|
| 25 |
cursor.execute("""
|
| 26 |
SELECT role, content FROM conversations
|
|
|
|
| 30 |
""", (user_id, limit))
|
| 31 |
|
| 32 |
rows = cursor.fetchall()
|
| 33 |
+
|
| 34 |
+
# Convert into LLM message format
|
| 35 |
+
formatted = [
|
| 36 |
+
{"role": role, "content": content}
|
| 37 |
+
for role, content in reversed(rows)
|
| 38 |
+
]
|
| 39 |
+
|
| 40 |
+
return formatted
|