Spaces:
Paused
Paused
Update app.py
Browse files129 unmodified lines1301311321331341351361371384 unmodified lines1431441451461471481497 unmodified lines157158159160161162163164165166167168169129 unmodified linesreturn jsonify({"error": "No content provided"}), 400try:# FIX: Pass arguments as labels (Keyword Arguments), NOT as a dict object.# "put requires labels" means db.put(text=...) not db.put({"text":...})db.put(text=content, title="User Memory", tag="web-entry")# Force flush by deleting reference (Rust Drop trait)del db4 unmodified linesreturn jsonify({"success": True, "message": "Memory added and synced to cloud."})except Exception as e:# Re-init db if something crashed so next request worksif db is None: init_db()return jsonify({"error": str(e)}), 5007 unmodified linesreturn jsonify({"error": "No query provided"}), 400try:# FIX: Pass query as positional string, options as kwargs.# Previous error: "dict cannot be converted to PyString" -> means first arg must be string.results = db.find(query, top_k=5)formatted_results = []for hit in results:# Handle result object vs dict safetyif isinstance(hit, dict):text = hit.get('text') or hit.get('content') or "No text"else:129 unmodified lines1301311321331341351361371381391401411421431444 unmodified lines1491501511521531547 unmodified lines162163164165166167168169170171172173129 unmodified linesreturn jsonify({"error": "No content provided"}), 400try:# FIX: Pass a Dictionary with a 'text' key.# This solves "unexpected keyword argument 'text'" (from db.put(text=...))# AND "str cannot be converted to PyDict" (from db.put("string"))payload = {"text": content,"title": "User Memory","tag": "web-entry"}db.put(payload)# Force flush by deleting reference (Rust Drop trait)del db4 unmodified linesreturn jsonify({"success": True, "message": "Memory added and synced to cloud."})except Exception as e:if db is None: init_db()return jsonify({"error": str(e)}), 5007 unmodified linesreturn jsonify({"error": "No query provided"}), 400try:# FIX: Pass string as positional arg, top_k as keyword.# This solves "dict cannot be converted to PyString"results = db.find(query, top_k=5)formatted_results = []for hit in results:if isinstance(hit, dict):text = hit.get('text') or hit.get('content') or "No text"else:
app.py+11-7