sorts messages in ChromaDB export by 'date' order

This commit is contained in:
johnbenac
2023-06-22 00:25:53 -04:00
parent db0b232903
commit add7daa61b

View File

@@ -809,7 +809,7 @@ def chromadb_export():
ids = collection_content.get('ids', [])
metadatas = collection_content.get('metadatas', [])
content = [
unsorted_content = [
{
"id": ids[i],
"metadata": metadatas[i],
@@ -817,13 +817,14 @@ def chromadb_export():
}
for i in range(len(ids))
]
sorted_content = sorted(unsorted_content, key=lambda x: x['metadata']['date'])
export = {
"chat_id": data["chat_id"],
"content": content
"chat_id": data["chat_id"],
"content": sorted_content
}
return jsonify(export)
@app.route("/api/chromadb/import", methods=["POST"])