Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -130,9 +130,15 @@ def add_memory():
|
|
| 130 |
return jsonify({"error": "No content provided"}), 400
|
| 131 |
|
| 132 |
try:
|
| 133 |
-
# FIX: Pass
|
| 134 |
-
#
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
# Force flush by deleting reference (Rust Drop trait)
|
| 138 |
del db
|
|
@@ -143,7 +149,6 @@ def add_memory():
|
|
| 143 |
|
| 144 |
return jsonify({"success": True, "message": "Memory added and synced to cloud."})
|
| 145 |
except Exception as e:
|
| 146 |
-
# Re-init db if something crashed so next request works
|
| 147 |
if db is None: init_db()
|
| 148 |
return jsonify({"error": str(e)}), 500
|
| 149 |
|
|
@@ -157,13 +162,12 @@ def search_memory():
|
|
| 157 |
return jsonify({"error": "No query provided"}), 400
|
| 158 |
|
| 159 |
try:
|
| 160 |
-
# FIX: Pass
|
| 161 |
-
#
|
| 162 |
results = db.find(query, top_k=5)
|
| 163 |
|
| 164 |
formatted_results = []
|
| 165 |
for hit in results:
|
| 166 |
-
# Handle result object vs dict safety
|
| 167 |
if isinstance(hit, dict):
|
| 168 |
text = hit.get('text') or hit.get('content') or "No text"
|
| 169 |
else:
|
|
|
|
| 130 |
return jsonify({"error": "No content provided"}), 400
|
| 131 |
|
| 132 |
try:
|
| 133 |
+
# FIX: Pass a Dictionary with a 'text' key.
|
| 134 |
+
# This solves "unexpected keyword argument 'text'" (from db.put(text=...))
|
| 135 |
+
# AND "str cannot be converted to PyDict" (from db.put("string"))
|
| 136 |
+
payload = {
|
| 137 |
+
"text": content,
|
| 138 |
+
"title": "User Memory",
|
| 139 |
+
"tag": "web-entry"
|
| 140 |
+
}
|
| 141 |
+
db.put(payload)
|
| 142 |
|
| 143 |
# Force flush by deleting reference (Rust Drop trait)
|
| 144 |
del db
|
|
|
|
| 149 |
|
| 150 |
return jsonify({"success": True, "message": "Memory added and synced to cloud."})
|
| 151 |
except Exception as e:
|
|
|
|
| 152 |
if db is None: init_db()
|
| 153 |
return jsonify({"error": str(e)}), 500
|
| 154 |
|
|
|
|
| 162 |
return jsonify({"error": "No query provided"}), 400
|
| 163 |
|
| 164 |
try:
|
| 165 |
+
# FIX: Pass string as positional arg, top_k as keyword.
|
| 166 |
+
# This solves "dict cannot be converted to PyString"
|
| 167 |
results = db.find(query, top_k=5)
|
| 168 |
|
| 169 |
formatted_results = []
|
| 170 |
for hit in results:
|
|
|
|
| 171 |
if isinstance(hit, dict):
|
| 172 |
text = hit.get('text') or hit.get('content') or "No text"
|
| 173 |
else:
|