maceter636 commited on
Commit
f1b8a2b
·
1 Parent(s): 577ff99

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +22 -6
server.py CHANGED
@@ -81,12 +81,12 @@ def chromadb_add_messages():
81
  for m in data["messages"]
82
  ]
83
 
84
- collection.delete()
85
- collection.upsert(
86
- ids=ids,
87
- documents=documents,
88
- metadatas=metadatas,
89
- )
90
 
91
  return jsonify({"count": len(ids)})
92
 
@@ -137,5 +137,21 @@ def chromadb_query():
137
  ]
138
 
139
  return jsonify(messages)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
 
141
  app.run(host=host, port=port)
 
81
  for m in data["messages"]
82
  ]
83
 
84
+ if len(ids) > 0:
85
+ collection.upsert(
86
+ ids=ids,
87
+ documents=documents,
88
+ metadatas=metadatas,
89
+ )
90
 
91
  return jsonify({"count": len(ids)})
92
 
 
137
  ]
138
 
139
  return jsonify(messages)
140
+
141
+ @app.route("/api/chromadb/purge", methods=["POST"])
142
+ def chromadb_purge():
143
+ data = request.get_json()
144
+ if "chat_id" not in data or not isinstance(data["chat_id"], str):
145
+ abort(400, '"chat_id" is required')
146
+
147
+ ip = get_real_ip()
148
+ chat_id_md5 = hashlib.md5(f'{ip}-{data["chat_id"]}'.encode()).hexdigest()
149
+ collection = chromadb_client.get_or_create_collection(
150
+ name=f"chat-{chat_id_md5}", embedding_function=chromadb_embed_fn
151
+ )
152
+
153
+ deleted = collection.delete()
154
+ print("ChromaDB embeddings deleted", len(deleted))
155
 
156
+ return 'Ok', 200
157
  app.run(host=host, port=port)